/
__XMLInputFactory.java
225 lines (187 loc) · 8.57 KB
/
__XMLInputFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package __redirected;
import java.io.InputStream;
import java.io.Reader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import javax.xml.stream.EventFilter;
import javax.xml.stream.StreamFilter;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLReporter;
import javax.xml.stream.XMLResolver;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.util.XMLEventAllocator;
import javax.xml.transform.Source;
import org.jboss.modules.ModuleIdentifier;
import org.jboss.modules.ModuleLoader;
/**
* A redirected XMLInputFactory
*
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
* @author Jason T. Greene
*/
public final class __XMLInputFactory extends XMLInputFactory {
private static final Constructor<? extends XMLInputFactory> PLATFORM_FACTORY;
private static volatile Constructor<? extends XMLInputFactory> DEFAULT_FACTORY;
static {
Thread thread = Thread.currentThread();
ClassLoader old = thread.getContextClassLoader();
// Unfortunately we can not use null because of a stupid bug in the jdk JAXP factory finder.
// Lack of tccl causes the provider file discovery to fallback to the jaxp loader (bootclasspath)
// which is correct. However, after parsing it, it then disables the fallback for the loading of the class.
// Thus, the class can not be found.
//
// Work around the problem by using the System CL, although in the future we may want to just "inherit"
// the environment's TCCL
thread.setContextClassLoader(ClassLoader.getSystemClassLoader());
try {
if (System.getProperty(XMLInputFactory.class.getName(), "").equals(__XMLInputFactory .class.getName())) {
System.clearProperty(XMLInputFactory.class.getName());
}
XMLInputFactory factory = XMLInputFactory.newInstance();
try {
DEFAULT_FACTORY = PLATFORM_FACTORY = factory.getClass().getConstructor();
} catch (NoSuchMethodException e) {
throw __RedirectedUtils.wrapped(new NoSuchMethodError(e.getMessage()), e);
}
System.setProperty(XMLInputFactory.class.getName(), __XMLInputFactory.class.getName());
} finally {
thread.setContextClassLoader(old);
}
}
@Deprecated
public static void changeDefaultFactory(ModuleIdentifier id, ModuleLoader loader) {
changeDefaultFactory(id.toString(), loader);
}
public static void changeDefaultFactory(String id, ModuleLoader loader) {
Class<? extends XMLInputFactory> clazz = __RedirectedUtils.loadProvider(id, XMLInputFactory.class, loader);
if (clazz != null) {
try {
DEFAULT_FACTORY = clazz.getConstructor();
} catch (NoSuchMethodException e) {
throw __RedirectedUtils.wrapped(new NoSuchMethodError(e.getMessage()), e);
}
}
}
/**
* Init method.
*/
public static void init() {}
public static void restorePlatformFactory() {
DEFAULT_FACTORY = PLATFORM_FACTORY;
}
/**
* Construct a new instance.
*/
public __XMLInputFactory() {
Constructor<? extends XMLInputFactory> factory = DEFAULT_FACTORY;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
if (loader != null) {
Class<? extends XMLInputFactory> provider = __RedirectedUtils.loadProvider(XMLInputFactory.class, loader);
if (provider != null)
factory = provider.getConstructor();
}
actual = factory.newInstance();
} catch (InstantiationException e) {
throw __RedirectedUtils.wrapped(new InstantiationError(e.getMessage()), e);
} catch (IllegalAccessException e) {
throw __RedirectedUtils.wrapped(new IllegalAccessError(e.getMessage()), e);
} catch (InvocationTargetException e) {
throw __RedirectedUtils.rethrowCause(e);
} catch (NoSuchMethodException e) {
throw __RedirectedUtils.wrapped(new NoSuchMethodError(e.getMessage()), e);
}
}
private final XMLInputFactory actual;
public XMLStreamReader createXMLStreamReader(final Reader reader) throws XMLStreamException {
return actual.createXMLStreamReader(reader);
}
public XMLStreamReader createXMLStreamReader(final Source source) throws XMLStreamException {
return actual.createXMLStreamReader(source);
}
public XMLStreamReader createXMLStreamReader(final InputStream stream) throws XMLStreamException {
return actual.createXMLStreamReader(stream);
}
public XMLStreamReader createXMLStreamReader(final InputStream stream, final String encoding) throws XMLStreamException {
return actual.createXMLStreamReader(stream, encoding);
}
public XMLStreamReader createXMLStreamReader(final String systemId, final InputStream stream) throws XMLStreamException {
return actual.createXMLStreamReader(systemId, stream);
}
public XMLStreamReader createXMLStreamReader(final String systemId, final Reader reader) throws XMLStreamException {
return actual.createXMLStreamReader(systemId, reader);
}
public XMLEventReader createXMLEventReader(final Reader reader) throws XMLStreamException {
return actual.createXMLEventReader(reader);
}
public XMLEventReader createXMLEventReader(final String systemId, final Reader reader) throws XMLStreamException {
return actual.createXMLEventReader(systemId, reader);
}
public XMLEventReader createXMLEventReader(final XMLStreamReader reader) throws XMLStreamException {
return actual.createXMLEventReader(reader);
}
public XMLEventReader createXMLEventReader(final Source source) throws XMLStreamException {
return actual.createXMLEventReader(source);
}
public XMLEventReader createXMLEventReader(final InputStream stream) throws XMLStreamException {
return actual.createXMLEventReader(stream);
}
public XMLEventReader createXMLEventReader(final InputStream stream, final String encoding) throws XMLStreamException {
return actual.createXMLEventReader(stream, encoding);
}
public XMLEventReader createXMLEventReader(final String systemId, final InputStream stream) throws XMLStreamException {
return actual.createXMLEventReader(systemId, stream);
}
public XMLStreamReader createFilteredReader(final XMLStreamReader reader, final StreamFilter filter) throws XMLStreamException {
return actual.createFilteredReader(reader, filter);
}
public XMLEventReader createFilteredReader(final XMLEventReader reader, final EventFilter filter) throws XMLStreamException {
return actual.createFilteredReader(reader, filter);
}
public XMLResolver getXMLResolver() {
return actual.getXMLResolver();
}
public void setXMLResolver(final XMLResolver resolver) {
actual.setXMLResolver(resolver);
}
public XMLReporter getXMLReporter() {
return actual.getXMLReporter();
}
public void setXMLReporter(final XMLReporter reporter) {
actual.setXMLReporter(reporter);
}
public void setProperty(final String name, final Object value) throws IllegalArgumentException {
actual.setProperty(name, value);
}
public Object getProperty(final String name) throws IllegalArgumentException {
return actual.getProperty(name);
}
public boolean isPropertySupported(final String name) {
return actual.isPropertySupported(name);
}
public void setEventAllocator(final XMLEventAllocator allocator) {
actual.setEventAllocator(allocator);
}
public XMLEventAllocator getEventAllocator() {
return actual.getEventAllocator();
}
}