1:
37:
38: package ;
39:
40: import ;
41: import ;
42:
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49:
50: import ;
51: import ;
52: import ;
53:
54:
55:
63: public final class JAXPFactory
64: extends SAXParserFactory
65: {
66:
67: private Hashtable flags = new Hashtable();
68:
69:
73: public JAXPFactory()
74: {
75: }
76:
77: public SAXParser newSAXParser()
78: throws ParserConfigurationException, SAXException
79: {
80: JaxpParser jaxp = new JaxpParser();
81: Enumeration e = flags.keys();
82: XMLReader parser = jaxp.getXMLReader();
83:
84: parser.setFeature(SAXDriver.FEATURE + "namespaces",
85: isNamespaceAware());
86: parser.setFeature(SAXDriver.FEATURE + "validation",
87: isValidating());
88:
89:
90: while (e.hasMoreElements())
91: {
92: String uri = (String) e.nextElement();
93: Boolean value = (Boolean) flags.get(uri);
94: parser.setFeature(uri, value.booleanValue());
95: }
96:
97: return jaxp;
98: }
99:
100:
101:
102: public void setFeature(String name, boolean value)
103: throws ParserConfigurationException, SAXNotRecognizedException,
104: SAXNotSupportedException
105: {
106: try
107: {
108:
109:
110: new JaxpParser().getXMLReader().setFeature(name, value);
111:
112: flags.put(name, Boolean.valueOf(value));
113: }
114: catch (SAXNotRecognizedException e)
115: {
116: throw new SAXNotRecognizedException(name);
117: }
118: catch (SAXNotSupportedException e)
119: {
120: throw new SAXNotSupportedException(name);
121: }
122: catch (Exception e)
123: {
124: throw new ParserConfigurationException(e.getClass().getName()
125: + ": "
126: + e.getMessage());
127: }
128: }
129:
130: public boolean getFeature(String name)
131: throws ParserConfigurationException, SAXNotRecognizedException,
132: SAXNotSupportedException
133: {
134: Boolean value = (Boolean) flags.get(name);
135:
136: if (value != null)
137: {
138: return value.booleanValue();
139: }
140: else
141: {
142: try
143: {
144: return new JaxpParser().getXMLReader().getFeature(name);
145: }
146: catch (SAXNotRecognizedException e)
147: {
148: throw new SAXNotRecognizedException(name);
149: }
150: catch (SAXNotSupportedException e)
151: {
152: throw new SAXNotSupportedException(name);
153: }
154: catch (SAXException e)
155: {
156: throw new ParserConfigurationException(e.getClass().getName()
157: + ": "
158: + e.getMessage());
159: }
160: }
161: }
162:
163: private static class JaxpParser
164: extends SAXParser
165: {
166:
167: private XmlReader ae2 = new XmlReader();
168: private XMLReaderAdapter parser = null;
169:
170: JaxpParser()
171: {
172: }
173:
174: public void setProperty(String id, Object value)
175: throws SAXNotRecognizedException, SAXNotSupportedException
176: {
177: ae2.setProperty(id, value);
178: }
179:
180: public Object getProperty(String id)
181: throws SAXNotRecognizedException, SAXNotSupportedException
182: {
183: return ae2.getProperty(id);
184: }
185:
186: public Parser getParser()
187: throws SAXException
188: {
189: if (parser == null)
190: {
191: parser = new XMLReaderAdapter(ae2);
192: }
193: return parser;
194: }
195:
196: public XMLReader getXMLReader ()
197: throws SAXException
198: {
199: return ae2;
200: }
201:
202: public boolean isNamespaceAware()
203: {
204: try
205: {
206: return ae2.getFeature(SAXDriver.FEATURE + "namespaces");
207: }
208: catch (Exception e)
209: {
210: throw new Error();
211: }
212: }
213:
214: public boolean isValidating()
215: {
216: try
217: {
218: return ae2.getFeature(SAXDriver.FEATURE + "validation");
219: }
220: catch (Exception e)
221: {
222: throw new Error();
223: }
224: }
225:
226:
227:
228: }
229:
230: }