1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62:
63:
66: public abstract class XMLEventFactory
67: {
68:
69: protected XMLEventFactory()
70: {
71: }
72:
73:
77: public static XMLEventFactory newInstance()
78: throws FactoryConfigurationError
79: {
80: return newInstance(null, null);
81: }
82:
83:
103: public static XMLEventFactory newInstance(String factoryId,
104: ClassLoader classLoader)
105: throws FactoryConfigurationError
106: {
107: ClassLoader loader = classLoader;
108: if (loader == null)
109: {
110: loader = Thread.currentThread().getContextClassLoader();
111: }
112: if (loader == null)
113: {
114: loader = XMLEventFactory.class.getClassLoader();
115: }
116: String className = null;
117: int count = 0;
118: do
119: {
120: className = getFactoryClassName(loader, count++);
121: if (className != null)
122: {
123: try
124: {
125: Class<?> t = (loader != null) ? loader.loadClass(className) :
126: Class.forName(className);
127: return (XMLEventFactory) t.newInstance();
128: }
129: catch (ClassNotFoundException e)
130: {
131: className = null;
132: }
133: catch (Exception e)
134: {
135: throw new FactoryConfigurationError(e,
136: "error instantiating class " + className);
137: }
138: }
139: }
140: while (className == null && count < 3);
141: return new gnu.xml.stream.XMLEventFactoryImpl();
142: }
143:
144: private static String getFactoryClassName(ClassLoader loader, int attempt)
145: {
146: final String propertyName = "javax.xml.stream.XMLEventFactory";
147: switch (attempt)
148: {
149: case 0:
150: return System.getProperty(propertyName);
151: case 1:
152: try
153: {
154: File file = new File(System.getProperty("java.home"));
155: file = new File(file, "lib");
156: file = new File(file, "stax.properties");
157: InputStream in = new FileInputStream(file);
158: Properties props = new Properties();
159: props.load(in);
160: in.close();
161: return props.getProperty(propertyName);
162: }
163: catch (IOException e)
164: {
165: return null;
166: }
167: case 2:
168: try
169: {
170: String serviceKey = "/META-INF/services/" + propertyName;
171: InputStream in = (loader != null) ?
172: loader.getResourceAsStream(serviceKey) :
173: XMLEventFactory.class.getResourceAsStream(serviceKey);
174: if (in != null)
175: {
176: BufferedReader r =
177: new BufferedReader(new InputStreamReader(in));
178: String ret = r.readLine();
179: r.close();
180: return ret;
181: }
182: }
183: catch (IOException e)
184: {
185: }
186: return null;
187: default:
188: return null;
189: }
190: }
191:
192:
195: public abstract void setLocation(Location location);
196:
197:
200: public abstract Attribute createAttribute(String prefix, String namespaceURI,
201: String localName, String value);
202:
203:
206: public abstract Attribute createAttribute(String localName, String value);
207:
208:
211: public abstract Attribute createAttribute(QName name, String value);
212:
213:
216: public abstract Namespace createNamespace(String namespaceURI);
217:
218:
221: public abstract Namespace createNamespace(String prefix, String namespaceUri);
222:
223:
226: @SuppressWarnings("rawtypes")
227: public abstract StartElement createStartElement(QName name,
228: Iterator attributes,
229: Iterator namespaces);
230:
231:
234: public abstract StartElement createStartElement(String prefix,
235: String namespaceUri,
236: String localName);
237:
238:
241: @SuppressWarnings("rawtypes")
242: public abstract StartElement createStartElement(String prefix,
243: String namespaceUri,
244: String localName,
245: Iterator attributes,
246: Iterator namespaces);
247:
248:
251: @SuppressWarnings("rawtypes")
252: public abstract StartElement createStartElement(String prefix,
253: String namespaceUri,
254: String localName,
255: Iterator attributes,
256: Iterator namespaces,
257: NamespaceContext context);
258:
259:
262: @SuppressWarnings("rawtypes")
263: public abstract EndElement createEndElement(QName name,
264: Iterator namespaces);
265:
266:
269: public abstract EndElement createEndElement(String prefix,
270: String namespaceUri,
271: String localName);
272:
273:
276: @SuppressWarnings("rawtypes")
277: public abstract EndElement createEndElement(String prefix,
278: String namespaceUri,
279: String localName,
280: Iterator namespaces);
281:
282:
285: public abstract Characters createCharacters(String content);
286:
287:
290: public abstract Characters createCData(String content);
291:
292:
295: public abstract Characters createSpace(String content);
296:
297:
300: public abstract Characters createIgnorableSpace(String content);
301:
302:
305: public abstract StartDocument createStartDocument();
306:
307:
310: public abstract StartDocument createStartDocument(String encoding,
311: String version,
312: boolean standalone);
313:
314:
317: public abstract StartDocument createStartDocument(String encoding,
318: String version);
319:
320:
323: public abstract StartDocument createStartDocument(String encoding);
324:
325:
328: public abstract EndDocument createEndDocument();
329:
330:
333: public abstract EntityReference createEntityReference(String name,
334: EntityDeclaration declaration);
335:
336:
339: public abstract Comment createComment(String text);
340:
341:
344: public abstract ProcessingInstruction createProcessingInstruction(String target,
345: String data);
346:
347:
350: public abstract DTD createDTD(String dtd);
351:
352: }