|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.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 | |
---|---|
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(java.lang.String mapname,
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. |
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(java.lang.String mapname)
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. |
java.lang.Object |
getUserContext()
Get the user context object. |
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. |
void |
popNamespaces()
End use of namespace indexes from a separate binding. |
void |
popObject()
Pop marshalled object from stack. |
void |
pushNamespaces(java.lang.String factname)
Use namespace indexes from a separate binding, as identified by that binding's factory class name. |
void |
pushObject(java.lang.Object obj)
Push created object to marshalling stack. |
void |
removeMarshalling(java.lang.String mapname)
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 |
setUserContext(java.lang.Object obj)
Set a user context object. |
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 |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String XML_NAMESPACE
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 |
---|
public 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) throws java.io.IOException
XMLWriterBase.flush()
operation
on the writer used by the that context before resuming output on the
parent.
parent
- context supplying target for marshalled document text
java.io.IOException
- on error writing outputpublic 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(java.lang.String mapname, java.lang.String name) throws JiBXException
mapname
- mapping name associated with unmarshallername
- marshaller class name handling
JiBXException
- if unknown mapping namepublic void removeMarshalling(java.lang.String mapname) throws JiBXException
mapname
- mapping name associated with unmarshaller
JiBXException
- if unknown mapping namepublic 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(java.lang.String mapname) throws JiBXException
getMarshaller
in interface IMarshallingContext
mapname
- marshaller mapping name (generally the class name to be
handled, or abstract mapping type name)
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 void pushNamespaces(java.lang.String factname)
pushNamespaces
in interface IMarshallingContext
factname
- binding factory class name for binding defining namespacespublic void popNamespaces()
pushNamespaces(String)
,
restoring whatever namespace usage was in effect prior to that call.
popNamespaces
in interface IMarshallingContext
public java.util.HashMap getIdMap()
public void setUserContext(java.lang.Object obj)
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).
setUserContext
in interface IMarshallingContext
obj
- user context object, or null
if clearing existing
context objectgetUserContext()
public java.lang.Object getUserContext()
getUserContext
in interface IMarshallingContext
null
if no context object
setsetUserContext(Object)
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 |