Top Description Inners Fields Constructors Methods
org.glassfish.jaxb.runtime.v2.runtime.output

public final Class NamespaceContextImpl

extends Object
implements NamespaceContext2
Class Inheritance
All Implemented Interfaces
org.glassfish.jaxb.runtime.v2.runtime.NamespaceContext2, javax.xml.namespace.NamespaceContext
Imports
com.sun.istack.NotNull, .Nullable, org.glassfish.jaxb.runtime.marshaller.NamespacePrefixMapper, org.glassfish.jaxb.core.v2.WellKnownNamespace, org.glassfish.jaxb.runtime.v2.runtime.Name, .NamespaceContext2, .XMLSerializer, org.xml.sax.SAXException, javax.xml.XMLConstants, javax.xml.stream.XMLStreamException, java.io.IOException, java.util.Collections, .Iterator

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 and Inner Type Summary

Modifier and TypeClass and Description
public class
NamespaceContextImpl.Element

This model of namespace declarations maintain the following invariants.

Field Summary

Modifier and TypeField and Description
public boolean
collectionMode

True to allow new URIs to be declared.

private NamespaceContextImpl.Element
private static final NamespacePrefixMapper
defaultNamespacePrefixMapper

Default NamespacePrefixMapper implementation used when it is not specified by the user.

private String[]
private final XMLSerializer
private String[]
private NamespacePrefixMapper
prefixMapper

Never null.

private int
size

Number of URIs declared.

private final NamespaceContextImpl.Element
top

This is the Element whose prev==null.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
count()

Number of total bindings declared.

public String
declareNamespace(String namespaceUri, String preferedPrefix, boolean requirePrefix)

Implements org.glassfish.jaxb.runtime.v2.runtime.NamespaceContext2.declareNamespace.

Declares a new namespace binding within the current context.

public int
declareNsUri(String uri, String preferedPrefix, boolean requirePrefix)

Returns the prefix index to the specified URI.

public int
force(String uri, String prefix)

Implements org.glassfish.jaxb.runtime.v2.runtime.NamespaceContext2.force.

Forcibly make a namespace declaration in effect.

public NamespaceContextImpl.Element
public String
getNamespaceURI(int prefixIndex)

public String

Returns:

null if the prefix is unbound.
getNamespaceURI
(String prefix)

Implements javax.xml.namespace.NamespaceContext.getNamespaceURI.

Gets the namespace URI that is bound to the specified prefix.

public String
getPrefix(int prefixIndex)

Gets the prefix from a prefix index.

public String
getPrefix(String uri)

Implements javax.xml.namespace.NamespaceContext.getPrefix.

Returns the prefix of the specified URI, or null if none exists.

public Iterator<String>
getPrefixes(String uri)

Implements javax.xml.namespace.NamespaceContext.getPrefixes.

Get all prefixes bound to a Namespace URI in the current scope.

public int
getPrefixIndex(String uri)

Returns the prefix index of the specified URI.

public NamespacePrefixMapper
private String
public int

Returns:

the index of this new binding.
put
(String uri, String prefix)

Puts this new binding into the declared prefixes list without doing any duplicate check.

public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

collectionModeback to summary
public boolean collectionMode

True to allow new URIs to be declared. False otherwise.

currentback to summary
private NamespaceContextImpl.Element current
defaultNamespacePrefixMapperback to summary
private static final NamespacePrefixMapper defaultNamespacePrefixMapper

Default NamespacePrefixMapper implementation used when it is not specified by the user.

nsUrisback to summary
private String[] nsUris
ownerback to summary
private final XMLSerializer owner
prefixesback to summary
private String[] prefixes
prefixMapperback to summary
private NamespacePrefixMapper prefixMapper

Never null.

sizeback to summary
private int size

Number of URIs declared. Identifies the valid portion of the prefixes and nsUris arrays.

topback to summary
private final NamespaceContextImpl.Element top

This is the Element whose prev==null. This element is used to hold the contextual namespace bindings that are assumed to be outside of the document we are marshalling. Specifically the xml prefix and any other user-specified bindings.

See Also
NamespacePrefixMapper#getPreDeclaredNamespaceUris()

Constructor Detail

NamespaceContextImplback to summary
public NamespaceContextImpl(XMLSerializer owner)

Method Detail

countback to summary
public int count()

Number of total bindings declared.

declareNamespaceback to summary
public String declareNamespace(String namespaceUri, String preferedPrefix, boolean requirePrefix)

Implements org.glassfish.jaxb.runtime.v2.runtime.NamespaceContext2.declareNamespace.

Doc from org.glassfish.jaxb.runtime.v2.runtime.NamespaceContext2.declareNamespace.

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.

Annotations
@Override
declareNsUriback to summary
public int declareNsUri(String uri, String preferedPrefix, boolean requirePrefix)

Returns the prefix index to the specified URI. This method allocates a new URI if necessary.

forceback to summary
public int force(String uri, String prefix)

Implements org.glassfish.jaxb.runtime.v2.runtime.NamespaceContext2.force.

Doc from org.glassfish.jaxb.runtime.v2.runtime.NamespaceContext2.force.

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.

Annotations
@Override
getCurrentback to summary
public NamespaceContextImpl.Element getCurrent()
getNamespaceURIback to summary
public String getNamespaceURI(int prefixIndex)
getNamespaceURIback to summary
public String getNamespaceURI(String prefix)

Implements javax.xml.namespace.NamespaceContext.getNamespaceURI.

Gets the namespace URI that is bound to the specified prefix.

Returns:String

null if the prefix is unbound.

Annotations
@Override
getPrefixback to summary
public String getPrefix(int prefixIndex)

Gets the prefix from a prefix index. The behavior is undefined if the index is out of range.

