| java.lang.Object org.jibx.runtime.impl.MarshallingContext
MarshallingContext | public class MarshallingContext implements IMarshallingContext(Code) | | JiBX serializer supplying convenience methods for marshalling. Most of these
methods are designed for use in code generated by the binding generator.
author: Dennis M. Sosnoski version: 1.0 |
Method Summary | |
public void | addMarshalling(int index, String name) Define marshalling for class. | public MarshallingContext | attribute(int index, String name, String value) Generate text attribute. | public MarshallingContext | attribute(int index, String name, int value) Generate integer attribute. | public MarshallingContext | attribute(int index, String name, int value, String[] table) Generate enumeration attribute. | public String | buildNameString(int index, String name) Build name with optional namespace. | public MarshallingContext | closeStartContent() Close start tag with content to follow. | public MarshallingContext | closeStartEmpty() Close start tag with no content (empty tag). | public MarshallingContext | content(String value) Add text content to current element. | public MarshallingContext | content(int value) Add integer content to current element. | public MarshallingContext | content(int value, String[] table) Add enumeration content to current element. | public MarshallingContext | element(int index, String name, String value) Generate complete element with text content. | public MarshallingContext | element(int index, String name, int value) Generate complete element with integer content. | public MarshallingContext | element(int index, String name, int value, String[] table) Generate complete element with enumeration content. | public void | endDocument() End document. | public MarshallingContext | endTag(int index, String name) Generate end tag for element. | public IBindingFactory | getFactory() Return the binding factory used to create this unmarshaller. | public HashMap | getIdMap() Get shared ID map. | public int | getIndent() Get current nesting indent spaces. | public IMarshaller | getMarshaller(int index, String name) Find the marshaller for a particular class index
in the current context. | public String[] | getNamespaces() Get namespace URIs for mapping. | public int | getStackDepth() Get current marshalling object stack depth. | public Object | getStackObject(int depth) Get object from marshalling stack. | public Object | getStackTop() Get top object on marshalling stack. | public Object | getUserContext() Get the user context object. | public IXMLWriter | getXmlWriter() Get the writer being used for output. | public MarshallingContext | marshalCollection(Collection col) Marshal all items in a collection. | public MarshallingContext | marshalCollection(ArrayList col) Marshal all items in a collection. | public MarshallingContext | marshalCollection(Vector col) Marshal all items in a collection. | public void | marshalDocument(Object root) Marshal document from root object without XML declaration. | public void | marshalDocument(Object root, String enc, Boolean alone) Marshal document from root object. | public void | marshalDocument(Object root, String enc, Boolean alone, OutputStream outs) Marshal document from root object to output stream with encoding. | public void | marshalDocument(Object root, String enc, Boolean alone, Writer outw) Marshal document from root object to writer. | protected void | marshalRoot(Object root) Marshal document from root object. | public void | popObject() Pop marshalled object from stack. | public void | pushObject(Object obj) Push created object to marshalling stack. | public void | removeMarshalling(int index) Undefine marshalling for element. | public void | reset() Reset to initial state for reuse. | public void | setFromContext(MarshallingContext parent) Initializes the context to use the same marshalled text destination and
parameters as another marshalling context. | public void | setIndent(int count) Set nesting indent spaces. | public void | setIndent(int count, String newline, char indent) Set nesting indentation. | public void | setOutput(OutputStream outs, String enc, ICharacterEscaper esc) Set output stream with encoding and escaper. | public void | setOutput(OutputStream outs, String enc) Set output stream and encoding. | public void | setOutput(Writer outw, ICharacterEscaper esc) Set output writer and escaper. | public void | setOutput(Writer outw) Set output writer. | public void | setUserContext(Object obj) Set a user context object. | public void | setXmlWriter(IXMLWriter xwrite) Set the writer being used for output. | public void | startDocument(String enc, Boolean alone) Start document. | public void | startDocument(String enc, Boolean alone, OutputStream outs) Start document with output stream and encoding. | public void | startDocument(String enc, Boolean alone, Writer outw) Start document with writer. | public MarshallingContext | startTag(int index, String name) Generate start tag for element without attributes. | public MarshallingContext | startTagAttributes(int index, String name) Generate start tag for element with attributes. | public MarshallingContext | startTagNamespaces(int index, String name, int[] nums, String[] prefs) Generate start tag for element with namespaces. | public MarshallingContext | writeCData(String text) Write CDATA text to document. | public MarshallingContext | writeContent(String text) Write content value with character entity substitutions. |
XML_NAMESPACE | final public static String XML_NAMESPACE(Code) | | Fixed XML namespace.
|
m_userContext | protected Object m_userContext(Code) | | User context object (not used by JiBX, only for user convenience).
|
MarshallingContext | public MarshallingContext(String[] classes, String[] mcs, String[] uris, IBindingFactory ifact)(Code) | | Constructor.
Parameters: classes - ordered array of class names included in mappingdefinition (reference kept, must be constant) Parameters: mcs - names of marshaller classes for indexes with fixed marshallers(as opposed to mapping slots, which may be overridden; reference kept,must be constant) Parameters: uris - ordered array of URIs for namespaces used in binding (mustbe constant; the value in position 0 must always be the empty string "",and the value in position 1 must always be the XML namespace"http://www.w3.org/XML/1998/namespace") Parameters: ifact - binding factory creating this unmarshaller |
addMarshalling | public void addMarshalling(int index, String name)(Code) | | Define marshalling for class. Adds the marshalling definition using fixed
indexes for each class, allowing direct lookup of the marshaller when
multiple versions are defined.
Parameters: index - class index for marshalling definition Parameters: name - marshaller class name handling |
attribute | public MarshallingContext attribute(int index, String name, String value) throws JiBXException(Code) | | Generate text attribute. This can only be used following an open start
tag with attributes.
Parameters: index - namespace URI index number Parameters: name - attribute name Parameters: value - text value for attribute (cannot be null ) this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
attribute | public MarshallingContext attribute(int index, String name, int value) throws JiBXException(Code) | | Generate integer attribute. This can only be used following an open start
tag.
Parameters: index - namespace URI index number Parameters: name - attribute name Parameters: value - integer value for attribute this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
attribute | public MarshallingContext attribute(int index, String name, int value, String[] table) throws JiBXException(Code) | | Generate enumeration attribute. The actual text to be written is obtained
by indexing into the supplied array of values. This can only be used
following an open start tag.
Parameters: index - namespace URI index number Parameters: name - attribute name Parameters: value - integer enumeration value (zero-based) Parameters: table - text values in enumeration this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
buildNameString | public String buildNameString(int index, String name)(Code) | | Build name with optional namespace. Just returns the appropriate
name format.
Parameters: index - namespace URI index number Parameters: name - local name part of name formatted name string |
content | public MarshallingContext content(int value) throws JiBXException(Code) | | Add integer content to current element.
Parameters: value - integer element content this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
content | public MarshallingContext content(int value, String[] table) throws JiBXException(Code) | | Add enumeration content to current element. The actual text to be
written is obtained by indexing into the supplied array of values.
Parameters: value - integer enumeration value (zero-based) Parameters: table - text values in enumeration this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
element | public MarshallingContext element(int index, String name, String value) throws JiBXException(Code) | | Generate complete element with text content.
Parameters: index - namespace URI index number Parameters: name - element name Parameters: value - text element content this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
element | public MarshallingContext element(int index, String name, int value) throws JiBXException(Code) | | Generate complete element with integer content.
Parameters: index - namespace URI index number Parameters: name - element name Parameters: value - integer element content this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
element | public MarshallingContext element(int index, String name, int value, String[] table) throws JiBXException(Code) | | Generate complete element with enumeration content. The actual text to be
written is obtained by indexing into the supplied array of values.
Parameters: index - namespace URI index number Parameters: name - element name Parameters: value - integer enumeration value (zero-based) Parameters: table - text values in enumeration this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
endDocument | public void endDocument() throws JiBXException(Code) | | End document. Finishes all output and closes the document. Note that if
this is called with an imcomplete marshalling the result will not be
well-formed XML.
throws: JiBXException - on any error (possibly wrapping other exception) |
endTag | public MarshallingContext endTag(int index, String name) throws JiBXException(Code) | | Generate end tag for element.
Parameters: index - namespace URI index number Parameters: name - element name this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
getFactory | public IBindingFactory getFactory()(Code) | | Return the binding factory used to create this unmarshaller.
binding factory |
getIdMap | public HashMap getIdMap()(Code) | | Get shared ID map. The ID map returned is not used directly by the
marshalling code, but is provided to support user extensions.
ID map |
getIndent | public int getIndent()(Code) | | Get current nesting indent spaces. This returns the number of spaces used
to show indenting, if used.
number of spaces indented per level, or negative if indentationdisabled |
getMarshaller | public IMarshaller getMarshaller(int index, String name) throws JiBXException(Code) | | Find the marshaller for a particular class index
in the current context.
TODO: Eliminate the string passing, since it's not a common enough
problem to be worth checking (and with abstract mappings can be really
difficult to set properly)
Parameters: index - class index for marshalling definition Parameters: name - fully qualified name of class to be marshalled (used onlyfor validation) marshalling handler for class throws: JiBXException - on any error (possibly wrapping other exception) |
getNamespaces | public String[] getNamespaces()(Code) | | Get namespace URIs for mapping. This gets the full ordered array of
namespaces known in the binding used for this marshalling, where the
index number of each namespace URI is the namespace index used to lookup
the prefix when marshalling a name in that namespace. The returned array
must not be modified.
array of namespaces |
getStackDepth | public int getStackDepth()(Code) | | Get current marshalling object stack depth. This allows tracking
nested calls to marshal one object while in the process of
marshalling another object. The bottom item on the stack is always the
root object being marshalled.
number of objects in marshalling stack |
getStackObject | public Object getStackObject(int depth)(Code) | | Get object from marshalling stack. This stack allows tracking nested
calls to marshal one object while in the process of marshalling
another object. The bottom item on the stack is always the root object
being marshalled.
Parameters: depth - object depth in stack to be retrieved (must be in the rangeof zero to the current depth minus one). object from marshalling stack |
getStackTop | public Object getStackTop()(Code) | | Get top object on marshalling stack. This is safe to call even when no
objects are on the stack.
object from marshalling stack, or null if none |
getXmlWriter | public IXMLWriter getXmlWriter()(Code) | | Get the writer being used for output.
XML writer used for output |
marshalCollection | public MarshallingContext marshalCollection(Collection col) throws JiBXException(Code) | | Marshal all items in a collection. This variation is for generic
collections.
Parameters: col - collection of items to be marshalled this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
marshalCollection | public MarshallingContext marshalCollection(ArrayList col) throws JiBXException(Code) | | Marshal all items in a collection. This variation is for ArrayList
collections.
Parameters: col - collection of items to be marshalled this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
marshalCollection | public MarshallingContext marshalCollection(Vector col) throws JiBXException(Code) | | Marshal all items in a collection. This variation is for Vector
collections.
Parameters: col - collection of items to be marshalled this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
marshalDocument | public void marshalDocument(Object root) throws JiBXException(Code) | | Marshal document from root object without XML declaration. This can only
be validly called immediately following one of the set output methods;
otherwise the output document will be corrupt. The effect of this method
is the same as the sequence of a call to marshal the root object using
this context followed by a call to
MarshallingContext.endDocument .
Parameters: root - object at root of structure to be marshalled, which must havea top-level mapping in the binding throws: JiBXException - on any error (possibly wrapping other exception) |
marshalDocument | public void marshalDocument(Object root, String enc, Boolean alone) throws JiBXException(Code) | | Marshal document from root object. This can only be validly called
immediately following one of the set output methods; otherwise the output
document will be corrupt. The effect of this method is the same as the
sequence of a call to
MarshallingContext.startDocument , a call to marshal the root
object using this context, and finally a call to
MarshallingContext.endDocument .
Parameters: root - object at root of structure to be marshalled, which must havea top-level mapping in the binding Parameters: enc - document encoding, null if not specified Parameters: alone - standalone document flag, null if notspecified throws: JiBXException - on any error (possibly wrapping other exception) |
marshalDocument | public void marshalDocument(Object root, String enc, Boolean alone, OutputStream outs) throws JiBXException(Code) | | Marshal document from root object to output stream with encoding. The
effect of this method is the same as the sequence of a call to
MarshallingContext.startDocument , a call to marshal the root object using this context,
and finally a call to
MarshallingContext.endDocument .
Parameters: root - object at root of structure to be marshalled, which must havea top-level mapping in the binding Parameters: enc - document encoding, null if not specified Parameters: alone - standalone document flag, null if notspecified Parameters: outs - stream for document data output throws: JiBXException - on any error (possibly wrapping other exception) |
marshalDocument | public void marshalDocument(Object root, String enc, Boolean alone, Writer outw) throws JiBXException(Code) | | Marshal document from root object to writer. The effect of this method
is the same as the sequence of a call to
MarshallingContext.startDocument , a call
to marshal the root object using this context, and finally a call to
MarshallingContext.endDocument .
Parameters: root - object at root of structure to be marshalled, which must havea top-level mapping in the binding Parameters: enc - document encoding, null if not specified Parameters: alone - standalone document flag, null if notspecified Parameters: outw - writer for document data output throws: JiBXException - on any error (possibly wrapping other exception) |
marshalRoot | protected void marshalRoot(Object root) throws JiBXException(Code) | | Marshal document from root object. This internal method just verifies
that the object is marshallable, then calls the marshal method on the
object itself.
Parameters: root - object at root of structure to be marshalled, which must havea top-level mapping in the binding throws: JiBXException - on any error (possibly wrapping other exception) |
pushObject | public void pushObject(Object obj)(Code) | | Push created object to marshalling stack. This must be called before
beginning the marshalling of the object. It is only called for objects
with structure, not for those converted directly to and from text.
Parameters: obj - object being marshalled |
removeMarshalling | public void removeMarshalling(int index)(Code) | | Undefine marshalling for element. Removes the marshalling
definition for a particular class index.
Parameters: index - class index for marshalling definition |
reset | public void reset()(Code) | | Reset to initial state for reuse. The context is serially reusable,
as long as this method is called to clear any retained state information
between uses. It is automatically called when output is set.
|
setFromContext | public void setFromContext(MarshallingContext parent) throws IOException(Code) | | Initializes the context to use the same marshalled text destination and
parameters as another marshalling context. This method is designed for
use when an initial context needs to create and invoke a secondary
context (generally from a different binding) in the course of an
marshalling operation. Note that once the secondary context has been used
it's generally necessary to do a
XMLWriterBase.flush operation
on the writer used by the that context before resuming output on the
parent.
Parameters: parent - context supplying target for marshalled document text throws: IOException - on error writing output |
setIndent | public void setIndent(int count)(Code) | | Set nesting indent spaces. This is advisory only, and implementations of
this interface are free to ignore it. The intent is to indicate that the
generated output should use indenting to illustrate element nesting.
Parameters: count - number of spaces to indent per level, or disableindentation if negative |
setIndent | public void setIndent(int count, String newline, char indent)(Code) | | Set nesting indentation. This is advisory only, and implementations of
this interface are free to ignore it. The intent is to indicate that the
generated output should use indenting to illustrate element nesting.
Parameters: count - number of character to indent per level, or disableindentation if negative (zero means new line only) Parameters: newline - sequence of characters used for a line ending(null means use the single character '\n') Parameters: indent - whitespace character used for indentation |
setOutput | public void setOutput(OutputStream outs, String enc, ICharacterEscaper esc) throws JiBXException(Code) | | Set output stream with encoding and escaper. This forces handling of the
output stream to use the Java character encoding support with the
supplied escaper.
Parameters: outs - stream for document data output Parameters: enc - document output encoding, or null uses UTF-8default Parameters: esc - escaper for writing characters to stream throws: JiBXException - if error setting output |
setOutput | public void setOutput(OutputStream outs, String enc) throws JiBXException(Code) | | Set output stream and encoding.
Parameters: outs - stream for document data output Parameters: enc - document output encoding, or null for default throws: JiBXException - if error creating setting output |
setOutput | public void setOutput(Writer outw, ICharacterEscaper esc)(Code) | | Set output writer and escaper.
Parameters: outw - writer for document data output Parameters: esc - escaper for writing characters |
setOutput | public void setOutput(Writer outw)(Code) | | Set output writer.
Parameters: outw - writer for document data output |
setUserContext | public void setUserContext(Object obj)(Code) | | Set a user context object. This context object is not used directly by
JiBX, but can be accessed by all types of user extension methods. The
context object is automatically cleared by the
MarshallingContext.reset() method,
so to make use of this you need to first call the appropriate version of
the setOutput() method, then this method, and finally one of
the marshalDocument methods which uses the previously-set
output (not the ones which take a stream or writer as parameter, since
they call setOutput() themselves).
Parameters: obj - user context object, or null if clearing existingcontext object See Also: MarshallingContext.getUserContext() |
setXmlWriter | public void setXmlWriter(IXMLWriter xwrite)(Code) | | Set the writer being used for output.
Parameters: xwrite - XML writer used for output |
startDocument | public void startDocument(String enc, Boolean alone) throws JiBXException(Code) | | Start document. This can only be validly called immediately following
one of the set output methods; otherwise the output document will be
corrupt.
Parameters: enc - document encoding, null if not specified Parameters: alone - standalone document flag, null if notspecified throws: JiBXException - on any error (possibly wrapping other exception) |
startDocument | public void startDocument(String enc, Boolean alone, OutputStream outs) throws JiBXException(Code) | | Start document with output stream and encoding. The effect is the same
as from first setting the output stream and encoding, then making the
call to start document.
Parameters: enc - document encoding, null if not specified Parameters: alone - standalone document flag, null if notspecified Parameters: outs - stream for document data output throws: JiBXException - on any error (possibly wrapping other exception) |
startDocument | public void startDocument(String enc, Boolean alone, Writer outw) throws JiBXException(Code) | | Start document with writer. The effect is the same as from first
setting the writer, then making the call to start document.
Parameters: enc - document encoding, null if not specified Parameters: alone - standalone document flag, null if notspecified Parameters: outw - writer for document data output throws: JiBXException - on any error (possibly wrapping other exception) |
startTag | public MarshallingContext startTag(int index, String name) throws JiBXException(Code) | | Generate start tag for element without attributes.
Parameters: index - namespace URI index number Parameters: name - element name this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
startTagAttributes | public MarshallingContext startTagAttributes(int index, String name) throws JiBXException(Code) | | Generate start tag for element with attributes. This only opens the start
tag, allowing attributes to be added immediately following this call.
Parameters: index - namespace URI index number Parameters: name - element name this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
startTagNamespaces | public MarshallingContext startTagNamespaces(int index, String name, int[] nums, String[] prefs) throws JiBXException(Code) | | Generate start tag for element with namespaces. This creates the actual
start tag, along with any necessary namespace declarations. Previously
active namespace declarations are not duplicated. The tag is
left incomplete, allowing other attributes to be added.
TODO: Handle nested default namespaces declarations, prefixes for outers
Parameters: index - namespace URI index number Parameters: name - element name Parameters: nums - array of namespace indexes defined by this element (mustbe constant, reference is kept until end of element) Parameters: prefs - array of namespace prefixes mapped by this element (nonull values, use "" for default namespace declaration) this context (to allow chained calls) throws: JiBXException - on any error (possibly wrapping other exception) |
writeContent | public MarshallingContext writeContent(String text) throws IOException(Code) | | Write content value with character entity substitutions.
Parameters: text - content value text this context (to allow chained calls) throws: IOException - on error writing to document |
|
|