|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.crimson.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.
Nested Class Summary | |
private static class |
SimpleElementFactory.ClassLoaderFinder
|
(package private) static class |
SimpleElementFactory.ClassLoaderFinderConcrete
|
Field Summary | |
private ClassLoader |
defaultLoader
|
private Dictionary |
defaultMapping
|
private String |
defaultNs
|
private Locale |
locale
|
private Dictionary |
nsLoaders
|
private Dictionary |
nsMappings
|
Constructor Summary | |
SimpleElementFactory()
Constructs an unconfigured element factory. |
Method Summary | |
void |
addMapping(Dictionary dict,
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(String namespace,
Dictionary dict,
ClassLoader loader)
Records a namespace-specific mapping between element names and classes. |
ElementEx |
createElementEx(String tag)
Creates an element by using the default mapping. |
ElementEx |
createElementEx(String namespace,
String localName)
Creates an element by using the mapping associated with the specified namespace, or the default namespace as appropriate. |
private ElementNode |
doMap(String tagName,
Dictionary node2class,
ClassLoader loader)
|
private static ClassLoader |
findClassLoader()
Figure out which ClassLoader to use. |
(package private) String |
getMessage(String messageId)
|
(package private) String |
getMessage(String messageId,
Object[] parameters)
|
private Class |
map2Class(String key,
Dictionary node2class,
ClassLoader loader)
|
void |
setDefaultNamespace(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 |
Field Detail |
private Dictionary defaultMapping
private ClassLoader defaultLoader
private String defaultNs
private Dictionary nsMappings
private Dictionary nsLoaders
private Locale locale
Constructor Detail |
public SimpleElementFactory()
Method Detail |
public void addMapping(Dictionary dict, 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(String namespace, Dictionary dict, 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(String ns)
private Class map2Class(String key, Dictionary node2class, ClassLoader loader)
private ElementNode doMap(String tagName, Dictionary node2class, ClassLoader loader)
public ElementEx createElementEx(String namespace, String localName)
createElementEx
in interface ElementFactory
namespace
- URI for namespace; null indicates use of
the default namespace, if any.localName
- element tag, without any embedded colonpublic ElementEx createElementEx(String tag)
createElementEx
in interface ElementFactory
tag
- element tagString getMessage(String messageId)
String getMessage(String messageId, Object[] parameters)
private static ClassLoader findClassLoader()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |