|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.sun.xml.tree.SimpleElementFactory
This is a convenience class for creating application-specific elements associated with specified (or default) XML namespaces. It maintains tables mapping element tag names to classes, and uses them as needed to instantiate classes. The string *Element, which is not a legal XML element name, may be used to map otherwise unrecognized tags to a particular class. If this factory is not configured, then all mappings are to the ElementNode class. Erroneous mappings are fatal errors.
A suggested XML syntax for recording these bindings, which may in the future be explicitly supported, is:
<bindings xmlns="..."> <!-- first, bindings for the "default" namespace --> <binding tag="..." class="..."/> <binding tag="*Element" class="..."/> ... <!-- then bindings for other namespaces --> <namespace uri="..."> <binding tag="..." class="..."/> ... </namespace> <!-- can specify JAR files for namespaces --> <namespace uri="..." jar="..."> <binding tag="..." class="..."/> ... </namespace> ... </bindings>
Note that while most URIs used to identify namespaces will be URLs, such as http://www.example.com/xml/purchasing, some may also be URNs like urn:uuid:221ffe10-ae3c-11d1-b66c-00805f8a2676. You can't assume that the URIs are associated with web-accessible data; they must be treated as being no more than distinguishable strings.
Applications classes configuring an element factory will need to
provide their own class loader (this.class.getClassLoader
)
to get the desired behavior in common cases. Classes loaded via some
URL will similarly need to use a network class loader.
Constructor Summary | |
SimpleElementFactory()
Constructs an unconfigured element factory. |
Method Summary | |
void |
addMapping(java.util.Dictionary dict,
java.lang.ClassLoader loader)
Records a default element name to namespace mapping, for use by namespace-unaware DOM construction and when a specific namespace mapping is not available. |
void |
addMapping(java.lang.String namespace,
java.util.Dictionary dict,
java.lang.ClassLoader loader)
Records a namespace-specific mapping between element names and classes. |
ElementEx |
createElementEx(java.lang.String tag)
Creates an element by using the default mapping. |
ElementEx |
createElementEx(java.lang.String namespace,
java.lang.String tag)
Creates an element by using the mapping associated with the specified namespace, or the default namespace as appropriate. |
void |
setDefaultNamespace(java.lang.String ns)
Defines a URI to be treated as the "default" namespace. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public SimpleElementFactory()
Method Detail |
public void addMapping(java.util.Dictionary dict, java.lang.ClassLoader loader)
dict
- Keys are element names, and values are either class
names (interpreted with respect to loader) or class
objects. This value may not be null, and the dictionary is
retained and modified by the factory.loader
- If non-null, this is used instead of the bootstrap
class loader when mapping from class names to class objects.public void addMapping(java.lang.String namespace, java.util.Dictionary dict, java.lang.ClassLoader loader)
namespace
- A URI identifying the namespace for which the
mapping is defineddict
- Keys are element names, and values are either class
names (interpreted with respect to loader) or class
objects. This value may not be null, and the dictionary is
retained and modified by the factory.loader
- If non-null, this is used instead of the bootstrap
class loader when mapping from class names to class objects.public void setDefaultNamespace(java.lang.String ns)
public ElementEx createElementEx(java.lang.String namespace, java.lang.String tag)
namespace
- URI for namespace; null indicates use of
the default namespace, if any.tag
- element tag, without any embedded colonpublic ElementEx createElementEx(java.lang.String tag)
tag
- element tag
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |