org.w3c.dom.bootstrap
public final class: DOMImplementationRegistry [javadoc |
source]
java.lang.Object
org.w3c.dom.bootstrap.DOMImplementationRegistry
A factory that enables applications to obtain instances of
DOMImplementation.
Example:
// get an instance of the DOMImplementation registry
DOMImplementationRegistry registry =
DOMImplementationRegistry.newInstance();
// get a DOM implementation the Level 3 XML module
DOMImplementation domImpl =
registry.getDOMImplementation("XML 3.0");
This provides an application with an implementation-independent starting
point. DOM implementations may modify this class to meet new security
standards or to provide *additional* fallbacks for the list of
DOMImplementationSources.
| Field Summary |
|---|
| public static final String | PROPERTY | The system property to specify the
DOMImplementationSource class names. |
| Method from org.w3c.dom.bootstrap.DOMImplementationRegistry Detail: |
public void addSource(DOMImplementationSource s) {
if (s == null) {
throw new NullPointerException();
}
if (!sources.contains(s)) {
sources.addElement(s);
}
}
Register an implementation. |
public DOMImplementation getDOMImplementation(String features) {
int size = sources.size();
String name = null;
for (int i = 0; i < size; i++) {
DOMImplementationSource source =
(DOMImplementationSource) sources.elementAt(i);
DOMImplementation impl = source.getDOMImplementation(features);
if (impl != null) {
return impl;
}
}
return null;
}
Return the first implementation that has the desired
features, or null if none is found. |
public DOMImplementationList getDOMImplementationList(String features) {
final Vector implementations = new Vector();
int size = sources.size();
for (int i = 0; i < size; i++) {
DOMImplementationSource source =
(DOMImplementationSource) sources.elementAt(i);
DOMImplementationList impls =
source.getDOMImplementationList(features);
for (int j = 0; j < impls.getLength(); j++) {
DOMImplementation impl = impls.item(j);
implementations.addElement(impl);
}
}
return new DOMImplementationList() {
public DOMImplementation item(final int index) {
if (index >= 0 && index < implementations.size()) {
try {
return (DOMImplementation)
implementations.elementAt(index);
} catch (ArrayIndexOutOfBoundsException e) {
return null;
}
}
return null;
}
public int getLength() {
return implementations.size();
}
};
}
Return a list of implementations that support the
desired features. |
public static DOMImplementationRegistry newInstance() throws ClassNotFoundException, ClassCastException, IllegalAccessException, InstantiationException {
Vector sources = new Vector();
ClassLoader classLoader = getClassLoader();
// fetch system property:
String p = getSystemProperty(PROPERTY);
//
// if property is not specified then use contents of
// META_INF/org.w3c.dom.DOMImplementationSourceList from classpath
if (p == null) {
p = getServiceValue(classLoader);
}
if (p == null) {
//
// DOM Implementations can modify here to add *additional* fallback
// mechanisms to access a list of default DOMImplementationSources.
//fall back to JAXP implementation class com.sun.org.apache.xerces.internal.dom.DOMXSImplementationSourceImpl
p = FALLBACK_CLASS;
}
if (p != null) {
StringTokenizer st = new StringTokenizer(p);
while (st.hasMoreTokens()) {
String sourceName = st.nextToken();
// Use context class loader, falling back to Class.forName
// if and only if this fails...
Class sourceClass = null;
if (classLoader != null) {
sourceClass = classLoader.loadClass(sourceName);
} else {
sourceClass = Class.forName(sourceName);
}
DOMImplementationSource source =
(DOMImplementationSource) sourceClass.newInstance();
sources.addElement(source);
}
}
return new DOMImplementationRegistry(sources);
}
Obtain a new instance of a DOMImplementationRegistry.
The DOMImplementationRegistry is initialized by the
application or the implementation, depending on the context, by
first checking the value of the Java system property
org.w3c.dom.DOMImplementationSourceList and
the the service provider whose contents are at
"META_INF/services/org.w3c.dom.DOMImplementationSourceList"
The value of this property is a white-space separated list of
names of availables classes implementing the
DOMImplementationSource interface. Each class listed
in the class name list is instantiated and any exceptions
encountered are thrown to the application. |