org.opensaml.xml.io
Class AbstractXMLObjectMarshaller

java.lang.Object
  extended by org.opensaml.xml.io.AbstractXMLObjectMarshaller
All Implemented Interfaces:
Marshaller
Direct Known Subclasses:
AbstractElementExtensibleXMLObjectMarshaller, AbstractXMLEncryptionMarshaller, AbstractXMLSignatureMarshaller, BaseXMLObjectMarshaller, X509SerialNumberMarshaller, XSAnyMarshaller, XSBase64BinaryMarshaller, XSBooleanMarshaller, 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:


Field Summary
private  Logger log
          Class logger.
private  MarshallerFactory marshallerFactory
          Factory for XMLObject Marshallers.
private  QName targetQName
          The target name and namespace for this marshaller.
 
Constructor Summary
protected AbstractXMLObjectMarshaller()
          Constructor.
protected AbstractXMLObjectMarshaller(String targetNamespaceURI, String targetLocalName)
          Deprecated. no replacement
 
Method Summary
protected  void checkXMLObjectIsTarget(XMLObject xmlObject)
          Checks to make sure the given XMLObject's schema type or element QName matches the target parameters given at marshaller construction time.
 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 abstract  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 abstract  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.
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 Detail

log

private final Logger log
Class logger.


targetQName

private QName targetQName
The target name and namespace for this marshaller.


marshallerFactory

private MarshallerFactory marshallerFactory
Factory for XMLObject Marshallers.

Constructor Detail

AbstractXMLObjectMarshaller

protected AbstractXMLObjectMarshaller()
Constructor.


AbstractXMLObjectMarshaller

protected AbstractXMLObjectMarshaller(String targetNamespaceURI,
                                      String targetLocalName)
Deprecated. no replacement

This constructor supports checking an XMLObject to be marshalled, either element name or schema type, against a given namespace/local name pair.

Parameters:
targetNamespaceURI - the namespace URI of either the schema type QName or element QName of the elements this unmarshaller operates on
targetLocalName - the local name of either the schema type QName or element QName of the elements this unmarshaller operates on
Method Detail

marshall

public Element marshall(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

public Element marshall(XMLObject xmlObject,
                        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

public Element marshall(XMLObject xmlObject,
                        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(Document document,
                                  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

protected Element marshallInto(XMLObject xmlObject,
                               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

checkXMLObjectIsTarget

protected void checkXMLObjectIsTarget(XMLObject xmlObject)
                               throws MarshallingException
Checks to make sure the given XMLObject's schema type or element QName matches the target parameters given at marshaller construction time.

Parameters:
xmlObject - the XMLObject to marshall
Throws:
MarshallingException - thrown if the given object is not or the required type

marshallNamespacePrefix

protected void marshallNamespacePrefix(XMLObject xmlObject,
                                       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(XMLObject xmlObject,
                                     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(XMLObject xmlObject,
                                  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(XMLObject xmlObject,
                                                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 abstract void marshallAttributes(XMLObject xmlObject,
                                           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.

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

marshallElementContent

protected abstract void marshallElementContent(XMLObject xmlObject,
                                               Element domElement)
                                        throws MarshallingException
Marshalls data from the XMLObject into content of the DOM Element.

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(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.


Copyright © 1999-2013. All Rights Reserved.