getPrefixback to summary
public String getPrefix(String uri)

Implements javax.xml.namespace.NamespaceContext.getPrefix.

Returns the prefix of the specified URI, or null if none exists.

Annotations
@Override
getPrefixesback to summary
public Iterator<String> getPrefixes(String uri)

Implements javax.xml.namespace.NamespaceContext.getPrefixes.

Doc from javax.xml.namespace.NamespaceContext.getPrefixes.

Get all prefixes bound to a Namespace URI in the current scope.

An Iterator over String elements is returned in an arbitrary, implementation dependent, order.

The Iterator is not modifiable. e.g. the remove() method will throw UnsupportedOperationException.

When requesting prefixes by Namespace URI, the following table describes the returned prefixes value for all Namespace URI values:

Return value for specified Namespace URIs
Namespace URI parameter prefixes value returned
bound Namespace URI, including the <default Namespace URI> Iterator over prefixes bound to Namespace URI in the current scope in an arbitrary, implementation dependent, order
unbound Namespace URI empty Iterator
XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace") Iterator with one element set to XMLConstants.XML_NS_PREFIX ("xml")
XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/") Iterator with one element set to XMLConstants.XMLNS_ATTRIBUTE ("xmlns")
null IllegalArgumentException is thrown
Annotations
@Override
getPrefixIndexback to summary
public int getPrefixIndex(String uri)

Returns the prefix index of the specified URI. It is an error if the URI is not declared.

getPrefixMapperback to summary
public NamespacePrefixMapper getPrefixMapper()
makeUniquePrefixback to summary
private String makeUniquePrefix()
putback to summary
public int put(String uri, String prefix)

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:int

the index of this new binding.

resetback to summary
public void reset()
setPrefixMapperback to summary
public void setPrefixMapper(NamespacePrefixMapper mapper)
org.glassfish.jaxb.runtime.v2.runtime.output back to summary

public final Class NamespaceContextImpl.Element

extends Object
Class Inheritance
  • java.lang.Object
  • org.glassfish.jaxb.runtime.v2.runtime.output.NamespaceContextImpl.Element

This model of namespace declarations maintain the following invariants.

Field Summary

Modifier and TypeField and Description
private int
baseIndex

The numbe of prefixes declared by ancestor Elements.

public final NamespaceContextImpl
private int
private final int
depth

The depth of the Element.

private String
private Name
elementName

Tag name of this element.

private int
private Object
private NamespaceContextImpl.Element
private int
private Object
outerPeer

Used for the binder.

private final NamespaceContextImpl.Element
prev

Elements form a doubly-linked list.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
count()

Gets the number of bindings declared on this element.

public void
public int
public Object
public String
getNsUri(int
between 0 and count()
idx
)

Gets the namespace URI declared in this context.

public Object
public NamespaceContextImpl.Element
getParent()

Gets the parent .

public String
getPrefix(int
between 0 and count()
idx
)

Gets the prefix declared in this context.

public boolean
isRootElement()

Returns true if this represents the root element that we are marshalling.

private void
public NamespaceContextImpl.Element
pop()

public NamespaceContextImpl.Element
push()

public void
setTagName(int prefix, String localName, Object outerPeer)

public void
setTagName(Name tagName, Object outerPeer)

public void
startElement(XmlOutput out, Object innerPeer)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseIndexback to summary
private int baseIndex

The numbe of prefixes declared by ancestor Elements.

contextback to summary
public final NamespaceContextImpl context
defaultPrefixIndexback to summary
private int defaultPrefixIndex
depthback to summary
private final int depth

The depth of the Element. This value is equivalent as the result of the following computation.

int depth() {
  int i=-1;
  for(Element e=this; e!=null;e=e.prev)
    i++;
  return i;
}
elementLocalNameback to summary
private String elementLocalName
elementNameback to summary
private Name elementName

Tag name of this element. Either this field is used or the elementNamePrefix and elementLocalName pair.

elementNamePrefixback to summary
private int elementNamePrefix
innerPeerback to summary
private Object innerPeer
nextback to summary
private NamespaceContextImpl.Element next
oldDefaultNamespaceUriIndexback to summary
private int oldDefaultNamespaceUriIndex
outerPeerback to summary
private Object outerPeer

Used for the binder. The JAXB object that corresponds to this element.

prevback to summary
private final NamespaceContextImpl.Element prev

Elements form a doubly-linked list.

Constructor Detail

Elementback to summary
private Element(NamespaceContextImpl context, NamespaceContextImpl.Element prev)

Method Detail

countback to summary
public int count()

Gets the number of bindings declared on this element.

endElementback to summary
public void endElement(XmlOutput out) throws IOException, SAXException, XMLStreamException
getBaseback to summary
public int getBase()
getInnerPeerback to summary
public Object getInnerPeer()
getNsUriback to summary
public String getNsUri(int idx)

Gets the namespace URI declared in this context.

Parameters
idx:int

between 0 and count()

getOuterPeerback to summary
public Object getOuterPeer()
getParentback to summary
public NamespaceContextImpl.Element getParent()

Gets the parent .

getPrefixback to summary
public String getPrefix(int idx)

Gets the prefix declared in this context.

Parameters
idx:int

between 0 and count()

isRootElementback to summary
public boolean isRootElement()

Returns true if this represents the root element that we are marshalling.

onPushedback to summary
private void onPushed()
popback to summary
public NamespaceContextImpl.Element pop()
pushback to summary
public NamespaceContextImpl.Element push()
setTagNameback to summary
public void setTagName(int prefix, String localName, Object outerPeer)
setTagNameback to summary
public void setTagName(Name tagName, Object outerPeer)
startElementback to summary
public void startElement(XmlOutput out, Object innerPeer) throws IOException, XMLStreamException