18 * limitations under the License. |
19 * limitations under the License. |
19 */ |
20 */ |
20 |
21 |
21 package com.sun.org.apache.xml.internal.dtm.ref; |
22 package com.sun.org.apache.xml.internal.dtm.ref; |
22 |
23 |
|
24 import com.sun.org.apache.xalan.internal.utils.ObjectFactory; |
|
25 import com.sun.org.apache.xerces.internal.parsers.SAXParser; |
|
26 import com.sun.org.apache.xml.internal.res.XMLErrorResources; |
|
27 import com.sun.org.apache.xml.internal.res.XMLMessages; |
23 import java.io.IOException; |
28 import java.io.IOException; |
24 import java.lang.reflect.Constructor; |
29 import java.lang.reflect.Constructor; |
25 import java.lang.reflect.Method; |
30 import java.lang.reflect.Method; |
26 |
|
27 import com.sun.org.apache.xerces.internal.parsers.SAXParser; |
|
28 import com.sun.org.apache.xml.internal.res.XMLErrorResources; |
|
29 import com.sun.org.apache.xml.internal.res.XMLMessages; |
|
30 import com.sun.org.apache.xalan.internal.utils.ObjectFactory; |
|
31 |
|
32 import org.xml.sax.InputSource; |
31 import org.xml.sax.InputSource; |
33 import org.xml.sax.SAXException; |
32 import org.xml.sax.SAXException; |
34 import org.xml.sax.XMLReader; |
33 import org.xml.sax.XMLReader; |
35 |
34 |
36 |
35 |
55 Method fParseSome=null; // Xerces1 method |
54 Method fParseSome=null; // Xerces1 method |
56 Object fPullParserConfig=null; // Xerces2 pull control object |
55 Object fPullParserConfig=null; // Xerces2 pull control object |
57 Method fConfigSetInput=null; // Xerces2 method |
56 Method fConfigSetInput=null; // Xerces2 method |
58 Method fConfigParse=null; // Xerces2 method |
57 Method fConfigParse=null; // Xerces2 method |
59 Method fSetInputSource=null; // Xerces2 pull control method |
58 Method fSetInputSource=null; // Xerces2 pull control method |
60 Constructor fConfigInputSourceCtor=null; // Xerces2 initialization method |
59 Constructor<?> fConfigInputSourceCtor=null; // Xerces2 initialization method |
61 Method fConfigSetByteStream=null; // Xerces2 initialization method |
60 Method fConfigSetByteStream=null; // Xerces2 initialization method |
62 Method fConfigSetCharStream=null; // Xerces2 initialization method |
61 Method fConfigSetCharStream=null; // Xerces2 initialization method |
63 Method fConfigSetEncoding=null; // Xerces2 initialization method |
62 Method fConfigSetEncoding=null; // Xerces2 initialization method |
64 Method fReset=null; // Both Xerces1 and Xerces2, but diff. signatures |
63 Method fReset=null; // Both Xerces1 and Xerces2, but diff. signatures |
65 |
64 |
98 // Reflection is used to allow us to continue to compile against |
97 // Reflection is used to allow us to continue to compile against |
99 // Xerces1. If/when we can abandon the older versions of the parser, |
98 // Xerces1. If/when we can abandon the older versions of the parser, |
100 // this will simplify significantly. |
99 // this will simplify significantly. |
101 |
100 |
102 // If we can't get the magic constructor, no need to look further. |
101 // If we can't get the magic constructor, no need to look further. |
103 Class xniConfigClass=ObjectFactory.findProviderClass( |
102 Class<?> xniConfigClass=ObjectFactory.findProviderClass( |
104 "com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration", |
103 "com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration", |
105 true); |
104 true); |
106 Class[] args1={xniConfigClass}; |
105 Class<?>[] args1={xniConfigClass}; |
107 Constructor ctor=SAXParser.class.getConstructor(args1); |
106 Constructor<?> ctor=SAXParser.class.getConstructor(args1); |
108 |
107 |
109 // Build the parser configuration object. StandardParserConfiguration |
108 // Build the parser configuration object. StandardParserConfiguration |
110 // happens to implement XMLPullParserConfiguration, which is the API |
109 // happens to implement XMLPullParserConfiguration, which is the API |
111 // we're going to want to use. |
110 // we're going to want to use. |
112 Class xniStdConfigClass=ObjectFactory.findProviderClass( |
111 Class<?> xniStdConfigClass=ObjectFactory.findProviderClass( |
113 "com.sun.org.apache.xerces.internal.parsers.StandardParserConfiguration", |
112 "com.sun.org.apache.xerces.internal.parsers.StandardParserConfiguration", |
114 true); |
113 true); |
115 fPullParserConfig=xniStdConfigClass.getConstructor().newInstance(); |
114 fPullParserConfig=xniStdConfigClass.getConstructor().newInstance(); |
116 Object[] args2={fPullParserConfig}; |
115 Object[] args2={fPullParserConfig}; |
117 fIncrementalParser = (SAXParser)ctor.newInstance(args2); |
116 fIncrementalParser = (SAXParser)ctor.newInstance(args2); |
118 |
117 |
119 // Preload all the needed the configuration methods... I want to know they're |
118 // Preload all the needed the configuration methods... I want to know they're |
120 // all here before we commit to trying to use them, just in case the |
119 // all here before we commit to trying to use them, just in case the |
121 // API changes again. |
120 // API changes again. |
122 Class fXniInputSourceClass=ObjectFactory.findProviderClass( |
121 Class<?> fXniInputSourceClass=ObjectFactory.findProviderClass( |
123 "com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource", |
122 "com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource", |
124 true); |
123 true); |
125 Class[] args3={fXniInputSourceClass}; |
124 Class<?>[] args3={fXniInputSourceClass}; |
126 fConfigSetInput=xniStdConfigClass.getMethod("setInputSource",args3); |
125 fConfigSetInput=xniStdConfigClass.getMethod("setInputSource",args3); |
127 |
126 |
128 Class[] args4={String.class,String.class,String.class}; |
127 Class<?>[] args4={String.class,String.class,String.class}; |
129 fConfigInputSourceCtor=fXniInputSourceClass.getConstructor(args4); |
128 fConfigInputSourceCtor=fXniInputSourceClass.getConstructor(args4); |
130 Class[] args5={java.io.InputStream.class}; |
129 Class<?>[] args5={java.io.InputStream.class}; |
131 fConfigSetByteStream=fXniInputSourceClass.getMethod("setByteStream",args5); |
130 fConfigSetByteStream=fXniInputSourceClass.getMethod("setByteStream",args5); |
132 Class[] args6={java.io.Reader.class}; |
131 Class<?>[] args6={java.io.Reader.class}; |
133 fConfigSetCharStream=fXniInputSourceClass.getMethod("setCharacterStream",args6); |
132 fConfigSetCharStream=fXniInputSourceClass.getMethod("setCharacterStream",args6); |
134 Class[] args7={String.class}; |
133 Class<?>[] args7={String.class}; |
135 fConfigSetEncoding=fXniInputSourceClass.getMethod("setEncoding",args7); |
134 fConfigSetEncoding=fXniInputSourceClass.getMethod("setEncoding",args7); |
136 |
135 |
137 Class[] argsb={Boolean.TYPE}; |
136 Class<?>[] argsb={Boolean.TYPE}; |
138 fConfigParse=xniStdConfigClass.getMethod("parse",argsb); |
137 fConfigParse=xniStdConfigClass.getMethod("parse",argsb); |
139 Class[] noargs=new Class[0]; |
138 Class<?>[] noargs=new Class<?>[0]; |
140 fReset=fIncrementalParser.getClass().getMethod("reset",noargs); |
139 fReset=fIncrementalParser.getClass().getMethod("reset",noargs); |
141 } |
140 } |
142 catch(Exception e) |
141 catch(Exception e) |
143 { |
142 { |
144 // Fallback if this fails (implemented in createIncrementalSAXSource) is |
143 // Fallback if this fails (implemented in createIncrementalSAXSource) is |
170 // Xerces2. If/when we can abandon the older versions of the parser, |
169 // Xerces2. If/when we can abandon the older versions of the parser, |
171 // this constructor will simply have to fail until/unless the |
170 // this constructor will simply have to fail until/unless the |
172 // Xerces2 incremental support is made available on previously |
171 // Xerces2 incremental support is made available on previously |
173 // constructed SAXParser instances. |
172 // constructed SAXParser instances. |
174 fIncrementalParser=parser; |
173 fIncrementalParser=parser; |
175 Class me=parser.getClass(); |
174 Class<?> me=parser.getClass(); |
176 Class[] parms={InputSource.class}; |
175 Class<?>[] parms={InputSource.class}; |
177 fParseSomeSetup=me.getMethod("parseSomeSetup",parms); |
176 fParseSomeSetup=me.getMethod("parseSomeSetup",parms); |
178 parms=new Class[0]; |
177 parms=new Class<?>[0]; |
179 fParseSome=me.getMethod("parseSome",parms); |
178 fParseSome=me.getMethod("parseSome",parms); |
180 // Fallback if this fails (implemented in createIncrementalSAXSource) is |
179 // Fallback if this fails (implemented in createIncrementalSAXSource) is |
181 // to use IncrementalSAXSource_Filter rather than Xerces-specific code. |
180 // to use IncrementalSAXSource_Filter rather than Xerces-specific code. |
182 } |
181 } |
183 |
182 |