Package org.opensaml.core.xml.io

# Class AbstractXMLObjectMarshaller

java.lang.Object
org.opensaml.core.xml.io.AbstractXMLObjectMarshaller

All Implemented Interfaces:
  `Marshaller`

Direct Known Subclasses:
  `AbstractElementExtensibleXMLObjectMarshaller`, `AbstractSAMLObjectMarshaller`, `AbstractWSAddressingObjectMarshaller`, `AbstractWSPolicyObjectMarshaller`, `AbstractWSSecurityObjectMarshaller`, `AbstractWSTrustObjectMarshaller`, `AbstractXACMLObjectMarshaller`, `AbstractXMLEncryptionMarshaller`, `AbstractXMLSignatureMarshaller`, `AddressMarshaller`, `AppliesToMarshaller`, `BodyMarshaller`, `DetailMarshaller`, `EndPointReferenceMarshaller`, `EnvelopeMarshaller`, `FaultMarshaller`, `HeaderMarshaller`, `RequestedSecurityTokenMarshaller`, `RequestSecurityTokenResponseMarshaller`, `SimpleXMLObjectMarshaller`, `X509SerialNumberMarshaller`, `XSAnyMarshaller`, `XSBase64BinaryMarshaller`, `XSBooleanMarshaller`, `XSDateTimeMarshaller`, `XSIntegerMarshaller`, `XSQNameMarshaller`, `XSStringMarshaller`, `XSURIMarshaller`

public abstract class AbstractXMLObjectMarshaller extends Object implements Marshaller
A thread safe, abstract implementation of the `Marshaller` interface. This class handles most of the boilerplate code:

- Ensuring elements to be marshalled are of either the correct xsi:type or element QName
- Setting the appropriate namespace and prefix for the marshalled element
- Setting the xsi:type for the element if the element has an explicit type
- Setting namespaces attributes declared for the element
- Marshalling of child elements

## Field Summary

