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: import ;
63:
64:
67: public abstract class XMLEventFactory
68: {
69:
70: protected XMLEventFactory()
71: {
72: }
73:
74:
78: public static XMLEventFactory newInstance()
79: throws FactoryConfigurationError
80: {
81: return newInstance(null, null);
82: }
83:
84:
99: static XMLEventFactory newInstance(String factoryId, ClassLoader classLoader)
100: throws FactoryConfigurationError
101: {
102: ClassLoader loader = classLoader;
103: if (loader == null)
104: {
105: loader = Thread.currentThread().getContextClassLoader();
106: }
107: if (loader == null)
108: {
109: loader = XMLEventFactory.class.getClassLoader();
110: }
111: String className = null;
112: int count = 0;
113: do
114: {
115: className = getFactoryClassName(loader, count++);
116: if (className != null)
117: {
118: try
119: {
120: Class t = (loader != null) ? loader.loadClass(className) :
121: Class.forName(className);
122: return (XMLEventFactory) t.newInstance();
123: }
124: catch (ClassNotFoundException e)
125: {
126: className = null;
127: }
128: catch (Exception e)
129: {
130: throw new FactoryConfigurationError(e,
131: "error instantiating class " + className);
132: }
133: }
134: }
135: while (className == null && count < 3);
136: return new gnu.xml.stream.XMLEventFactoryImpl();
137: }
138:
139: private static String getFactoryClassName(ClassLoader loader, int attempt)
140: {
141: final String propertyName = "javax.xml.stream.XMLEventFactory";
142: switch (attempt)
143: {
144: case 0:
145: return System.getProperty(propertyName);
146: case 1:
147: try
148: {
149: File file = new File(System.getProperty("java.home"));
150: file = new File(file, "lib");
151: file = new File(file, "stax.properties");
152: InputStream in = new FileInputStream(file);
153: Properties props = new Properties();
154: props.load(in);
155: in.close();
156: return props.getProperty(propertyName);
157: }
158: catch (IOException e)
159: {
160: return null;
161: }
162: case 2:
163: try
164: {
165: String serviceKey = "/META-INF/services/" + propertyName;
166: InputStream in = (loader != null) ?
167: loader.getResourceAsStream(serviceKey) :
168: XMLEventFactory.class.getResourceAsStream(serviceKey);
169: if (in != null)
170: {
171: BufferedReader r =
172: new BufferedReader(new InputStreamReader(in));
173: String ret = r.readLine();
174: r.close();
175: return ret;
176: }
177: }
178: catch (IOException e)
179: {
180: }
181: return null;
182: default:
183: return null;
184: }
185: }
186:
187:
190: public abstract void setLocation(Location location);
191:
192:
195: public abstract Attribute createAttribute(String prefix, String namespaceURI,
196: String localName, String value);
197:
198:
201: public abstract Attribute createAttribute(String localName, String value);
202:
203:
206: public abstract Attribute createAttribute(QName name, String value);
207:
208:
211: public abstract Namespace createNamespace(String namespaceURI);
212:
213:
216: public abstract Namespace createNamespace(String prefix, String namespaceUri);
217:
218:
221: public abstract StartElement createStartElement(QName name,
222: Iterator attributes,
223: Iterator namespaces);
224:
225:
228: public abstract StartElement createStartElement(String prefix,
229: String namespaceUri,
230: String localName);
231:
232:
235: public abstract StartElement createStartElement(String prefix,
236: String namespaceUri,
237: String localName,
238: Iterator attributes,
239: Iterator namespaces);
240:
241:
244: public abstract StartElement createStartElement(String prefix,
245: String namespaceUri,
246: String localName,
247: Iterator attributes,
248: Iterator namespaces,
249: NamespaceContext context);
250:
251:
254: public abstract EndElement createEndElement(QName name,
255: Iterator namespaces);
256:
257:
260: public abstract EndElement createEndElement(String prefix,
261: String namespaceUri,
262: String localName);
263:
264:
267: public abstract EndElement createEndElement(String prefix,
268: String namespaceUri,
269: String localName,
270: Iterator namespaces);
271:
272:
275: public abstract Characters createCharacters(String content);
276:
277:
280: public abstract Characters createCData(String content);
281:
282:
285: public abstract Characters createSpace(String content);
286:
287:
290: public abstract Characters createIgnorableSpace(String content);
291:
292:
295: public abstract StartDocument createStartDocument();
296:
297:
300: public abstract StartDocument createStartDocument(String encoding,
301: String version,
302: boolean standalone);
303:
304:
307: public abstract StartDocument createStartDocument(String encoding,
308: String version);
309:
310:
313: public abstract StartDocument createStartDocument(String encoding);
314:
315:
318: public abstract EndDocument createEndDocument();
319:
320:
323: public abstract EntityReference createEntityReference(String name,
324: EntityDeclaration declaration);
325:
326:
329: public abstract Comment createComment(String text);
330:
331:
334: public abstract ProcessingInstruction createProcessingInstruction(String target,
335: String data);
336:
337:
340: public abstract DTD createDTD(String dtd);
341:
342: }