|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jibx.runtime.impl.MarshallingContext
public class MarshallingContext
JiBX serializer supplying convenience methods for marshalling. Most of these methods are designed for use in code generated by the binding generator.
Field Summary | |
---|---|
private static int |
INITIAL_STACK_SIZE
Starting size for object stack. |
private java.lang.String[] |
m_classes
Names of classes included in mapping definition. |
private IBindingFactory |
m_factory
Binding factory used to create this unmarshaller. |
private int |
m_globalCount
Number of classes with global marshallers. |
private java.util.HashMap |
m_idMap
Shared map from IDs to objects. |
private char |
m_indentChar
Character used for indenting. |
private int |
m_indentCount
Indent character count per level. |
private java.lang.String[] |
m_marshallerClasses
Marshaller classes for mapping definition ( null for
mappings out of context). |
private IMarshaller[] |
m_marshallers
Marshallers for classes in mapping definition (lazy create of actual marshaller instances) |
private java.lang.String |
m_newLine
Character sequence for end of line. |
private java.lang.Object[] |
m_objectStack
Stack of objects being marshalled. |
private int |
m_stackDepth
Current marshalling stack depth. |
private java.lang.String[] |
m_uris
URIs for namespaces used in binding. |
private IXMLWriter |
m_writer
Output document handler. |
static java.lang.String |
XML_NAMESPACE
Fixed XML namespace. |
Constructor Summary | |
---|---|
MarshallingContext(java.lang.String[] classes,
java.lang.String[] mcs,
java.lang.String[] uris,
IBindingFactory ifact)
Constructor. |
Method Summary | |
---|---|
void |
addMarshalling(int index,
java.lang.String name)
Define marshalling for class. |
MarshallingContext |
attribute(int index,
java.lang.String name,
int value)
Generate integer attribute. |
MarshallingContext |
attribute(int index,
java.lang.String name,
int value,
java.lang.String[] table)
Generate enumeration attribute. |
MarshallingContext |
attribute(int index,
java.lang.String name,
java.lang.String value)
Generate text attribute. |
java.lang.String |
buildNameString(int index,
java.lang.String name)
Build name with optional namespace. |
MarshallingContext |
closeStartContent()
Close start tag with content to follow. |
MarshallingContext |
closeStartEmpty()
Close start tag with no content (empty tag). |
MarshallingContext |
content(int value)
Add integer content to current element. |
MarshallingContext |
content(int value,
java.lang.String[] table)
Add enumeration content to current element. |
MarshallingContext |
content(java.lang.String value)
Add text content to current element. |
private ICharacterEscaper |
createEscaper(java.lang.String enc)
Create character escaper for encoding. |
MarshallingContext |
element(int index,
java.lang.String name,
int value)
Generate complete element with integer content. |
MarshallingContext |
element(int index,
java.lang.String name,
int value,
java.lang.String[] table)
Generate complete element with enumeration content. |
MarshallingContext |
element(int index,
java.lang.String name,
java.lang.String value)
Generate complete element with text content. |
void |
endDocument()
End document. |
MarshallingContext |
endTag(int index,
java.lang.String name)
Generate end tag for element. |
IBindingFactory |
getFactory()
Return the binding factory used to create this unmarshaller. |
java.util.HashMap |
getIdMap()
Get shared ID map. |
int |
getIndent()
Get current nesting indent spaces. |
IMarshaller |
getMarshaller(int index,
java.lang.String name)
Find the marshaller for a particular class index in the current context. |
java.lang.String[] |
getNamespaces()
Get namespace URIs for mapping. |
int |
getStackDepth()
Get current marshalling object stack depth. |
java.lang.Object |
getStackObject(int depth)
Get object from marshalling stack. |
java.lang.Object |
getStackTop()
Get top object on marshalling stack. |
IXMLWriter |
getXmlWriter()
Get the writer being used for output. |
MarshallingContext |
marshalCollection(java.util.ArrayList col)
Marshal all items in a collection. |
MarshallingContext |
marshalCollection(java.util.Collection col)
Marshal all items in a collection. |
MarshallingContext |
marshalCollection(java.util.Vector col)
Marshal all items in a collection. |
void |
marshalDocument(java.lang.Object root)
Marshal document from root object without XML declaration. |
void |
marshalDocument(java.lang.Object root,
java.lang.String enc,
java.lang.Boolean alone)
Marshal document from root object. |
void |
marshalDocument(java.lang.Object root,
java.lang.String enc,
java.lang.Boolean alone,
java.io.OutputStream outs)
Marshal document from root object to output stream with encoding. |
void |
marshalDocument(java.lang.Object root,
java.lang.String enc,
java.lang.Boolean alone,
java.io.Writer outw)
Marshal document from root object to writer. |
protected void |
marshalRoot(java.lang.Object root)
Marshal document from root object. |
void |
popObject()
Pop marshalled object from stack. |
void |
pushObject(java.lang.Object obj)
Push created object to marshalling stack. |
void |
removeMarshalling(int index)
Undefine marshalling for element. |
void |
reset()
Reset to initial state for reuse. |
void |
setFromContext(MarshallingContext parent)
Initializes the context to use the same marshalled text destination and parameters as another marshalling context. |
void |
setIndent(int count)
Set nesting indent spaces. |
void |
setIndent(int count,
java.lang.String newline,
char indent)
Set nesting indentation. |
void |
setOutput(java.io.OutputStream outs,
java.lang.String enc)
Set output stream and encoding. |
void |
setOutput(java.io.OutputStream outs,
java.lang.String enc,
ICharacterEscaper esc)
Set output stream with encoding and escaper. |
void |
setOutput(java.io.Writer outw)
Set output writer. |
void |
setOutput(java.io.Writer outw,
ICharacterEscaper esc)
Set output writer and escaper. |
void |
setXmlWriter(IXMLWriter xwrite)
Set the writer being used for output. |
void |
startDocument(java.lang.String enc,
java.lang.Boolean alone)
Start document. |
void |
startDocument(java.lang.String enc,
java.lang.Boolean alone,
java.io.OutputStream outs)
Start document with output stream and encoding. |
void |
startDocument(java.lang.String enc,
java.lang.Boolean alone,
java.io.Writer outw)
Start document with writer. |
MarshallingContext |
startTag(int index,
java.lang.String name)
Generate start tag for element without attributes. |
MarshallingContext |
startTagAttributes(int index,
java.lang.String name)
Generate start tag for element with attributes. |
MarshallingContext |
startTagNamespaces(int index,
java.lang.String name,
int[] nums,
java.lang.String[] prefs)
Generate start tag for element with namespaces. |
MarshallingContext |
writeCData(java.lang.String text)
Write CDATA text to document. |
MarshallingContext |
writeContent(java.lang.String text)
Write content value with character entity substitutions. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String XML_NAMESPACE
private static final int INITIAL_STACK_SIZE
private IBindingFactory m_factory
private java.lang.String[] m_classes
private int m_globalCount
private java.lang.String[] m_marshallerClasses
null
for
mappings out of context).
private IMarshaller[] m_marshallers
private java.lang.String[] m_uris
private int m_stackDepth
private java.lang.Object[] m_objectStack
private int m_indentCount
private java.lang.String m_newLine
private char m_indentChar
private java.util.HashMap m_idMap
private IXMLWriter m_writer
Constructor Detail |
---|
public MarshallingContext(java.lang.String[] classes, java.lang.String[] mcs, java.lang.String[] uris, IBindingFactory ifact)
classes
- ordered array of class names included in mapping
definition (reference kept, must be constant)mcs
- names of marshaller classes for indexes with fixed marshallers
(as opposed to mapping slots, which may be overridden; reference kept,
must be constant)uris
- ordered array of URIs for namespaces used in binding (must
be 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")ifact
- binding factory creating this unmarshallerMethod Detail |
---|
private ICharacterEscaper createEscaper(java.lang.String enc) throws JiBXException
enc
- document output encoding, or null
for default
JiBXException
- if error creating setting outputpublic void setOutput(java.io.OutputStream outs, java.lang.String enc, ICharacterEscaper esc) throws JiBXException
setOutput
in interface IMarshallingContext
outs
- stream for document data outputenc
- document output encoding, or null
uses UTF-8
defaultesc
- escaper for writing characters to stream
JiBXException
- if error setting outputpublic void setOutput(java.io.OutputStream outs, java.lang.String enc) throws JiBXException
setOutput
in interface IMarshallingContext
outs
- stream for document data outputenc
- document output encoding, or null
for default
JiBXException
- if error creating setting outputpublic void setOutput(java.io.Writer outw, ICharacterEscaper esc)
setOutput
in interface IMarshallingContext
outw
- writer for document data outputesc
- escaper for writing characterspublic void setOutput(java.io.Writer outw)
setOutput
in interface IMarshallingContext
outw
- writer for document data outputpublic IXMLWriter getXmlWriter()
getXmlWriter
in interface IMarshallingContext
public void setXmlWriter(IXMLWriter xwrite)
setXmlWriter
in interface IMarshallingContext
xwrite
- XML writer used for outputpublic int getIndent()
getIndent
in interface IMarshallingContext
public void setIndent(int count)
setIndent
in interface IMarshallingContext
count
- number of spaces to indent per level, or disable
indentation if negativepublic void setIndent(int count, java.lang.String newline, char indent)
setIndent
in interface IMarshallingContext
count
- number of character to indent per level, or disable
indentation if negative (zero means new line only)newline
- sequence of characters used for a line ending
(null
means use the single character '\n')indent
- whitespace character used for indentationpublic void setFromContext(MarshallingContext parent)
parent
- context supplying target for marshalled document textpublic void reset()
reset
in interface IMarshallingContext
public IBindingFactory getFactory()
public java.lang.String[] getNamespaces()
public void startDocument(java.lang.String enc, java.lang.Boolean alone) throws JiBXException
startDocument
in interface IMarshallingContext
enc
- document encoding, null
if not specifiedalone
- standalone document flag, null
if not
specified
JiBXException
- on any error (possibly wrapping other exception)public void startDocument(java.lang.String enc, java.lang.Boolean alone, java.io.OutputStream outs) throws JiBXException
startDocument
in interface IMarshallingContext
enc
- document encoding, null
if not specifiedalone
- standalone document flag, null
if not
specifiedouts
- stream for document data output
JiBXException
- on any error (possibly wrapping other exception)public void startDocument(java.lang.String enc, java.lang.Boolean alone, java.io.Writer outw) throws JiBXException
startDocument
in interface IMarshallingContext
enc
- document encoding, null
if not specifiedalone
- standalone document flag, null
if not
specifiedoutw
- writer for document data output
JiBXException
- on any error (possibly wrapping other exception)public void endDocument() throws JiBXException
endDocument
in interface IMarshallingContext
JiBXException
- on any error (possibly wrapping other exception)public java.lang.String buildNameString(int index, java.lang.String name)
index
- namespace URI index numbername
- local name part of name
public MarshallingContext startTag(int index, java.lang.String name) throws JiBXException
index
- namespace URI index numbername
- element name
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext startTagAttributes(int index, java.lang.String name) throws JiBXException
index
- namespace URI index numbername
- element name
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext attribute(int index, java.lang.String name, java.lang.String value) throws JiBXException
index
- namespace URI index numbername
- attribute namevalue
- text value for attribute (cannot be null
)
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext attribute(int index, java.lang.String name, int value) throws JiBXException
index
- namespace URI index numbername
- attribute namevalue
- integer value for attribute
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext attribute(int index, java.lang.String name, int value, java.lang.String[] table) throws JiBXException
index
- namespace URI index numbername
- attribute namevalue
- integer enumeration value (zero-based)table
- text values in enumeration
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext closeStartContent() throws JiBXException
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext closeStartEmpty() throws JiBXException
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext content(java.lang.String value) throws JiBXException
value
- text element content
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext content(int value) throws JiBXException
value
- integer element content
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext content(int value, java.lang.String[] table) throws JiBXException
value
- integer enumeration value (zero-based)table
- text values in enumeration
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext endTag(int index, java.lang.String name) throws JiBXException
index
- namespace URI index numbername
- element name
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext element(int index, java.lang.String name, java.lang.String value) throws JiBXException
index
- namespace URI index numbername
- element namevalue
- text element content
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext element(int index, java.lang.String name, int value) throws JiBXException
index
- namespace URI index numbername
- element namevalue
- integer element content
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext element(int index, java.lang.String name, int value, java.lang.String[] table) throws JiBXException
index
- namespace URI index numbername
- element namevalue
- integer enumeration value (zero-based)table
- text values in enumeration
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext writeCData(java.lang.String text) throws java.io.IOException
text
- content value text
java.io.IOException
- on error writing to documentpublic MarshallingContext writeContent(java.lang.String text) throws java.io.IOException
text
- content value text
java.io.IOException
- on error writing to documentpublic MarshallingContext marshalCollection(java.util.Collection col) throws JiBXException
col
- collection of items to be marshalled
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext marshalCollection(java.util.ArrayList col) throws JiBXException
col
- collection of items to be marshalled
JiBXException
- on any error (possibly wrapping other exception)public MarshallingContext marshalCollection(java.util.Vector col) throws JiBXException
col
- collection of items to be marshalled
JiBXException
- on any error (possibly wrapping other exception)public void addMarshalling(int index, java.lang.String name)
index
- class index for marshalling definitionname
- marshaller class name handlingpublic void removeMarshalling(int index)
index
- class index for marshalling definitionpublic MarshallingContext startTagNamespaces(int index, java.lang.String name, int[] nums, java.lang.String[] prefs) throws JiBXException
index
- namespace URI index numbername
- element namenums
- array of namespace indexes defined by this element (must
be constant, reference is kept until end of element)prefs
- array of namespace prefixes mapped by this element (no
null
values, use "" for default namespace declaration)
JiBXException
- on any error (possibly wrapping other exception)public IMarshaller getMarshaller(int index, java.lang.String name) throws JiBXException
getMarshaller
in interface IMarshallingContext
index
- class index for marshalling definitionname
- fully qualified name of class to be marshalled (used only
for validation)
JiBXException
- on any error (possibly wrapping other exception)protected void marshalRoot(java.lang.Object root) throws JiBXException
root
- object at root of structure to be marshalled, which must have
a top-level mapping in the binding
JiBXException
- on any error (possibly wrapping other exception)public void marshalDocument(java.lang.Object root) throws JiBXException
endDocument()
.
marshalDocument
in interface IMarshallingContext
root
- object at root of structure to be marshalled, which must have
a top-level mapping in the binding
JiBXException
- on any error (possibly wrapping other exception)public void marshalDocument(java.lang.Object root, java.lang.String enc, java.lang.Boolean alone) throws JiBXException
startDocument(java.lang.String, java.lang.Boolean)
, a call to marshal the root
object using this context, and finally a call to endDocument()
.
marshalDocument
in interface IMarshallingContext
root
- object at root of structure to be marshalled, which must have
a top-level mapping in the bindingenc
- document encoding, null
if not specifiedalone
- standalone document flag, null
if not
specified
JiBXException
- on any error (possibly wrapping other exception)public void marshalDocument(java.lang.Object root, java.lang.String enc, java.lang.Boolean alone, java.io.OutputStream outs) throws JiBXException
startDocument(java.lang.String, java.lang.Boolean)
, a call to marshal the root object using this context,
and finally a call to endDocument()
.
marshalDocument
in interface IMarshallingContext
root
- object at root of structure to be marshalled, which must have
a top-level mapping in the bindingenc
- document encoding, null
if not specifiedalone
- standalone document flag, null
if not
specifiedouts
- stream for document data output
JiBXException
- on any error (possibly wrapping other exception)public void marshalDocument(java.lang.Object root, java.lang.String enc, java.lang.Boolean alone, java.io.Writer outw) throws JiBXException
startDocument(java.lang.String, java.lang.Boolean)
, a call
to marshal the root object using this context, and finally a call to
endDocument()
.
marshalDocument
in interface IMarshallingContext
root
- object at root of structure to be marshalled, which must have
a top-level mapping in the bindingenc
- document encoding, null
if not specifiedalone
- standalone document flag, null
if not
specifiedoutw
- writer for document data output
JiBXException
- on any error (possibly wrapping other exception)public java.util.HashMap getIdMap()
public void pushObject(java.lang.Object obj)
pushObject
in interface IMarshallingContext
obj
- object being marshalledpublic void popObject() throws JiBXException
popObject
in interface IMarshallingContext
JiBXException
- if no object on stackpublic int getStackDepth()
getStackDepth
in interface IMarshallingContext
public java.lang.Object getStackObject(int depth)
getStackObject
in interface IMarshallingContext
depth
- object depth in stack to be retrieved (must be in the range
of zero to the current depth minus one).
public java.lang.Object getStackTop()
getStackTop
in interface IMarshallingContext
null
if none
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |