Interface XMLSerializer
-
- All Known Implementing Classes:
MSVValidator,SAXMarshaller
public interface XMLSerializerReceives XML serialization eventThis object coordinates the overall marshalling efforts across different content-tree objects and different target formats.
The following CFG gives the proper sequence of method invocation.
MARSHALLING := ELEMENT ELEMENT := "startElement" NSDECL* "endNamespaceDecls" ATTRIBUTE* "endAttributes" BODY "endElement" NSDECL := "declareNamespace" ATTRIBUTE := "startAttribute" ATTVALUES "endAttribute" ATTVALUES := "text"* BODY := ( "text" | ELEMENT )*A marshalling of one element consists of two stages. The first stage is for marshalling attributes and collecting namespace declarations. The second stage is for marshalling characters/child elements of that element.
Observe that multiple invocation of "text" is allowed.
Also observe that the namespace declarations are allowed only between "startElement" and "endAttributes".
- Author:
- Kohsuke Kawaguchi
-
-
Method Summary
All Methods Instance Methods Abstract 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 mode to marshal child texts/elements.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 e)Errors detected by the XMLSerializable should be either thrown asSAXExceptionor reported through this method.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.
-
-
-
Method Detail
-
reportError
void reportError(ValidationEvent e) throws com.sun.xml.bind.serializer.AbortSerializationException
Errors detected by the XMLSerializable should be either thrown asSAXExceptionor reported through this method. The callee should report an error to the client application and- Throws:
com.sun.xml.bind.serializer.AbortSerializationException
-
startElement
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.- Throws:
SAXException
-
endNamespaceDecls
void endNamespaceDecls() throws SAXExceptionSwitches to the mode to marshal attribute values. This method has to be called after the 1st pass is completed.- Throws:
SAXException
-
endAttributes
void endAttributes() throws SAXExceptionSwitches to the mode to marshal child texts/elements. This method has to be called after the 2nd pass is completed.- Throws:
SAXException
-
endElement
void endElement() throws SAXExceptionEnds marshalling of an element. Pops the internal stack.- Throws:
SAXException
-
text
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.endNamespaceDecls(); 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>.- Throws:
SAXException
-
startAttribute
void startAttribute(String uri, String local) throws SAXException
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
- Throws:
SAXException
-
endAttribute
void endAttribute() throws SAXException- Throws:
SAXException
-
getNamespaceContext
NamespaceContext2 getNamespaceContext()
Obtains a namespace context object, which is used to declare/obtain namespace bindings.
-
onID
String onID(com.sun.xml.bind.marshaller.IdentifiableObject owner, String value) throws SAXException
Notifies 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.- 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
String onIDREF(com.sun.xml.bind.marshaller.IdentifiableObject obj) throws SAXException
Notifies 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.- 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
void childAsBody(com.sun.xml.bind.JAXBObject o, String fieldName) throws SAXExceptionThis 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)- Parameters:
fieldName- 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
void childAsAttributes(com.sun.xml.bind.JAXBObject o, String fieldName) throws SAXExceptionThis method is called when an JAXBObject object is found while the marshaller is in the "attribute" mode (i.e. marshalling attributes of an element)- Parameters:
fieldName- 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
void childAsURIs(com.sun.xml.bind.JAXBObject o, String fieldName) throws SAXExceptionThis method is called when an JAXBObject object is found while the marshaller is in the "URI" mode.- Parameters:
fieldName- 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
-
-