Package org.opensaml.core.xml
Class NamespaceManager
- java.lang.Object
-
- org.opensaml.core.xml.NamespaceManager
-
public class NamespaceManager extends Object
A class which is responsible for managing XML namespace-related data for anXMLObject.Code which mutates the state of an XMLObject such that XML namespace-related data is also logically changed, should call the appropriate method, based on the type of change being made.
-
-
Field Summary
Fields Modifier and Type Field Description private Set<Namespace>attrNamesRegistered namespaces of attribute names.private Map<String,Namespace>attrValuesRegistered namespaces of attribute values.private NamespacecontentValueRegistered namespaces of content values.private Set<Namespace>declsExplicitly declared namespaces.static StringDEFAULT_NS_TOKENThe token used to represent the default namespace ingetNonVisibleNamespacePrefixes().private NamespaceelementNameXMLObject name namespace.private NamespaceelementTypeXMLObject type namespace.private XMLObjectownerThe owning XMLObject.private static NamespaceXML_NAMESPACEThe 'xml' namespace.private static NamespaceXSI_NAMESPACEThe 'xsi' namespace.
-
Constructor Summary
Constructors Constructor Description NamespaceManager(XMLObject owningObject)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddNamespace(Set<Namespace> namespaces, Namespace newNamespace)Add a Namespace to a set of Namespaces.private voidaddPrefixes(Set<String> prefixes, Collection<Namespace> namespaces)Add the prefixes from a collection of namespaces to a set of prefixes.private NamespacebuildNamespace(QName name)private booleancheckQName(QName name)Check whether the supplied QName contains non-empty namespace info and should be managed by the namespace manager.voidderegisterAttributeName(QName attributeName)Deregister a namespace-qualified attribute name.voidderegisterAttributeValue(String attributeID)Deregister a QName attribute value.voidderegisterContentValue()Deregister a QName content value.voidderegisterNamespaceDeclaration(Namespace namespace)Deregister a namespace declaration.static StringgenerateAttributeID(QName name)From a QName representing a qualified attribute name, generate an attribute ID suitable for use inregisterAttributeValue(String, QName)andderegisterAttributeValue(String).Set<Namespace>getAllNamespacesInSubtreeScope()Get the set of all namespaces which are in scope within the subtree rooted at the owning XMLObject.private NamespacegetElementNameNamespace()Return a Namespace instance representing the namespace of the element name.private NamespacegetElementTypeNamespace()Return a Namespace instance representing the namespace of the element type, if known.Set<Namespace>getNamespaceDeclarations()Get the set of namespace declarations registered on the owning XMLObject.Set<Namespace>getNamespaces()Get the set of namespaces currently in use on the owning XMLObject.private Set<Namespace>getNonVisibleNamespaceCandidates()Get the set of non-visibly used namespaces used on the owning XMLObject (only the owner, not the owner's children).Set<String>getNonVisibleNamespacePrefixes()Obtain the set of namespace prefixes used in a non-visible manner on owning XMLObject and its children.Set<Namespace>getNonVisibleNamespaces()Obtain the set of namespaces used in a non-visible manner on owning XMLObject and its children.XMLObjectgetOwner()Get the owning XMLObject instance.private Set<Namespace>getVisibleNamespaces()Get the set of namespaces which are currently visibly-used on the owning XMLObject (only the owner, not its children).private Set<Namespace>mergeNamespaceCollections(Collection<Namespace>... namespaces)Merge 2 or more Namespace collections into a single set.voidregisterAttributeName(QName attributeName)Register a namespace-qualified attribute name.voidregisterAttributeValue(String attributeID, QName attributeValue)Register a QName attribute value.voidregisterContentValue(QName content)Register a QName element content value.voidregisterElementName(QName name)Register the owning XMLObject's element name.voidregisterElementType(QName type)Register the owning XMLObject's element type, if explicitly declared via an xsi:type.voidregisterNamespaceDeclaration(Namespace namespace)Register a namespace declaration.private voidremoveNamespace(Set<Namespace> namespaces, Namespace oldNamespace)Remove a Namespace from a set of Namespaces.
-
-
-
Field Detail
-
DEFAULT_NS_TOKEN
public static final String DEFAULT_NS_TOKEN
The token used to represent the default namespace ingetNonVisibleNamespacePrefixes().- See Also:
- Constant Field Values
-
XML_NAMESPACE
private static final Namespace XML_NAMESPACE
The 'xml' namespace.
-
XSI_NAMESPACE
private static final Namespace XSI_NAMESPACE
The 'xsi' namespace.
-
owner
@Nonnull private final XMLObject owner
The owning XMLObject.
-
elementName
private Namespace elementName
XMLObject name namespace.
-
elementType
private Namespace elementType
XMLObject type namespace.
-
attrValues
@Nonnull private final Map<String,Namespace> attrValues
Registered namespaces of attribute values.
-
contentValue
private Namespace contentValue
Registered namespaces of content values.
-
-
Constructor Detail
-
NamespaceManager
public NamespaceManager(@Nonnull XMLObject owningObject)Constructor.- Parameters:
owningObject- the XMLObject whose namespace info is to be managed
-
-
Method Detail
-
generateAttributeID
@Nonnull @NotEmpty public static String generateAttributeID(@Nonnull QName name)
From a QName representing a qualified attribute name, generate an attribute ID suitable for use inregisterAttributeValue(String, QName)andderegisterAttributeValue(String).- Parameters:
name- attribute name as a QName- Returns:
- a string attribute ID
-
getOwner
@Nonnull public XMLObject getOwner()
Get the owning XMLObject instance.- Returns:
- the owning XMLObject
-
getNamespaces
@Nonnull public Set<Namespace> getNamespaces()
Get the set of namespaces currently in use on the owning XMLObject.- Returns:
- the unmodifiable set of namespaces
-
registerNamespaceDeclaration
public void registerNamespaceDeclaration(@Nonnull Namespace namespace)Register a namespace declaration.- Parameters:
namespace- the namespace to register
-
deregisterNamespaceDeclaration
public void deregisterNamespaceDeclaration(@Nonnull Namespace namespace)Deregister a namespace declaration.- Parameters:
namespace- the namespace to deregister
-
getNamespaceDeclarations
@Nonnull public Set<Namespace> getNamespaceDeclarations()
Get the set of namespace declarations registered on the owning XMLObject.- Returns:
- the set of namespace declarations
-
registerAttributeName
public void registerAttributeName(@Nonnull QName attributeName)Register a namespace-qualified attribute name.- Parameters:
attributeName- the attribute name to register
-
deregisterAttributeName
public void deregisterAttributeName(@Nonnull QName attributeName)Deregister a namespace-qualified attribute name.- Parameters:
attributeName- the attribute name to deregister
-
registerAttributeValue
public void registerAttributeValue(@Nonnull String attributeID, @Nonnull QName attributeValue)Register a QName attribute value.- Parameters:
attributeID- unique identifier for the attribute within the XMLObject's content modelattributeValue- the QName value to register
-
deregisterAttributeValue
public void deregisterAttributeValue(@Nonnull String attributeID)Deregister a QName attribute value.- Parameters:
attributeID- unique identifier for the attribute within the XMLObject's content model
-
registerContentValue
public void registerContentValue(@Nonnull QName content)Register a QName element content value.- Parameters:
content- the QName value to register
-
deregisterContentValue
public void deregisterContentValue()
Deregister a QName content value.
-
getNonVisibleNamespacePrefixes
@Nonnull public Set<String> getNonVisibleNamespacePrefixes()
Obtain the set of namespace prefixes used in a non-visible manner on owning XMLObject and its children.The primary use case for this information is to support the inclusive prefixes information that may optionally be supplied as a part of XML exclusive canonicalization.
- Returns:
- the set of non-visibly used namespace prefixes
-
getNonVisibleNamespaces
@Nonnull public Set<Namespace> getNonVisibleNamespaces()
Obtain the set of namespaces used in a non-visible manner on owning XMLObject and its children.The primary use case for this information is to support the inclusive prefixes information that may optionally be supplied as a part of XML exclusive canonicalization.
- Returns:
- the set of non-visibly used namespaces
-
getAllNamespacesInSubtreeScope
@Nonnull public Set<Namespace> getAllNamespacesInSubtreeScope()
Get the set of all namespaces which are in scope within the subtree rooted at the owning XMLObject.- Returns:
- set of all namespaces in scope for the owning object
-
registerElementName
public void registerElementName(@Nonnull QName name)Register the owning XMLObject's element name.- Parameters:
name- the element name to register
-
registerElementType
public void registerElementType(@Nullable QName type)Register the owning XMLObject's element type, if explicitly declared via an xsi:type.- Parameters:
type- the element type to register
-
getElementNameNamespace
@Nullable private Namespace getElementNameNamespace()
Return a Namespace instance representing the namespace of the element name.- Returns:
- the element name's namespace
-
getElementTypeNamespace
@Nullable private Namespace getElementTypeNamespace()
Return a Namespace instance representing the namespace of the element type, if known.- Returns:
- the element type's namespace
-
buildNamespace
@Nonnull private Namespace buildNamespace(@Nonnull QName name)
- Parameters:
name- the source QName- Returns:
- a Namespace built using the information in the QName
-
addNamespace
private void addNamespace(@Nonnull Set<Namespace> namespaces, @Nullable Namespace newNamespace)Add a Namespace to a set of Namespaces. Namespaces with identical URI and prefix will be treated as equivalent.- Parameters:
namespaces- the set of namespacesnewNamespace- the namespace to add to the set
-
removeNamespace
private void removeNamespace(@Nonnull Set<Namespace> namespaces, @Nullable Namespace oldNamespace)Remove a Namespace from a set of Namespaces.- Parameters:
namespaces- the set of namespacesoldNamespace- the namespace to add to the set
-
mergeNamespaceCollections
@Nonnull private Set<Namespace> mergeNamespaceCollections(Collection<Namespace>... namespaces)
Merge 2 or more Namespace collections into a single set.- Parameters:
namespaces- list of Namespaces to merge- Returns:
- the a new set of merged Namespaces
-
getVisibleNamespaces
@Nonnull private Set<Namespace> getVisibleNamespaces()
Get the set of namespaces which are currently visibly-used on the owning XMLObject (only the owner, not its children).- Returns:
- the set of visibly-used namespaces
-
getNonVisibleNamespaceCandidates
@Nonnull private Set<Namespace> getNonVisibleNamespaceCandidates()
Get the set of non-visibly used namespaces used on the owning XMLObject (only the owner, not the owner's children).- Returns:
- the set of non-visibly-used namespaces
-
addPrefixes
private void addPrefixes(@Nonnull Set<String> prefixes, @Nonnull Collection<Namespace> namespaces)Add the prefixes from a collection of namespaces to a set of prefixes. The value used to represent the default namespace will be normalized toDEFAULT_NS_TOKEN.- Parameters:
prefixes- the set of prefixes to which to addnamespaces- the source set of Namespaces
-
checkQName
private boolean checkQName(@Nullable QName name)Check whether the supplied QName contains non-empty namespace info and should be managed by the namespace manager.- Parameters:
name- the QName to check- Returns:
- true if the QName contains non-empty namespace info and should be managed, false otherwise
-
-