Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle TopLink
11g Release 1 (11.1.1)

E28847-01


org.eclipse.persistence.oxm
Class NamespaceResolver

java.lang.Object
  extended by org.eclipse.persistence.oxm.NamespaceResolver

All Implemented Interfaces:
XMLNamespaceResolver

public class NamespaceResolver
extends java.lang.Object
implements XMLNamespaceResolver

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);

See Also:
XMLDescriptor, EISDescriptor

Nested Class Summary
private static class NamespaceResolver.IteratorEnumeration
           

 

Field Summary
private static java.lang.String BASE_PREFIX
           
private  java.lang.String defaultNamespaceURI
           
private  org.w3c.dom.Node dom
           
(package private)  int prefixCounter
           
private  java.util.Map<java.lang.String,java.lang.String> prefixesToNamespaces
           

 

Constructor Summary
NamespaceResolver()
          Default constructor, creates a new NamespaceResolver.

 

Method Summary
 java.lang.String generatePrefix()
           
 java.lang.String generatePrefix(java.lang.String defaultPrefix)
           
 java.lang.String getDefaultNamespaceURI()
           
 java.util.Vector getNamespaces()
          INTERNAL: Returns a Vector of of Namespace objects in the current Namespace Resolver Used for deployment XML
private  java.lang.String getNextPrefix()
           
 java.util.Enumeration getPrefixes()
          Returns the list of prefixes in the NamespaceResolver
 java.util.Map<java.lang.String,java.lang.String> getPrefixesToNamespaces()
           
 void put(java.lang.String prefix, java.lang.String namespaceURI)
          Adds a namespace to the collection of namespaces on the NamespaceResolver
 void removeNamespace(java.lang.String prefix)
           
 java.lang.String resolveNamespacePrefix(java.lang.String prefix)
          Returns the namespace URI associated with a specified namespace prefix
private  java.lang.String resolveNamespaceURI(org.w3c.dom.Node node, java.lang.String uri)
           
 java.lang.String resolveNamespaceURI(java.lang.String uri)
          Return the namespace prefix associated with a namespace URI.
 void setDefaultNamespaceURI(java.lang.String namespaceUri)
           
 void setDOM(org.w3c.dom.Node dom)
           
 void setNamespaces(java.util.Vector names)
          INTERNAL: Set the namespaces on the namespace resolver based on the specified Vector of Namespace objects Used for deployment XML

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Field Detail

BASE_PREFIX

private static final java.lang.String BASE_PREFIX
See Also:
Constant Field Values

defaultNamespaceURI

private java.lang.String defaultNamespaceURI

prefixesToNamespaces

private java.util.Map<java.lang.String,java.lang.String> prefixesToNamespaces

prefixCounter

int prefixCounter

dom

private org.w3c.dom.Node dom

Constructor Detail

NamespaceResolver

public NamespaceResolver()
Default constructor, creates a new NamespaceResolver.

Method Detail

getPrefixesToNamespaces

public java.util.Map<java.lang.String,java.lang.String> getPrefixesToNamespaces()

setDOM

public void setDOM(org.w3c.dom.Node dom)

resolveNamespacePrefix

public java.lang.String resolveNamespacePrefix(java.lang.String prefix)
Returns the namespace URI associated with a specified namespace prefix
Specified by:
resolveNamespacePrefix in interface XMLNamespaceResolver
Parameters:
prefix - The prefix to lookup a namespace URI for
Returns:
The namespace URI associated with the specified prefix

resolveNamespaceURI

public java.lang.String resolveNamespaceURI(java.lang.String uri)
Return the namespace prefix associated with a namespace URI.
Parameters:
uri - A namespace URI.
Returns:
The prefix associated with the namespace URI.

resolveNamespaceURI

private java.lang.String resolveNamespaceURI(org.w3c.dom.Node node,
                                             java.lang.String uri)

put

public void put(java.lang.String prefix,
                java.lang.String namespaceURI)
Adds a namespace to the collection of namespaces on the NamespaceResolver
Parameters:
prefix - The prefix for a namespace
namespaceURI - The namespace URI associated with the specified prefix

getPrefixes

public java.util.Enumeration getPrefixes()
Returns the list of prefixes in the NamespaceResolver
Returns:
An Enumeration containing the prefixes in the NamespaceResolver

getNamespaces

public java.util.Vector getNamespaces()
INTERNAL: Returns a Vector of of Namespace objects in the current Namespace Resolver Used for deployment XML
Returns:
A Vector containing the namespace URIs in the namespace resolver

setNamespaces

public void setNamespaces(java.util.Vector names)
INTERNAL: Set the namespaces on the namespace resolver based on the specified Vector of Namespace objects Used for deployment XML
Parameters:
names - A Vector of namespace URIs

generatePrefix

public java.lang.String generatePrefix()

getNextPrefix

private java.lang.String getNextPrefix()

generatePrefix

public java.lang.String generatePrefix(java.lang.String defaultPrefix)

removeNamespace

public void removeNamespace(java.lang.String prefix)

setDefaultNamespaceURI

public void setDefaultNamespaceURI(java.lang.String namespaceUri)

getDefaultNamespaceURI

public java.lang.String getDefaultNamespaceURI()

Skip navigation links

Copyright © 1998, 2012, Oracle. All Rights Reserved.