Top Description Inners Fields Constructors Methods
org.eclipse.persistence.internal.oxm

public Class NamespaceResolver

extends Object
implements XMLNamespaceResolver
Class Inheritance
All Implemented Interfaces
org.eclipse.persistence.platform.xml.XMLNamespaceResolver
Known Direct Subclasses
org.eclipse.persistence.oxm.NamespaceResolver
Imports
java.util.ArrayList, .Enumeration, .Iterator, .List, .Map, .Map.Entry, .Vector, org.eclipse.persistence.platform.xml.XMLNamespaceResolver, .XMLPlatformFactory, org.w3c.dom.NamedNodeMap, .Node

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
org.eclipse.persistence.oxm.XMLDescriptor, org.eclipse.persistence.eis.EISDescriptor

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final String
private String
private Node
private static final Vector<Namespace>
private int
private NamespaceResolverStorage

Constructor Summary

AccessConstructor and Description
public
NamespaceResolver()

Default constructor, creates a new NamespaceResolver.

public
NamespaceResolver(NamespaceResolver namespaceResolver)

Copy Constructor

Method Summary

Modifier and TypeMethod and Description
public String
public String
generatePrefix(String defaultPrefix)

public String
public Vector<Namespace>

Returns:

A Vector containing the namespace URIs in the namespace resolver
getNamespaces
()

INTERNAL: Returns a Vector of of Namespace objects in the current Namespace Resolver Used for deployment XML

private String
public Enumeration<String>

Returns:

An Enumeration containing the prefixes in the NamespaceResolver
getPrefixes
()

Returns the list of prefixes in the NamespaceResolver

public Map<String, String>
public boolean

Returns:

true if prefix is present in prefix to name-space map (getPrefixesToNamespaces()
hasPrefix
(String
name-space prefix
prefix
)

Indicates whether given prefix is assigned to a name-space.

public boolean
public void
put(String
The prefix for a namespace
prefix
,
String
The namespace URI associated with the specified prefix
namespaceURI
)

Adds a namespace to the collection of namespaces on the NamespaceResolver

public void
public String

Returns:

The namespace URI associated with the specified prefix
resolveNamespacePrefix
(String
The prefix to lookup a namespace URI for
prefix
)

Implements org.eclipse.persistence.platform.xml.XMLNamespaceResolver.resolveNamespacePrefix.

Returns the namespace URI associated with a specified namespace prefix
public String

Returns:

The prefix associated with the namespace URI.
resolveNamespaceURI
(String
A namespace URI.
uri
)

Return the namespace prefix associated with a namespace URI.

private String
public void
public void
setDOM(Node dom)

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
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BASE_PREFIXback to summary
private static final String BASE_PREFIX
defaultNamespaceURIback to summary
private String defaultNamespaceURI
domback to summary
private Node dom
EMPTY_VECTORback to summary
private static final Vector<Namespace> EMPTY_VECTOR
prefixCounterback to summary
private int prefixCounter
prefixesToNamespacesback to summary
private NamespaceResolverStorage prefixesToNamespaces

Constructor Detail

NamespaceResolverback to summary
public NamespaceResolver()

Default constructor, creates a new NamespaceResolver.

NamespaceResolverback to summary
public NamespaceResolver(NamespaceResolver namespaceResolver)

Copy Constructor

Since
EclipseLink 2.5.0

Method Detail

generatePrefixback to summary
public String generatePrefix()
generatePrefixback to summary
public String generatePrefix(String defaultPrefix)
getDefaultNamespaceURIback to summary
public String getDefaultNamespaceURI()
getNamespacesback to summary
public Vector<Namespace> getNamespaces()

INTERNAL: Returns a Vector of of Namespace objects in the current Namespace Resolver Used for deployment XML

Returns:Vector<Namespace>

A Vector containing the namespace URIs in the namespace resolver

getNextPrefixback to summary
private String getNextPrefix()
getPrefixesback to summary
public Enumeration<String> getPrefixes()

Returns the list of prefixes in the NamespaceResolver

Returns:Enumeration<String>

An Enumeration containing the prefixes in the NamespaceResolver

getPrefixesToNamespacesback to summary
public Map<String, String> getPrefixesToNamespaces()
hasPrefixback to summary
public boolean hasPrefix(String prefix)

Indicates whether given prefix is assigned to a name-space.

Parameters
prefix:String

name-space prefix

Returns:boolean

true if prefix is present in prefix to name-space map (getPrefixesToNamespaces()

hasPrefixesToNamespacesback to summary
public boolean hasPrefixesToNamespaces()
putback to summary
public void put(String prefix, String namespaceURI)

Adds a namespace to the collection of namespaces on the NamespaceResolver

Parameters
prefix:String

The prefix for a namespace

namespaceURI:String

The namespace URI associated with the specified prefix

removeNamespaceback to summary
public void removeNamespace(String prefix)
resolveNamespacePrefixback to summary
public String resolveNamespacePrefix(String prefix)

Implements org.eclipse.persistence.platform.xml.XMLNamespaceResolver.resolveNamespacePrefix.

Returns the namespace URI associated with a specified namespace prefix

Parameters
prefix:String

The prefix to lookup a namespace URI for

Returns:String

The namespace URI associated with the specified prefix

Annotations
@Override
resolveNamespaceURIback to summary
public String resolveNamespaceURI(String uri)

Return the namespace prefix associated with a namespace URI.

Parameters
uri:String

A namespace URI.

Returns:String

The prefix associated with the namespace URI.

resolveNamespaceURIback to summary
private String resolveNamespaceURI(Node node, String uri)
setDefaultNamespaceURIback to summary
public void setDefaultNamespaceURI(String namespaceUri)
setDOMback to summary
public void setDOM(Node dom)
setNamespacesback 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

Parameters
names:Vector<Namespace>

A Vector of namespace URIs

setPrefixesToNamespacesback to summary
private void setPrefixesToNamespaces(Map<String, String> input)
org.eclipse.persistence.internal.oxm back to summary

private Class NamespaceResolver.IteratorEnumeration<E>

extends Object
implements Enumeration<E>
Class Inheritance
  • java.lang.Object
  • org.eclipse.persistence.internal.oxm.NamespaceResolver.IteratorEnumeration
All Implemented Interfaces
java.util.Enumeration

Field Summary

Modifier and TypeField and Description
private final Iterator<E>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
hasMoreElements()

Implements java.util.Enumeration.hasMoreElements.

Tests if this enumeration contains more elements.
public E
nextElement()

Implements java.util.Enumeration.nextElement.

Returns the next element of this enumeration if this enumeration object has at least one more element to provide.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iteratorback to summary
private final Iterator<E> iterator

Constructor Detail

IteratorEnumerationback to summary
public IteratorEnumeration(Iterator<E> iterator)

Method Detail

hasMoreElementsback to summary
public boolean hasMoreElements()

Implements java.util.Enumeration.hasMoreElements.

Doc from java.util.Enumeration.hasMoreElements.

Tests if this enumeration contains more elements.

Returns:boolean

true if and only if this enumeration object contains at least one more element to provide; false otherwise.

Annotations
@Override
nextElementback to summary
public E nextElement()

Implements java.util.Enumeration.nextElement.

Doc from java.util.Enumeration.nextElement.

Returns the next element of this enumeration if this enumeration object has at least one more element to provide.

Returns:E

the next element of this enumeration.

Annotations
@Override