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
,X509SerialNumberMarshaller
,XSAnyMarshaller
,XSBase64BinaryMarshaller
,XSBooleanMarshaller
,XSDateTimeMarshaller
,XSIntegerMarshaller
,XSQNameMarshaller
,XSStringMarshaller
,XSURIMarshaller
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
FieldsModifier and TypeFieldDescriptionprivate final org.slf4j.Logger
Class logger.private final MarshallerFactory
Factory for XMLObject Marshallers. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionMarshall this element, and its children, and root them in a newly created Document.Marshall this element, and its children, into a W3C DOM element.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.
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
marshallerFactory
Factory for XMLObject Marshallers.
-
-
Constructor Details
-
AbstractXMLObjectMarshaller
protected AbstractXMLObjectMarshaller()Constructor.
-
-
Method Details
-
marshall
Marshall this element, and its children, and root them in a newly created Document. The Document is created by aDocumentBuilder
obtained from aDocumentBuilderFactory
created without any additional parameters or properties set; that is the system defaults properties are used.- Specified by:
marshall
in interfaceMarshaller
- 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 interfaceMarshaller
- Parameters:
xmlObject
- the object to marshalldocument
- 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 interfaceMarshaller
- Parameters:
xmlObject
- the XMLObject to be marshalledparentElement
- 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
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 documentelement
- 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 marshalltargetElement
- 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
Marshalls the namespace prefix of the XMLObject into the DOM element.- Parameters:
xmlObject
- the XMLObject being marshalleddomElement
- 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 marshalleddomElement
- the DOM element that will recieved the marshalled children- Throws:
MarshallingException
- thrown if there is a problem marshalling a child element
-
marshallNamespaces
Creates the xmlns attributes for any namespaces set on the given XMLObject.- Parameters:
xmlObject
- the XMLObjectdomElement
- 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 XMLObjectdomElement
- 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 marshalldomElement
- 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 theAttributeMap
if the XMLObject is an instance ofAttributeExtensibleXMLObject
, viaXMLObjectSupport.marshallAttributeMapIDness(AttributeMap, Element)
.- Parameters:
xmlObject
- the XMLObject to marshalldomElement
- 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 XMLObjectdomElement
- the DOM element recieving the content- Throws:
MarshallingException
- thrown if the textual content can not be added to the DOM element
-
prepareForAdoption
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.
-