edu.ksi.virtualclassroom.mappers.jaxb.xmlwrapper.impl.runtime
Class SAXMarshaller

java.lang.Object
  extended byedu.ksi.virtualclassroom.mappers.jaxb.xmlwrapper.impl.runtime.SAXMarshaller
All Implemented Interfaces:
XMLSerializer

public class SAXMarshaller
extends java.lang.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 * @version $Revision$


Field Summary
private  java.lang.String attLocalName
          Field attLocalName
private  java.lang.String attNamespaceUri
          Field attNamespaceUri
private  org.xml.sax.helpers.AttributesImpl attributes
          "Attributes" object that is passed to the startElement event.
private  com.sun.xml.bind.JAXBObject currentTarget
          Object currently marshalling itself.
private static com.sun.xml.bind.marshaller.NamespacePrefixMapper defaultNamespacePrefixMapper
          Default NamespacePrefixMapper implementation used when it is not specified by the user.
private  int elementLen
          Field elementLen
private  java.lang.String[] elementStack
          Element name stack implemented as an array of (uri,local) pairs.
private  PrefixCallback endPrefixCallback
          Field endPrefixCallback
private  java.util.Set idReferencedObjects
          Objects referenced through IDREF.
private  NamespaceContextImpl nsContext
          namespace context.
private  java.util.Set objectsWithId
          Objects with ID.
private  MarshallerImpl owner
          Marshaller object to which this object belongs.
private  PrefixCallback startPrefixCallback
          Field startPrefixCallback
private  java.lang.StringBuffer textBuf
          Buffer for collecting characters.
private  org.xml.sax.ContentHandler writer
          This object receives SAX2 events generated from the marshaller.
 
