2
* Copyright (c) 2003 World Wide Web Consortium,
4
* (Massachusetts Institute of Technology, European Research Consortium for
5
* Informatics and Mathematics, Keio University). All Rights Reserved. This
6
* work is distributed under the W3C(r) Software License [1] in the hope that
7
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
8
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
* [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
15
* This class holds the list of registered DOMImplementations. The contents
16
* of the registry are drawn from the System Property
17
* <code>org.w3c.dom.DOMImplementationSourceList</code>, which must contain a
18
* white-space delimited sequence of the names of classes implementing
19
* <code>DOMImplementationSource</code>.
20
* Applications may also register DOMImplementationSource
21
* implementations by using a method on this class. They may then
22
* query instances of the registry for implementations supporting
26
* <pre class='example'>
27
* // get an instance of the DOMImplementation registry
28
* DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
29
* // get a DOM implementation the Level 3 XML module
30
* DOMImplementation domImpl = registry.getDOMImplementation("XML 3.0");
32
* <p>This provides an application with an implementation-independent
35
* @see DOMImplementation
36
* @see DOMImplementationSource
40
package org.w3c.dom.bootstrap;
42
import java.lang.reflect.Method;
43
import java.lang.reflect.InvocationTargetException;
44
import java.lang.ClassLoader;
45
import java.lang.String;
46
import java.util.StringTokenizer;
47
import java.util.Enumeration;
48
import java.util.Vector;
50
import org.w3c.dom.DOMImplementationSource;
51
import org.w3c.dom.DOMImplementationList;
52
import org.w3c.dom.DOMImplementation;
54
public class DOMImplementationRegistry {
56
// The system property to specify the DOMImplementationSource class names.
57
public final static String PROPERTY =
58
"org.w3c.dom.DOMImplementationSourceList";
60
private Vector _sources;
62
// deny construction by other classes
63
private DOMImplementationRegistry() {
66
// deny construction by other classes
67
private DOMImplementationRegistry(Vector srcs) {
73
* This method queries the System property
74
* <code>org.w3c.dom.DOMImplementationSourceList</code>. If it is
75
* able to read and parse the property, it attempts to instantiate
76
* classes according to each space-delimited substring. Any
77
* exceptions it encounters are thrown to the application. An application
78
* must call this method before using the class.
79
* @return an initialized instance of DOMImplementationRegistry
81
public static DOMImplementationRegistry newInstance()
82
throws ClassNotFoundException, InstantiationException,
83
IllegalAccessException
85
Vector _sources = new Vector();
87
// fetch system property:
88
String p = System.getProperty(PROPERTY);
90
StringTokenizer st = new StringTokenizer(p);
91
while (st.hasMoreTokens()) {
92
String sourceName = st.nextToken();
93
// Use context class loader, falling back to Class.forName
94
// if and only if this fails...
95
Object source = getClass(sourceName).newInstance();
99
return new DOMImplementationRegistry(_sources);
104
* Return the first registered implementation that has the desired
105
* features, or null if none is found.
107
* @param features A string that specifies which features are required.
108
* This is a space separated list in which each feature is
109
* specified by its name optionally followed by a space
110
* and a version number.
111
* This is something like: "XML 1.0 Traversal +Events 2.0"
112
* @return An implementation that has the desired features, or
113
* <code>null</code> if this source has none.
115
public DOMImplementation getDOMImplementation(String features)
116
throws ClassNotFoundException,
117
InstantiationException, IllegalAccessException, ClassCastException
119
int size = _sources.size();
121
for (int i = 0; i < size; i++) {
122
DOMImplementationSource source =
123
(DOMImplementationSource) _sources.get(i);
125
DOMImplementation impl = source.getDOMImplementation(features);
134
* Return the list of all registered implementation that support the desired
137
* @param features A string that specifies which features are required.
138
* This is a space separated list in which each feature is
139
* specified by its name optionally followed by a space
140
* and a version number.
141
* This is something like: "XML 1.0 Traversal +Events 2.0"
142
* @return A list of DOMImplementations that support the desired features.
144
public DOMImplementationList getDOMImplementationList(String features)
145
throws ClassNotFoundException,
146
InstantiationException, IllegalAccessException, ClassCastException
148
int size = _sources.size();
149
DOMImplementationListImpl list = new DOMImplementationListImpl();
151
for (int i = 0; i < size; i++) {
152
DOMImplementationSource source =
153
(DOMImplementationSource) _sources.get(i);
155
DOMImplementationList impls =
156
source.getDOMImplementationList(features);
157
for (int j = 0; j < impls.getLength(); j++) {
158
list.add(impls.item(j));
165
* Register an implementation.
167
public void addSource(DOMImplementationSource s)
168
throws ClassNotFoundException,
169
InstantiationException, IllegalAccessException
174
private static Class getClass (String className)
175
throws ClassNotFoundException, IllegalAccessException,
176
InstantiationException {
178
ClassLoader cl = null;
181
m = Thread.class.getMethod("getContextClassLoader", null);
182
} catch (NoSuchMethodException e) {
183
// Assume that we are running JDK 1.1, use the current ClassLoader
184
cl = DOMImplementationRegistry.class.getClassLoader();
189
cl = (ClassLoader) m.invoke(Thread.currentThread(), null);
190
} catch (IllegalAccessException e) {
192
throw new UnknownError(e.getMessage());
193
} catch (InvocationTargetException e) {
194
// assert(e.getTargetException() instanceof SecurityException)
195
throw new UnknownError(e.getMessage());
199
// fall back to Class.forName
200
return Class.forName(className);
203
return cl.loadClass(className);
204
} catch (ClassNotFoundException e) {
205
return Class.forName(className);
b'\\ No newline at end of file'