It is common for an XML document to include one or more namespaces. TopLink supports this using its NamespaceResolver. The namespace resolver maintains pairs of namespace prefixes and URIs. TopLink uses these prefixes in conjunction with the XPath statements you specify on EIS mappings to XML records and XML mappings.
Although TopLink captures namespace prefixes in the XPath statements for mappings (if applicable), the input document is not required to use the same namespace prefixes. TopLink will use the namespace prefixes specified in the mapping when creating new documents.
Code Sample
NamespaceResolver resolver = new NamespaceResolver();
resolver.put( "ns", "urn:namespace-example");
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Customer.class);
descriptor.setDefaultRootElement("ns:customer");
descriptor.setNamespaceResolver(resolver);
XMLDirectMapping mapping = new XMLDirectMapping();
mapping.setAttributeName("id");
mapping.setXPath("ns:id/text()");
descriptor.addMapping(mapping);
org.eclipse.persistence.oxm.XMLDescriptor , org.eclipse.persistence.eis.EISDescriptor
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private String | |
| private Node | |
| private static final Vector | |
| private int | |
| private NamespaceResolverStorage |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| public String | |
| public String | |
| public Vector | Returns: A Vector containing the namespace URIs in the namespace resolverINTERNAL: Returns a Vector of of Namespace objects in the current Namespace Resolver Used for deployment XML |
| private String | |
| public Enumeration | Returns: An Enumeration containing the prefixes in the NamespaceResolverReturns the list of prefixes in the NamespaceResolver |
| public Map | |
| public boolean | |
| public boolean | |
| public void | |
| public void | |
| public String | Returns: The namespace URI associated with the specified prefixThe prefix to lookup a namespace URI for prefix)Implements org. |
| public String | Returns: The prefix associated with the namespace URI.A namespace URI. uri)Return the namespace prefix associated with a namespace URI. |
| private String | |
| public void | |
| public void | |
| public void | setNamespaces(Vector<Namespace>
A Vector of namespace URIs names)INTERNAL: Set the namespaces on the namespace resolver based on the specified Vector of Namespace objects Used for deployment XML |
| private void |
| BASE_PREFIX | back to summary |
|---|---|
| private static final String BASE_PREFIX | |
| defaultNamespaceURI | back to summary |
|---|---|
| private String defaultNamespaceURI | |
| dom | back to summary |
|---|---|
| private Node dom | |
| EMPTY_VECTOR | back to summary |
|---|---|
| private static final Vector<Namespace> EMPTY_VECTOR | |
| prefixCounter | back to summary |
|---|---|
| private int prefixCounter | |
| prefixesToNamespaces | back to summary |
|---|---|
| private NamespaceResolverStorage prefixesToNamespaces | |
| NamespaceResolver | back to summary |
|---|---|
| public NamespaceResolver() Default constructor, creates a new NamespaceResolver. | |
| NamespaceResolver | back to summary |
|---|---|
| public NamespaceResolver(NamespaceResolver namespaceResolver) Copy Constructor
| |
| generatePrefix | back to summary |
|---|---|
| public String generatePrefix() | |
| generatePrefix | back to summary |
|---|---|
| public String generatePrefix(String defaultPrefix) | |
| getDefaultNamespaceURI | back to summary |
|---|---|
| public String getDefaultNamespaceURI() | |
| getNamespaces | back to summary |
|---|---|
| public Vector INTERNAL: Returns a Vector of of Namespace objects in the current Namespace Resolver Used for deployment XML | |
| getNextPrefix | back to summary |
|---|---|
| private String getNextPrefix() | |
| getPrefixes | back to summary |
|---|---|
| public Enumeration Returns the list of prefixes in the NamespaceResolver
| |
| getPrefixesToNamespaces | back to summary |
|---|---|
| public Map | |
| hasPrefix | back to summary |
|---|---|
| public boolean hasPrefix(String prefix) Indicates whether given
| |
| hasPrefixesToNamespaces | back to summary |
|---|---|
| public boolean hasPrefixesToNamespaces() | |
| put | back to summary |
|---|---|
| public void put(String prefix, String namespaceURI) Adds a namespace to the collection of namespaces on the NamespaceResolver | |
| removeNamespace | back to summary |
|---|---|
| public void removeNamespace(String prefix) | |
| resolveNamespacePrefix | back to summary |
|---|---|
| public String resolveNamespacePrefix(String prefix) Implements org. Returns the namespace URI associated with a specified namespace prefix | |
| resolveNamespaceURI | back to summary |
|---|---|
| public String resolveNamespaceURI(String uri) Return the namespace prefix associated with a namespace URI. | |
| resolveNamespaceURI | back to summary |
|---|---|
| private String resolveNamespaceURI(Node node, String uri) | |
| setDefaultNamespaceURI | back to summary |
|---|---|
| public void setDefaultNamespaceURI(String namespaceUri) | |
| setDOM | back to summary |
|---|---|
| public void setDOM(Node dom) | |
| setNamespaces | back to summary |
|---|---|
| public void setNamespaces(Vector<Namespace> names) INTERNAL: Set the namespaces on the namespace resolver based on the specified Vector of Namespace objects Used for deployment XML | |
| setPrefixesToNamespaces | back to summary |
|---|---|
| private void setPrefixesToNamespaces(Map<String, String> input) | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | hasMoreElements()
Implements java. |
| public E | nextElement()
Implements java. |
| iterator | back to summary |
|---|---|
| private final Iterator<E> iterator | |
| IteratorEnumeration | back to summary |
|---|---|
| public IteratorEnumeration(Iterator<E> iterator) | |
| hasMoreElements | back to summary |
|---|---|
| public boolean hasMoreElements() Implements java. Doc from java. Tests if this enumeration contains more elements.
| |
| nextElement | back to summary |
|---|---|
| public E nextElement() Implements java. Doc from java. Returns the next element of this enumeration if this enumeration object has at least one more element to provide.
| |