Constructor Summary
SAXMarshaller(org.xml.sax.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
private static void _assert(boolean b)
          Method _assert
 void childAsAttributes(com.sun.xml.bind.JAXBObject o, java.lang.String fieldName)
          Method childAsAttributes
 void childAsBody(com.sun.xml.bind.JAXBObject o, java.lang.String fieldName)
          Method childAsBody
 void childAsURIs(com.sun.xml.bind.JAXBObject o, java.lang.String fieldName)
          Method childAsURIs
 void endAttribute()
          Method endAttribute
 void endAttributes()
          Switches to the "marshal child texts/elements" mode.
 void endElement()
          Ends marshalling of an element.
 void endNamespaceDecls()
          Method endNamespaceDecls
private  java.lang.String getCurrentElementLocal()
          Method getCurrentElementLocal
private  java.lang.String getCurrentElementUri()
          Method getCurrentElementUri
 NamespaceContext2 getNamespaceContext()
          Obtains a namespace context object, which is used to declare/obtain namespace bindings.
 java.lang.String onID(com.sun.xml.bind.marshaller.IdentifiableObject owner, java.lang.String value)
          Method onID
 java.lang.String onIDREF(com.sun.xml.bind.marshaller.IdentifiableObject obj)
          Method onIDREF
private  void popElement()
          Method popElement
private  void pushElement(java.lang.String uri, java.lang.String local)
          Method pushElement
(package private)  void reconcileID()
          Method reconcileID
 void reportError(javax.xml.bind.ValidationEvent ve)
          Method reportError
 void reportMissingObjectError(java.lang.String fieldName)
          Method reportMissingObjectError
 void startAttribute(java.lang.String uri, java.lang.String local)
          Starts marshalling of an attribute.
 void startElement(java.lang.String uri, java.lang.String local)
          Starts marshalling of an element.
 void text(java.lang.String text, java.lang.String fieldName)
          Marshalls text.
private  void writePendingText()
          Writes pending text (characters inside elements) to the writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributes

private final org.xml.sax.helpers.AttributesImpl attributes
"Attributes" object that is passed to the startElement event. One object is reused throughout the marshalling.


writer

private final org.xml.sax.ContentHandler writer
This object receives SAX2 events generated from the marshaller.


owner

private final MarshallerImpl owner
Marshaller object to which this object belongs.


idReferencedObjects

private final java.util.Set idReferencedObjects
Objects referenced through IDREF.


objectsWithId

private final java.util.Set objectsWithId
Objects with ID.


currentTarget

private com.sun.xml.bind.JAXBObject currentTarget
Object currently marshalling itself.


nsContext

private final NamespaceContextImpl nsContext
namespace context.


elementStack

private java.lang.String[] elementStack
Element name stack implemented as an array of (uri,local) pairs.


elementLen

private int elementLen
Field elementLen


startPrefixCallback

private final PrefixCallback startPrefixCallback
Field startPrefixCallback


endPrefixCallback

private final PrefixCallback endPrefixCallback
Field endPrefixCallback


textBuf

private final java.lang.StringBuffer textBuf
Buffer for collecting characters.


attNamespaceUri

private java.lang.String attNamespaceUri
Field attNamespaceUri


attLocalName

private java.lang.String attLocalName
Field attLocalName


defaultNamespacePrefixMapper

private static com.sun.xml.bind.marshaller.NamespacePrefixMapper defaultNamespacePrefixMapper
Default NamespacePrefixMapper implementation used when it is not specified by the user.

Constructor Detail

SAXMarshaller

public SAXMarshaller(org.xml.sax.ContentHandler _writer,
                     com.sun.xml.bind.marshaller.NamespacePrefixMapper prefixMapper,
                     MarshallerImpl _owner)
Creates a marshalling context by designating the ContentHandler that receives generated SAX2 events.

Parameters:
_writer - ContentHandler
prefixMapper - NamespacePrefixMapper
_owner - MarshallerImpl
Method Detail

getNamespaceContext

public NamespaceContext2 getNamespaceContext()
Description copied from interface: XMLSerializer
Obtains a namespace context object, which is used to declare/obtain namespace bindings.

Specified by:
getNamespaceContext in interface XMLSerializer
Returns:
NamespaceContext2

pushElement

private void pushElement(java.lang.String uri,
                         java.lang.String local)
Method pushElement

Parameters:
uri - String
local - String

popElement

private void popElement()
Method popElement


getCurrentElementUri

private java.lang.String getCurrentElementUri()
Method getCurrentElementUri

Returns:
String

getCurrentElementLocal

private java.lang.String getCurrentElementLocal()
Method getCurrentElementLocal

Returns:
String

startElement

public void startElement(java.lang.String uri,
                         java.lang.String local)
                  throws org.xml.sax.SAXException
Starts marshalling of an element. Calling this method will push the internal state into the internal stack.

Specified by:
startElement in interface XMLSerializer
Parameters:
uri - String
local - String
Throws:
org.xml.sax.SAXException
See Also:
XMLSerializer.startElement(String, String)

endNamespaceDecls

public void endNamespaceDecls()
                       throws org.xml.sax.SAXException
Method endNamespaceDecls

Specified by:
endNamespaceDecls in interface XMLSerializer
Throws:
org.xml.sax.SAXException
See Also:
XMLSerializer.endNamespaceDecls()

endAttributes

public void endAttributes()
                   throws org.xml.sax.SAXException
Switches to the "marshal child texts/elements" mode. This method has to be called after the 1st pass is completed.

Specified by:
endAttributes in interface XMLSerializer
Throws:
org.xml.sax.SAXException
See Also:
XMLSerializer.endAttributes()

endElement

public void endElement()
                throws org.xml.sax.SAXException
Ends marshalling of an element. Pops the internal stack.

Specified by:
endElement in interface XMLSerializer
Throws:
org.xml.sax.SAXException
See Also:
XMLSerializer.endElement()

text

public void text(java.lang.String text,
                 java.lang.String fieldName)
          throws org.xml.sax.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:
text in interface XMLSerializer
Parameters:
text - String
fieldName - String
Throws:
org.xml.sax.SAXException
See Also:
XMLSerializer.text(String, String)

writePendingText

private void writePendingText()
                       throws org.xml.sax.SAXException
Writes pending text (characters inside elements) to the writer. This method is called from startElement and endElement.

Throws:
org.xml.sax.SAXException

startAttribute

public void startAttribute(java.lang.String uri,
                           java.lang.String local)
Starts marshalling of an attribute. The marshalling of an attribute will be done by
  1. call the startAttribute method
  2. call the text method (several times if necessary)
  3. call the endAttribute method
No two attributes can be marshalled at the same time. Note that the whole attribute marshalling must be happened after the startElement method and before the endAttributes method.

Specified by:
startAttribute in interface XMLSerializer
Parameters:
uri - String
local - String
See Also:
XMLSerializer.startAttribute(String, String)

endAttribute

public void endAttribute()
Method endAttribute

Specified by:
endAttribute in interface XMLSerializer
See Also:
XMLSerializer.endAttribute()

onID

public java.lang.String onID(com.sun.xml.bind.marshaller.IdentifiableObject owner,
                             java.lang.String value)
                      throws org.xml.sax.SAXException
Method onID

Specified by:
onID in interface XMLSerializer
Parameters:
owner - IdentifiableObject
value - String
Returns:
String
Throws:
org.xml.sax.SAXException
See Also:
XMLSerializer.onID(IdentifiableObject, String)

onIDREF

public java.lang.String onIDREF(com.sun.xml.bind.marshaller.IdentifiableObject obj)
                         throws org.xml.sax.SAXException
Method onIDREF

Specified by:
onIDREF in interface XMLSerializer
Parameters:
obj - IdentifiableObject
Returns:
String
Throws:
org.xml.sax.SAXException
See Also:
XMLSerializer.onIDREF(IdentifiableObject)

reconcileID

void reconcileID()
           throws com.sun.xml.bind.serializer.AbortSerializationException
Method reconcileID

Throws:
com.sun.xml.bind.serializer.AbortSerializationException

childAsBody

public void childAsBody(com.sun.xml.bind.JAXBObject o,
                        java.lang.String fieldName)
                 throws org.xml.sax.SAXException
Method childAsBody

Specified by:
childAsBody in interface XMLSerializer
Parameters:
o - JAXBObject
fieldName - String
Throws:
org.xml.sax.SAXException
See Also:
XMLSerializer.childAsBody(JAXBObject, String)

childAsAttributes

public void childAsAttributes(com.sun.xml.bind.JAXBObject o,
                              java.lang.String fieldName)
                       throws org.xml.sax.SAXException
Method childAsAttributes

Specified by:
childAsAttributes in interface XMLSerializer
Parameters:
o - JAXBObject
fieldName - String
Throws:
org.xml.sax.SAXException
See Also:
XMLSerializer.childAsAttributes(JAXBObject, String)

childAsURIs

public void childAsURIs(com.sun.xml.bind.JAXBObject o,
                        java.lang.String fieldName)
                 throws org.xml.sax.SAXException
Method childAsURIs

Specified by:
childAsURIs in interface XMLSerializer
Parameters:
o - JAXBObject
fieldName - String
Throws:
org.xml.sax.SAXException
See Also:
XMLSerializer.childAsURIs(JAXBObject, String)

reportError

public void reportError(javax.xml.bind.ValidationEvent ve)
                 throws com.sun.xml.bind.serializer.AbortSerializationException
Method reportError

Specified by:
reportError in interface XMLSerializer
Parameters:
ve - ValidationEvent
Throws:
com.sun.xml.bind.serializer.AbortSerializationException
See Also:
XMLSerializer.reportError(ValidationEvent)

reportMissingObjectError

public void reportMissingObjectError(java.lang.String fieldName)
                              throws org.xml.sax.SAXException
Method reportMissingObjectError

Parameters:
fieldName - String
Throws:
org.xml.sax.SAXException

_assert

private static void _assert(boolean b)
Method _assert

Parameters:
b - boolean