Package org.opensaml.core.xml.util

# Class XMLObjectSupport

java.lang.Object
org.opensaml.core.xml.util.XMLObjectSupport

public final class XMLObjectSupport extends Object
A helper class for working with XMLObjects.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`XMLObjectSupport.CloneOutputOption`
Options for handling output of XMLObject cloning.

## Field Summary

Fields
Modifier and Type
Field
Description
`private static final org.slf4j.Logger`
`LOG`
Logger.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`private`
`XMLObjectSupport()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`static XMLObject`
`buildXMLObject(QName elementName)`
Build an XMLObject based on the element name.
`static XMLObject`
`buildXMLObject(QName elementName, QName typeName)`
Build an XMLObject based on the element nane and xsi:type.
`static <T extends XMLObject>
T`
`cloneXMLObject(T originalXMLObject)`
Clone an XMLObject by brute force:
`static <T extends XMLObject>
T`
`cloneXMLObject(T originalXMLObject, XMLObjectSupport.CloneOutputOption cloneOutputOption)`
Clone an XMLObject by brute force:
`static XMLObjectBuilder<?>`
`getBuilder(QName typeOrName)`
Obtain an XMLObject builder for the given QName.
`static Marshaller`
`getMarshaller(QName typeOrName)`
Obtain an XMLObject marshaller for the given QName.
`static Marshaller`
`getMarshaller(XMLObject xmlObject)`
Obtain an XMLObject marshaller for the given XMLObject.
`private static XMLObjectProviderRegistry`
`getProviderRegistry()`
Obtain the XMLObject provider registry.
`static Unmarshaller`
`getUnmarshaller(QName typeOrName)`
Obtain an XMLObject unmarshaller for the given QName.
`static Unmarshaller`
`getUnmarshaller(Element element)`
Obtain an XMLObject unmarshaller for the given DOM Element.
`static String`
`lookupNamespacePrefix(XMLObject xmlObject, String namespaceURI)`
Get the prefix bound to the specified namespace URI within the scope of the specified XMLObject.
`static String`
`lookupNamespaceURI(XMLObject xmlObject, String prefix)`
Get the namespace URI bound to the specified prefix within the scope of the specified XMLObject.
`static Element`
`marshall(XMLObject xmlObject)`
Marshall an XMLObject.
`static void`
`marshallAttribute(QName attributeName, String attributeValue, Element domElement, boolean isIDAttribute)`
Marshall an attribute name and value to a DOM Element.
`static void`
`marshallAttribute(QName attributeName, List<String> attributeValues, Element domElement, boolean isIDAttribute)`
Marshall an attribute name and value to a DOM Element.
`static void`
`marshallAttributeIDness(String namespaceURI, String localPart, Element domElement, boolean isIDAttribute)`
Marshall the ID-ness of an attribute into the indicated DOM Element.
`static void`
`marshallAttributeIDness(QName attributeName, Element domElement, boolean isIDAttribute)`
Marshall the ID-ness of an attribute into the indicated DOM Element.
`static void`
`marshallAttributeMap(AttributeMap attributeMap, Element domElement)`
Marshall the attributes represented by the indicated AttributeMap into the indicated DOM Element.
`static void`
`marshallAttributeMapIDness(AttributeMap attributeMap, Element domElement)`
Marshall the ID-ness of attributes represented by the indicated AttributeMap into the indicated DOM Element.
`static void`
`marshallToOutputStream(XMLObject xmlObject, OutputStream outputStream)`
Marshall an XMLObject to an OutputStream.
`static XMLObject`
`unmarshallFromInputStream(ParserPool parserPool, InputStream inputStream)`
Unmarshall a Document from an InputSteam.
`static XMLObject`
`unmarshallFromReader(ParserPool parserPool, Reader reader)`
Unmarshall a Document from a Reader.
`static void`
`unmarshallToAttributeMap(AttributeMap attributeMap, Attr attribute)`
Unmarshall a DOM Attr to an AttributeMap.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### LOG

@Nonnull private static final org.slf4j.Logger LOG
Logger.

## Constructor Details

### XMLObjectSupport

private XMLObjectSupport()
Constructor.

## Method Details

### cloneXMLObject

@Nonnull public static <T extends XMLObject> T cloneXMLObject(@Nonnull T originalXMLObject) throws MarshallingException, UnmarshallingException
Clone an XMLObject by brute force:

1) Marshall the original object if necessary 2) Clone the resulting DOM Element 3) Unmarshall a new XMLObject tree around it.

This method variant is equivalent to `cloneXMLObject(originalXMLObject, CloneOutputOption.DropDOM).`

Type Parameters:
  `T` - the type of object being cloned
Parameters:
  `originalXMLObject` - the object to be cloned
Returns:
  a clone of the original object
Throws:
  `MarshallingException` - if original object can not be marshalled
  `UnmarshallingException` - if cloned object tree can not be unmarshalled

### cloneXMLObject

@Nonnull public static <T extends XMLObject> T cloneXMLObject(@Nonnull T originalXMLObject, @Nonnull XMLObjectSupport.CloneOutputOption cloneOutputOption) throws MarshallingException, UnmarshallingException
Clone an XMLObject by brute force:

1) Marshall the original object if necessary 2) Clone the resulting DOM Element 3) Unmarshall a new XMLObject tree around it.

Type Parameters:
  `T` - the type of object being cloned
Parameters:
  `originalXMLObject` - the object to be cloned
  `cloneOutputOption` - the option for handling the cloned object output
Returns:
  a clone of the original object
Throws:
  `MarshallingException` - if original object can not be marshalled
  `UnmarshallingException` - if cloned object tree can not be unmarshalled

### unmarshallFromInputStream

@Nonnull public static XMLObject unmarshallFromInputStream(@Nonnull ParserPool parserPool, @Nonnull InputStream inputStream) throws XMLParserException, UnmarshallingException
Unmarshall a Document from an InputSteam.

Parameters:
  `parserPool` - the ParserPool instance to use
  `inputStream` - the InputStream to unmarshall
Returns:
  the unmarshalled XMLObject
Throws:
  `XMLParserException` - if there is a problem parsing the input data
  `UnmarshallingException` - if there is a problem unmarshalling the parsed DOM

### unmarshallFromReader

@Nonnull public static XMLObject unmarshallFromReader(@Nonnull ParserPool parserPool, @Nonnull Reader reader) throws XMLParserException, UnmarshallingException
Unmarshall a Document from a Reader.

Parameters:
  `parserPool` - the ParserPool instance to use
  `reader` - the Reader to unmarshall
Returns:
  the unmarshalled XMLObject
Throws:
  `XMLParserException` - if there is a problem parsing the input data
  `UnmarshallingException` - if there is a problem unmarshalling the parsed DOM

### marshall

@Nonnull public static Element marshall(@Nonnull XMLObject xmlObject) throws MarshallingException
Marshall an XMLObject. If the XMLObject already has a cached DOM via `XMLObject.getDOM()`, that Element will be returned. Otherwise the object will be fully marshalled and that Element returned.

Parameters:
  `xmlObject` - the XMLObject to marshall
Returns:
  the marshalled Element
Throws:
  `MarshallingException` - if there is a problem marshalling the XMLObject

### marshallToOutputStream

public static void marshallToOutputStream(@Nonnull XMLObject xmlObject, @Nonnull OutputStream outputStream) throws MarshallingException
Marshall an XMLObject to an OutputStream.

Parameters:
  `xmlObject` - the XMLObject to marshall
  `outputStream` - the OutputStream to which to marshall
Throws:
  `MarshallingException` - if there is a problem marshalling the object

### lookupNamespaceURI

@Nullable public static String lookupNamespaceURI(XMLObject xmlObject, String prefix)
Get the namespace URI bound to the specified prefix within the scope of the specified XMLObject.

Parameters:
  `xmlObject` - the XMLObject from which to search
  `prefix` - the prefix to search
Returns:
  the namespace URI bound to the prefix, or none if not found

### lookupNamespacePrefix

@Nullable public static String lookupNamespacePrefix(XMLObject xmlObject, String namespaceURI)
Get the prefix bound to the specified namespace URI within the scope of the specified XMLObject.

Parameters:
  `xmlObject` - the XMLObject from which to search
  `namespaceURI` - the namespace URI to search
Returns:
  the prefix bound to the namespace URI, or none if not found

### marshallAttribute

public static void marshallAttribute(@Nonnull QName attributeName, @Nonnull List<String> attributeValues, @Nonnull Element domElement, boolean isIDAttribute)
Marshall an attribute name and value to a DOM Element. This is particularly useful for attributes whose names appear in namespace-qualified form.

Parameters:
  `attributeName` - the attribute name in QName form
  `attributeValues` - the attribute values
  `domElement` - the target element to which to marshall
  `isIDAttribute` - flag indicating whether the attribute being marshalled should be handled as an ID-typed attribute

### marshallAttribute

public static void marshallAttribute(@Nonnull QName attributeName, @Nullable String attributeValue, @Nonnull Element domElement, boolean isIDAttribute)
Marshall an attribute name and value to a DOM Element. This is particularly useful for attributes whose names appear in namespace-qualified form.

Parameters:
  `attributeName` - the attribute name in QName form
  `attributeValue` - the attribute value
  `domElement` - the target element to which to marshall
  `isIDAttribute` - flag indicating whether the attribute being marshalled should be handled as an ID-typed attribute

### marshallAttributeMap

public static void marshallAttributeMap(@Nonnull AttributeMap attributeMap, @Nonnull Element domElement)
Marshall the attributes represented by the indicated AttributeMap into the indicated DOM Element.

Parameters:
  `attributeMap` - the AttributeMap
  `domElement` - the target Element

### marshallAttributeMapIDness

public static void marshallAttributeMapIDness(@Nonnull AttributeMap attributeMap, @Nonnull Element domElement)
Marshall the ID-ness of attributes represented by the indicated AttributeMap into the indicated DOM Element.

Parameters:
  `attributeMap` - the AttributeMap
  `domElement` - the target Element

### marshallAttributeIDness

public static void marshallAttributeIDness(QName attributeName, Element domElement, boolean isIDAttribute)
Marshall the ID-ness of an attribute into the indicated DOM Element.

Parameters:
  `attributeName` - the attribute QName
  `domElement` - the target Element
  `isIDAttribute` - true if attribute is an ID attribute, false if not

### marshallAttributeIDness

public static void marshallAttributeIDness(String namespaceURI, String localPart, Element domElement, boolean isIDAttribute)
Marshall the ID-ness of an attribute into the indicated DOM Element.

Parameters:
  `namespaceURI` - the attribute name's namespace URI
  `localPart` - the attribute name's local part
  `domElement` - the target Element
  `isIDAttribute` - true if attribute is an ID attribute, false if not

### unmarshallToAttributeMap

public static void unmarshallToAttributeMap(@Nonnull AttributeMap attributeMap, @Nonnull Attr attribute)
Unmarshall a DOM Attr to an AttributeMap.

Parameters:
  `attributeMap` - the target AttributeMap
  `attribute` - the target DOM Attr

### buildXMLObject

@Nonnull public static XMLObject buildXMLObject(@Nonnull QName elementName)
Build an XMLObject based on the element name.

Parameters:
  `elementName` - the element name
Returns:
  an XMLObject
Throws:
  `XMLRuntimeException` - if the required builder can not be obtained

### buildXMLObject

@Nonnull public static XMLObject buildXMLObject(@Nonnull QName elementName, @Nullable QName typeName)
Build an XMLObject based on the element nane and xsi:type.

Parameters:
  `elementName` - the element name
  `typeName` - the xsi:type
Returns:
  an XMLObject
Throws:
  `XMLRuntimeException` - if the required builder can not be obtained

### getBuilder

@Nullable public static XMLObjectBuilder<?> getBuilder(@Nonnull QName typeOrName)
Obtain an XMLObject builder for the given QName.

Parameters:
  `typeOrName` - the element name or type
Returns:
  an XMLObject builder, or null if no provider registered

### getMarshaller

@Nullable public static Marshaller getMarshaller(@Nonnull QName typeOrName)
Obtain an XMLObject marshaller for the given QName.

Parameters:
  `typeOrName` - the element name or type
Returns:
  an XMLObject marshaller, or null if no provider registered

### getMarshaller

@Nullable public static Marshaller getMarshaller(@Nonnull XMLObject xmlObject)
Obtain an XMLObject marshaller for the given XMLObject.

Parameters:
  `xmlObject` - the XMLObject to be marshalled
Returns:
  an XMLObject marshaller, or null if no provider registered

### getUnmarshaller

@Nullable public static Unmarshaller getUnmarshaller(@Nonnull QName typeOrName)
Obtain an XMLObject unmarshaller for the given QName.

Parameters:
  `typeOrName` - the element name or type
Returns:
  an XMLObject unmarshaller, or null if no provider registered

### getUnmarshaller

@Nullable public static Unmarshaller getUnmarshaller(@Nonnull Element element)
Obtain an XMLObject unmarshaller for the given DOM Element.

Parameters:
  `element` - the DOM element
Returns:
  an XMLObject unmarshaller, or null if no provider registered

### getProviderRegistry

@Nonnull private static XMLObjectProviderRegistry getProviderRegistry()
Obtain the XMLObject provider registry.

Returns:
  the configured XMLObject provider registry
Throws:
  `XMLRuntimeException` - if the registry is not available