Package org.jibx.extras
Class BindingSelector
java.lang.Object
org.jibx.extras.BindingSelector
Binding selector that supports versioned XML documents. This looks for a
version attribute on the root element of the document, and selects the
mapping to be used for unmarshalling based on the value. It also supports
selecting the version for marshalling based on a supplied version argument
value.
- Version:
- 1.0
- Author:
- Dennis M. Sosnoski
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String
Name of version selection attribute.private final String
URI of version selection attribute.private final UnmarshallingContext
Basic unmarshalling context used to determine document version.private String
Encoding for output stream.private int
Indentation for marshalling.private OutputStream
Stream for marshalling output.private Writer
Output writer for marshalling.private final String[]
Array of bindings corresponding to versions.private final String[]
Array of version names. -
Constructor Summary
ConstructorsConstructorDescriptionBindingSelector
(String uri, String name, String[] versions, String[] bindings) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionGet initial unmarshalling context.void
marshalVersioned
(Object obj, String version) Marshal according to supplied version.void
setIndent
(int indent) Set nesting indent spaces.void
setOutput
(OutputStream outs, String enc) Set output stream and encoding.void
Set output writer.unmarshalVersioned
(Class clas) Unmarshal according to document version.
-
Field Details
-
m_attributeUri
URI of version selection attribute. -
m_attributeName
Name of version selection attribute. -
m_versionTexts
Array of version names. -
m_versionBindings
Array of bindings corresponding to versions. -
m_context
Basic unmarshalling context used to determine document version. -
m_outputStream
Stream for marshalling output. -
m_outputEncoding
Encoding for output stream. -
m_outputWriter
Output writer for marshalling. -
m_outputIndent
private int m_outputIndentIndentation for marshalling.
-
-
Constructor Details
-
BindingSelector
Constructor.- Parameters:
uri
- version selection attribute URI (null
if none)name
- version selection attribute nameversions
- array of version texts (first is default)bindings
- array of binding names corresponding to versions
-
-
Method Details
-
getContext
Get initial unmarshalling context. This gives access to the unmarshalling context used before the specific version is determined. The document information must be set for this context before callingunmarshalVersioned(java.lang.Class)
.- Returns:
- initial unmarshalling context
-
setOutput
Set output stream and encoding.- Parameters:
outs
- stream for document data outputenc
- document output encoding, ornull
for default
-
setOutput
Set output writer.- Parameters:
outw
- writer for document data output
-
setIndent
public void setIndent(int indent) Set nesting indent spaces.- Parameters:
indent
- number of spaces to indent per level, or disable indentation if negative
-
marshalVersioned
Marshal according to supplied version.- Parameters:
obj
- root object to be marshalledversion
- identifier for version to be used in marshalling- Throws:
JiBXException
- if error in marshalling
-
unmarshalVersioned
Unmarshal according to document version.- Parameters:
clas
- expected class mapped to root element of document (used only to look up the binding)- Returns:
- root object unmarshalled from document
- Throws:
JiBXException
- if error in unmarshalling
-