Class SAXMarshaller
- java.lang.Object
-
- com.sun.identity.saml2.jaxb.assertion.impl.runtime.SAXMarshaller
-
- All Implemented Interfaces:
XMLSerializer
public class SAXMarshaller extends Object implements XMLSerializer
XMLSerializer that produces SAX2 events. To marshal an object, create an instance of SAXMarshaller and call the serializeElements method of the XMLSerializable object that you want to marshal.- Author:
- Kohsuke Kawaguchi
-
-
Constructor Summary
Constructors Constructor Description SAXMarshaller(ContentHandler _writer, com.sun.xml.bind.marshaller.NamespacePrefixMapper prefixMapper, MarshallerImpl _owner)Creates a marshalling context by designating the ContentHandler that receives generated SAX2 events.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchildAsAttributes(com.sun.xml.bind.JAXBObject o, String fieldName)This method is called when an JAXBObject object is found while the marshaller is in the "attribute" mode (i.e. marshalling attributes of an element)voidchildAsBody(com.sun.xml.bind.JAXBObject o, String fieldName)This method is called when an JAXBObject object is found while the marshaller is in the "element" mode (i.e. marshalling a content model of an element)voidchildAsURIs(com.sun.xml.bind.JAXBObject o, String fieldName)This method is called when an JAXBObject object is found while the marshaller is in the "URI" mode.voidendAttribute()voidendAttributes()Switches to the "marshal child texts/elements" mode.voidendElement()Ends marshalling of an element.voidendNamespaceDecls()Switches to the mode to marshal attribute values.NamespaceContext2getNamespaceContext()Obtains a namespace context object, which is used to declare/obtain namespace bindings.StringonID(com.sun.xml.bind.marshaller.IdentifiableObject owner, String value)Notifies the serializer that an ID value has just marshalled.StringonIDREF(com.sun.xml.bind.marshaller.IdentifiableObject obj)Notifies the serializer that an IDREF value has just marshalled.voidreportError(ValidationEvent ve)Errors detected by the XMLSerializable should be either thrown asSAXExceptionor reported through this method.voidreportMissingObjectError(String fieldName)voidstartAttribute(String uri, String local)Starts marshalling of an attribute.voidstartElement(String uri, String local)Starts marshalling of an element.voidtext(String text, String fieldName)Marshalls text.
-
-
-
Constructor Detail
-
SAXMarshaller
public SAXMarshaller(ContentHandler _writer, com.sun.xml.bind.marshaller.NamespacePrefixMapper prefixMapper, MarshallerImpl _owner)
Creates a marshalling context by designating the ContentHandler that receives generated SAX2 events.
-
-
Method Detail
-
getNamespaceContext
public NamespaceContext2 getNamespaceContext()
Description copied from interface:XMLSerializerObtains a namespace context object, which is used to declare/obtain namespace bindings.- Specified by:
getNamespaceContextin interfaceXMLSerializer
-
startElement
public void startElement(String uri, String local) throws SAXException
Starts marshalling of an element. Calling this method will push the internal state into the internal stack.- Specified by:
startElementin interfaceXMLSerializer- Throws:
SAXException
-
endNamespaceDecls
public void endNamespaceDecls() throws SAXExceptionDescription copied from interface:XMLSerializerSwitches to the mode to marshal attribute values. This method has to be called after the 1st pass is completed.- Specified by:
endNamespaceDeclsin interfaceXMLSerializer- Throws:
SAXException
-
endAttributes
public void endAttributes() throws SAXExceptionSwitches to the "marshal child texts/elements" mode. This method has to be called after the 1st pass is completed.- Specified by:
endAttributesin interfaceXMLSerializer- Throws:
SAXException
-
endElement
public void endElement() throws SAXExceptionEnds marshalling of an element. Pops the internal stack.- Specified by:
endElementin interfaceXMLSerializer- Throws:
SAXException
-
text
public void text(String text, String fieldName) throws SAXException
Marshalls text.This method can be called (i) after the startAttribute method and (ii) before the endAttribute method, to marshal attribute values. If the method is called more than once, those texts are considered as separated by whitespaces. For example,
c.startAttribute(); c.text("abc"); c.text("def"); c.endAttribute("","foo");will generate foo="abc def".Similarly, this method can be called after the endAttributes method to marshal texts inside elements. The same rule about multiple invokations apply to this case, too. For example,
c.startElement("","foo"); c.endAttributes(); c.text("abc"); c.text("def"); c.startElement("","bar"); c.endAttributes(); c.endElement(); c.text("ghi"); c.endElement();will generate<foo>abc def<bar/>ghi</foo>.- Specified by:
textin interfaceXMLSerializer- Throws:
SAXException
-
startAttribute
public void startAttribute(String uri, String local)
Starts marshalling of an attribute. The marshalling of an attribute will be done by- call the startAttribute method
- call the text method (several times if necessary)
- call the endAttribute method
- Specified by:
startAttributein interfaceXMLSerializer
-
endAttribute
public void endAttribute()
- Specified by:
endAttributein interfaceXMLSerializer
-
onID
public String onID(com.sun.xml.bind.marshaller.IdentifiableObject owner, String value) throws SAXException
Description copied from interface:XMLSerializerNotifies the serializer that an ID value has just marshalled. The serializer may or may not check the consistency of ID/IDREFs and may throw a SAXException.- Specified by:
onIDin interfaceXMLSerializer- Parameters:
owner- JAXB content object that posesses the ID.value- The value of the ID.- Returns:
- Return the value parameter without any modification, so that the invocation of this method can be done transparently by a transducer.
- Throws:
SAXException
-
onIDREF
public String onIDREF(com.sun.xml.bind.marshaller.IdentifiableObject obj) throws SAXException
Description copied from interface:XMLSerializerNotifies the serializer that an IDREF value has just marshalled. The serializer may or may not check the consistency of ID/IDREFs and may throw a SAXException.- Specified by:
onIDREFin interfaceXMLSerializer- Returns:
- Return the value parameter without any modification. so that the invocation of this method can be done transparently by a transducer.
- Throws:
SAXException
-
childAsBody
public void childAsBody(com.sun.xml.bind.JAXBObject o, String fieldName) throws SAXExceptionDescription copied from interface:XMLSerializerThis method is called when an JAXBObject object is found while the marshaller is in the "element" mode (i.e. marshalling a content model of an element)- Specified by:
childAsBodyin interfaceXMLSerializerfieldName- property name of the parent objeect from which 'o' comes. Used as a part of the error message in case anything goes wrong with 'o'.- Throws:
SAXException
-
childAsAttributes
public void childAsAttributes(com.sun.xml.bind.JAXBObject o, String fieldName) throws SAXExceptionDescription copied from interface:XMLSerializerThis method is called when an JAXBObject object is found while the marshaller is in the "attribute" mode (i.e. marshalling attributes of an element)- Specified by:
childAsAttributesin interfaceXMLSerializerfieldName- property name of the parent objeect from which 'o' comes. Used as a part of the error message in case anything goes wrong with 'o'.- Throws:
SAXException
-
childAsURIs
public void childAsURIs(com.sun.xml.bind.JAXBObject o, String fieldName) throws SAXExceptionDescription copied from interface:XMLSerializerThis method is called when an JAXBObject object is found while the marshaller is in the "URI" mode.- Specified by:
childAsURIsin interfaceXMLSerializerfieldName- property name of the parent objeect from which 'o' comes. Used as a part of the error message in case anything goes wrong with 'o'.- Throws:
SAXException
-
reportError
public void reportError(ValidationEvent ve) throws com.sun.xml.bind.serializer.AbortSerializationException
Description copied from interface:XMLSerializerErrors detected by the XMLSerializable should be either thrown asSAXExceptionor reported through this method. The callee should report an error to the client application and- Specified by:
reportErrorin interfaceXMLSerializer- Throws:
com.sun.xml.bind.serializer.AbortSerializationException
-
reportMissingObjectError
public void reportMissingObjectError(String fieldName) throws SAXException
- Throws:
SAXException
-
-