Top Description Methods
org.glassfish.jaxb.runtime.v2.runtime

public Interface NamespaceContext2

extends NamespaceContext
Known Direct Implementers
org.glassfish.jaxb.runtime.v2.runtime.output.NamespaceContextImpl
Imports
com.sun.istack.NotNull, javax.xml.namespace.NamespaceContext

Maintains namespace <-> prefix bindings.

This interface extends NamespaceContext and provides an additional functionality, which is necessary to declare namespaced attributes on elements. The added method is for self-consumption by the marshaller. This object is composed into a Serializer.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

returns the assigned prefix. If the namespace is bound to the default namespace, null is returned.
declareNamespace
(String namespaceUri, String
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.
preferedPrefix
,
boolean
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.
requirePrefix
)

Declares a new namespace binding within the current context.

public int
force(String uri, String prefix)

Forcibly make a namespace declaration in effect.

Inherited from javax.xml.namespace.NamespaceContext:
getNamespaceURIgetPrefixgetPrefixes

Method Detail

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

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.

Parameters
preferedPrefix:String

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

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

returns the assigned prefix. If the namespace is bound to the default namespace, null is returned.

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

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.