Fields
Modifier and Type
Field
Description
`private final org.slf4j.Logger`
`log`
Class logger.
`private final MarshallerFactory`
`marshallerFactory`
Factory for XMLObject Marshallers.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`AbstractXMLObjectMarshaller()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`Element`
`marshall(XMLObject xmlObject)`
Marshall this element, and its children, and root them in a newly created Document.
`Element`
`marshall(XMLObject xmlObject, Document document)`
Marshall this element, and its children, into a W3C DOM element.
`Element`
`marshall(XMLObject xmlObject, Element parentElement)`
Marshall the given XMLObject and append it as a child to the given parent element.
`protected void`
`marshallAttributeIDness(XMLObject xmlObject, Element domElement)`
Marshalls the IDness of the ID attribute present on the element, if any.
`protected void`
`marshallAttributes(XMLObject xmlObject, Element domElement)`
Marshalls a given XMLObject into a W3C Element.
`protected void`
`marshallChildElements(XMLObject xmlObject, Element domElement)`
Marshalls the child elements of the given XMLObject.
`protected void`
`marshallElementContent(XMLObject xmlObject, Element domElement)`
Marshalls data from the XMLObject into content of the DOM Element.
`protected Element`
`marshallInto(XMLObject xmlObject, Element targetElement)`
Marshalls the given XMLObject into the given DOM Element.
`protected void`
`marshallNamespacePrefix(XMLObject xmlObject, Element domElement)`
Marshalls the namespace prefix of the XMLObject into the DOM element.
`protected void`
`marshallNamespaces(XMLObject xmlObject, Element domElement)`
Creates the xmlns attributes for any namespaces set on the given XMLObject.
`protected void`
`marshallSchemaInstanceAttributes(XMLObject xmlObject, Element domElement)`
Creates the XSI type, schemaLocation, and noNamespaceSchemaLocation attributes for an XMLObject.
`protected void`
`marshallUnknownAttributes(AttributeExtensibleXMLObject xmlObject, Element domElement)`
Marshalls unknown attributes.
`private void`
`prepareForAdoption(XMLObject domCachingObject)`
Prepares the given DOM caching XMLObject for adoption into another document.
`protected void`
`setDocumentElement(Document document, Element element)`
Sets the given element as the Document Element of the given Document.

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

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

## Field Details

### log

@Nonnull private final org.slf4j.Logger log
Class logger.

### marshallerFactory

@Nonnull private final MarshallerFactory marshallerFactory
Factory for XMLObject Marshallers.

## Constructor Details

### AbstractXMLObjectMarshaller

protected AbstractXMLObjectMarshaller()
Constructor.

## Method Details

### marshall

@Nonnull public Element marshall(@Nonnull XMLObject xmlObject) throws MarshallingException
Marshall this element, and its children, and root them in a newly created Document. The Document is created by a `DocumentBuilder` obtained from a `DocumentBuilderFactory` created without any additional parameters or properties set; that is the system defaults properties are used.

Specified by:
  `marshall` in interface `Marshaller`
Parameters:
  `xmlObject` - the object to marshall
Returns:
  the W3C DOM element representing this SAML element
Throws:
  `MarshallingException` - thrown if there is a problem marshalling the given object

### marshall

@Nonnull public Element marshall(@Nonnull XMLObject xmlObject, @Nonnull Document document) throws MarshallingException
Marshall this element, and its children, into a W3C DOM element. If the document does not have a Document Element the Element resulting from this marshalling will be set as the Document Element.

Specified by:
  `marshall` in interface `Marshaller`
Parameters:
  `xmlObject` - the object to marshall
  `document` - the DOM document the marshalled element will be placed in
Returns:
  the W3C DOM element representing this XMLObject
Throws:
  `MarshallingException` - thrown if there is a problem marshalling the given object

### marshall

@Nonnull public Element marshall(@Nonnull XMLObject xmlObject, @Nonnull Element parentElement) throws MarshallingException
Marshall the given XMLObject and append it as a child to the given parent element. NOTE: The given Element must be within a DOM tree whose root is the root of the Document owning the given Element.

Specified by:
  `marshall` in interface `Marshaller`
Parameters:
  `xmlObject` - the XMLObject to be marshalled
  `parentElement` - the parent of the Element resulting from marshalling the given XMLObject
Returns:
  the marshalled XMLObject
Throws:
  `MarshallingException` - thrown if the given XMLObject can not be marshalled.

### setDocumentElement

protected void setDocumentElement(@Nonnull Document document, @Nonnull Element element)
Sets the given element as the Document Element of the given Document. If the document already has a Document Element it is replaced by the given element.

Parameters:
  `document` - the document
  `element` - the Element that will serve as the Document Element

### marshallInto

@Nonnull protected Element marshallInto(@Nonnull XMLObject xmlObject, @Nonnull Element targetElement) throws MarshallingException
Marshalls the given XMLObject into the given DOM Element. The DOM Element must be within a DOM tree whose root is the Document Element of the Document that owns the given DOM Element.

Parameters:
  `xmlObject` - the XMLObject to marshall
  `targetElement` - the Element into which the XMLObject is marshalled into
Returns:
  the DOM element the `XMLObject` is marshalled into
Throws:
  `MarshallingException` - thrown if there is a problem marshalling the object

### marshallNamespacePrefix

protected void marshallNamespacePrefix(@Nonnull XMLObject xmlObject, @Nonnull Element domElement)
Marshalls the namespace prefix of the XMLObject into the DOM element.

Parameters:
  `xmlObject` - the XMLObject being marshalled
  `domElement` - the DOM element the XMLObject is being marshalled into

### marshallChildElements

protected void marshallChildElements(@Nonnull XMLObject xmlObject, @Nonnull Element domElement) throws MarshallingException
Marshalls the child elements of the given XMLObject.

Parameters:
  `xmlObject` - the XMLObject whose children will be marshalled
  `domElement` - the DOM element that will recieved the marshalled children
Throws:
  `MarshallingException` - thrown if there is a problem marshalling a child element

### marshallNamespaces

protected void marshallNamespaces(@Nonnull XMLObject xmlObject, @Nonnull Element domElement)
Creates the xmlns attributes for any namespaces set on the given XMLObject.

Parameters:
  `xmlObject` - the XMLObject
  `domElement` - the DOM element the namespaces will be added to

### marshallSchemaInstanceAttributes

protected void marshallSchemaInstanceAttributes(@Nonnull XMLObject xmlObject, @Nonnull Element domElement) throws MarshallingException
Creates the XSI type, schemaLocation, and noNamespaceSchemaLocation attributes for an XMLObject.

Parameters:
  `xmlObject` - the XMLObject
  `domElement` - the DOM element the namespaces will be added to
Throws:
  `MarshallingException` - thrown if the schema type information is invalid

### marshallAttributes

protected void marshallAttributes(@Nonnull XMLObject xmlObject, @Nonnull Element domElement) throws MarshallingException
Marshalls a given XMLObject into a W3C Element. The given signing context should be blindly passed to the marshaller for child elements. The XMLObject passed to this method is guaranteed to be of the target name specified during this unmarshaller's construction. This default implementation of this method is a no-op

Parameters:
  `xmlObject` - the XMLObject to marshall
  `domElement` - the W3C DOM element
Throws:
  `MarshallingException` - thrown if there is a problem marshalling the element

### marshallAttributeIDness

protected void marshallAttributeIDness(@Nonnull XMLObject xmlObject, @Nonnull Element domElement) throws MarshallingException
Marshalls the IDness of the ID attribute present on the element, if any. The default implementation here handles the wildcard attributes in the `AttributeMap` if the XMLObject is an instance of `AttributeExtensibleXMLObject`, via `XMLObjectSupport.marshallAttributeMapIDness(AttributeMap, Element)`.

Parameters:
  `xmlObject` - the XMLObject to marshall
  `domElement` - the W3C DOM element
Throws:
  `MarshallingException` - thrown if there is a problem marshalling the element

### marshallElementContent

protected void marshallElementContent(@Nonnull XMLObject xmlObject, @Nonnull Element domElement) throws MarshallingException
Marshalls data from the XMLObject into content of the DOM Element. The default implementation of this method is a no-op.

Parameters:
  `xmlObject` - the XMLObject
  `domElement` - the DOM element recieving the content
Throws:
  `MarshallingException` - thrown if the textual content can not be added to the DOM element

### prepareForAdoption

private void prepareForAdoption(@Nonnull XMLObject domCachingObject) throws MarshallingException
Prepares the given DOM caching XMLObject for adoption into another document. If the XMLObject has a parent then all visible namespaces used by the given XMLObject and its descendants are declared within that subtree and the parent's DOM is invalidated.

Parameters:
  `domCachingObject` - the XMLObject to prepare for adoption
Throws:
  `MarshallingException` - thrown if a namespace within the XMLObject's DOM subtree can not be resolved.

### marshallUnknownAttributes

protected void marshallUnknownAttributes(@Nonnull AttributeExtensibleXMLObject xmlObject, @Nonnull Element domElement)
Marshalls unknown attributes.

Parameters:
  `xmlObject` - the Object which has the unknown attributes/
  `domElement` - where to marshall them to.