SAXMarshaller.java revision c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.6-b27-fcs
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2012.06.11 at 10:34:16 AM PDT
//
/**
* 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
*/
public class SAXMarshaller implements XMLSerializer
{
/**
* "Attributes" object that is passed to the startElement event.
* One object is reused throughout the marshalling.
*/
/** This object receives SAX2 events generated from the marshaller. */
private final ContentHandler writer;
/** Marshaller object to which this object belongs. */
private final MarshallerImpl owner;
/** Objects referenced through IDREF. */
/** Objects with ID. */
/** Object currently marshalling itself. */
private JAXBObject currentTarget;
/**
* Creates a marshalling context by designating the ContentHandler
* that receives generated SAX2 events.
*/
public SAXMarshaller( ContentHandler _writer, NamespacePrefixMapper prefixMapper, MarshallerImpl _owner ) {
this.nsContext = new NamespaceContextImpl(
}
/** namespace context. */
private final NamespaceContextImpl nsContext;
//
//
// name stack
//
//
/** Element name stack implemented as an array of (uri,local) pairs. */
private int elementLen=0;
// reallocate buffer
elementStack = buf;
}
}
/**
* Starts marshalling of an element.
* Calling this method will push the internal state into the
* internal stack.
*/
boolean isRoot = false;
if( elementLen==0 ) {
isRoot = true;
// this is the root element. suggest this as the default namespace
suggestion = "";
}
// declare this uri
// if this is the root element, declare user-specified namespace URIs.
if( isRoot ) {
// work defensively. we are calling an user-defined method.
}
}
}
}
}
};
}
};
public void endNamespaceDecls() throws SAXException {
}
/**
* This method has to be called after the 1st pass is completed.
*/
public void endAttributes() throws SAXException {
// calculate QName of the element
else
// fire startPrefixMapping events
// fire the startElement event
// reset attributes
attributes.clear();
// prepare to collect texts
}
/**
* Ends marshalling of an element.
* Pops the internal stack.
*/
public void endElement() throws SAXException {
else
// pop namespace bindings and
// fire endPrefixMapping events
popElement();
// prepare to collect texts
}
/** Buffer for collecting characters. */
/**
* Marshalls text.
*
* <p>
* 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,
*
* <pre>
* c.startAttribute();
* c.text("abc");
* c.text("def");
* c.endAttribute("","foo");
* </pre>
*
* will generate foo="abc def".
*
* <p>
* 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,
*
* <pre>
* c.startElement("","foo");
* c.endAttributes();
* c.text("abc");
* c.text("def");
* c.startElement("","bar");
* c.endAttributes();
* c.endElement();
* c.text("ghi");
* c.endElement();
* </pre>
*
* will generate <code><foo>abc def<bar/>ghi</foo></code>.
*/
// If the assertion fails, it must be a bug of xjc.
// right now, we are not expecting the text method to be called.
return;
}
}
/**
* Writes pending text (characters inside elements) to the writer.
* This method is called from startElement and endElement.
*/
private void writePendingText() throws SAXException {
// assert(textBuf!=null);
if(len!=0)
}
/**
* Starts marshalling of an attribute.
*
* The marshalling of an attribute will be done by
* <ol>
* <li>call the startAttribute method
* <li>call the text method (several times if necessary)
* <li>call the endAttribute method
* </ol>
*
* 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.
*/
// initialize the buffer to collect attribute value
// remember the attribute name. We'll use this value later.
this.attNamespaceUri = uri;
this.attLocalName = local;
}
// used to keep attribute names until the endAttribute method is called.
private String attNamespaceUri;
private String attLocalName;
public void endAttribute() {
// use CDATA as the attribute type. This preserves
// successive processors to collapse whitespaces.
// (we cannot prevent characters like #xD to be replaced to
// #x20, though).
//
// strictly speaking, attribute value normalization should be
// provessed by XML parser, so it's unclear whether XML writer
// uses this type value.
//
// in any way, CDATA type is the safest choice here.
// default namespace. don't need prefix
} else {
}
}
return value;
}
new ValidationEventLocatorImpl(obj) ) );
}
return id;
}
void reconcileID() throws AbortSerializationException {
// find objects that were not a part of the object graph
new ValidationEventLocatorImpl(o) ) );
}
// clear the garbage
}
if(o==null) {
// if null is passed, it usually means that the content tree object
// doesn't have some of its required property.
// as a marshaller, we should be generous, so we'll continue to marshal
// this document by skipping this missing object.
return;
}
currentTarget = o;
}
if(o==null) {
return;
}
currentTarget = o;
}
if(o==null) {
return;
}
currentTarget = o;
}
try {
} catch( JAXBException e ) {
throw new AbortSerializationException(e);
}
else
}
}
}
private static void _assert( boolean b ) {
if(!b)
throw new JAXBAssertionError();
}
/**
* Default {@link NamespacePrefixMapper} implementation used when
* it is not specified by the user.
*/
return "xsi";
return suggestion;
}
};
}