Class NamespaceContextImpl
java.lang.Object
com.sun.xml.bind.v2.runtime.output.NamespaceContextImpl
- All Implemented Interfaces:
NamespaceContext2
,NamespaceContext
Keeps track of in-scope namespace bindings for the marshaller.
This class is also used to keep track of tag names for each element for the marshaller (for the performance reason.)
- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal class
This model of namespace declarations maintain the following invariants. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
count()
Number of total bindings declared.declareNamespace
(String namespaceUri, String preferedPrefix, boolean requirePrefix) Declares a new namespace binding within the current context.int
declareNsUri
(String uri, String preferedPrefix, boolean requirePrefix) Returns the prefix index to the specified URI.int
Forcibly make a namespace declaration in effect.getNamespaceURI
(int prefixIndex) getNamespaceURI
(String prefix) Gets the namespace URI that is bound to the specified prefix.getPrefix
(int prefixIndex) Gets the prefix from a prefix index.Returns the prefix of the specified URI, or null if none exists.getPrefixes
(String uri) int
getPrefixIndex
(String uri) Returns the prefix index of the specified URI.int
Puts this new binding into the declared prefixes list without doing any duplicate check.void
reset()
void
setPrefixMapper
(NamespacePrefixMapper mapper)
-
Field Details
-
collectionMode
public boolean collectionModeTrue to allow new URIs to be declared. False otherwise.
-
-
Constructor Details
-
NamespaceContextImpl
-
-
Method Details
-
setPrefixMapper
-
getPrefixMapper
-
reset
public void reset() -
declareNsUri
Returns the prefix index to the specified URI. This method allocates a new URI if necessary. -
force
Description copied from interface:NamespaceContext2
Forcibly make a namespace declaration in effect. If the (prefix,uri) binding is already in-scope, this method simply returns the assigned prefix index. Otherwise a new declaration will be put.- Specified by:
force
in interfaceNamespaceContext2
-
put
Puts this new binding into the declared prefixes list without doing any duplicate check. This can be used to forcibly set namespace declarations.Most of the time
declareNamespace(String, String, boolean)
shall be used.- Returns:
- the index of this new binding.
-
getCurrent
-
getPrefixIndex
Returns the prefix index of the specified URI. It is an error if the URI is not declared. -
getPrefix
Gets the prefix from a prefix index. The behavior is undefined if the index is out of range. -
getNamespaceURI
-
getNamespaceURI
Gets the namespace URI that is bound to the specified prefix.- Specified by:
getNamespaceURI
in interfaceNamespaceContext
- Returns:
- null if the prefix is unbound.
-
getPrefix
Returns the prefix of the specified URI, or null if none exists.- Specified by:
getPrefix
in interfaceNamespaceContext
-
getPrefixes
- Specified by:
getPrefixes
in interfaceNamespaceContext
-
declareNamespace
Description copied from interface:NamespaceContext2
Declares a new namespace binding within the current context.The prefix is automatically assigned by MarshallingContext. If a given namespace URI is already declared, nothing happens.
It is NOT an error to declare the same namespace URI more than once.
For marshalling to work correctly, all namespace bindings for an element must be declared between its startElement method and its endAttributes event. Calling the same method with the same parameter between the endAttributes and the endElement returns the same prefix.
- Specified by:
declareNamespace
in interfaceNamespaceContext2
- Parameters:
preferedPrefix
- If the caller has any particular preference to the prefix, pass that as a parameter. The callee will try to honor it. Set null if there's no particular preference.requirePrefix
- If this parameter is true, this method must assign a prefix to this namespace, even if it's already bound to the default namespace. IOW, this method will never return null if this flag is true. This functionality is necessary to declare namespace URI used for attribute names.- Returns:
- returns the assigned prefix. If the namespace is bound to the default namespace, null is returned.
-
count
public int count()Number of total bindings declared.
-