Class NamespaceResolver
- java.lang.Object
-
- org.eclipse.persistence.internal.oxm.NamespaceResolver
-
- All Implemented Interfaces:
XMLNamespaceResolver
- Direct Known Subclasses:
NamespaceResolver
public class NamespaceResolver extends 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
-
-
Constructor Summary
Constructors Constructor Description NamespaceResolver()
Default constructor, creates a new NamespaceResolver.NamespaceResolver(NamespaceResolver namespaceResolver)
Copy Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
generatePrefix()
String
generatePrefix(String defaultPrefix)
String
getDefaultNamespaceURI()
Vector
getNamespaces()
INTERNAL: Returns a Vector of of Namespace objects in the current Namespace Resolver Used for deployment XMLEnumeration
getPrefixes()
Returns the list of prefixes in the NamespaceResolverMap<String,String>
getPrefixesToNamespaces()
boolean
hasPrefix(String prefix)
Indicates whether givenprefix
is assigned to a name-space.boolean
hasPrefixesToNamespaces()
void
put(String prefix, String namespaceURI)
Adds a namespace to the collection of namespaces on the NamespaceResolvervoid
removeNamespace(String prefix)
String
resolveNamespacePrefix(String prefix)
Returns the namespace URI associated with a specified namespace prefixString
resolveNamespaceURI(String uri)
Return the namespace prefix associated with a namespace URI.void
setDefaultNamespaceURI(String namespaceUri)
void
setDOM(Node dom)
void
setNamespaces(Vector names)
INTERNAL: Set the namespaces on the namespace resolver based on the specified Vector of Namespace objects Used for deployment XML
-
-
-
Constructor Detail
-
NamespaceResolver
public NamespaceResolver()
Default constructor, creates a new NamespaceResolver.
-
NamespaceResolver
public NamespaceResolver(NamespaceResolver namespaceResolver)
Copy Constructor- Since:
- EclipseLink 2.5.0
-
-
Method Detail
-
hasPrefixesToNamespaces
public boolean hasPrefixesToNamespaces()
-
hasPrefix
public boolean hasPrefix(String prefix)
Indicates whether givenprefix
is assigned to a name-space.- Parameters:
prefix
- name-space prefix- Returns:
true
ifprefix
is present in prefix to name-space map (getPrefixesToNamespaces()
-
setDOM
public void setDOM(Node dom)
-
resolveNamespacePrefix
public String resolveNamespacePrefix(String prefix)
Returns the namespace URI associated with a specified namespace prefix- Specified by:
resolveNamespacePrefix
in interfaceXMLNamespaceResolver
- Parameters:
prefix
- The prefix to lookup a namespace URI for- Returns:
- The namespace URI associated with the specified prefix
-
resolveNamespaceURI
public String resolveNamespaceURI(String uri)
Return the namespace prefix associated with a namespace URI.- Parameters:
uri
- A namespace URI.- Returns:
- The prefix associated with the namespace URI.
-
put
public void put(String prefix, String namespaceURI)
Adds a namespace to the collection of namespaces on the NamespaceResolver- Parameters:
prefix
- The prefix for a namespacenamespaceURI
- The namespace URI associated with the specified prefix
-
getPrefixes
public Enumeration getPrefixes()
Returns the list of prefixes in the NamespaceResolver- Returns:
- An Enumeration containing the prefixes in the NamespaceResolver
-
getNamespaces
public 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(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 String generatePrefix()
-
removeNamespace
public void removeNamespace(String prefix)
-
setDefaultNamespaceURI
public void setDefaultNamespaceURI(String namespaceUri)
-
getDefaultNamespaceURI
public String getDefaultNamespaceURI()
-
-