Package org.jibx.extras
Class BindingSelector
- java.lang.Object
-
- org.jibx.extras.BindingSelector
-
public class BindingSelector extends Object
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
-
-
Constructor Summary
Constructors Constructor Description BindingSelector(String uri, String name, String[] versions, String[] bindings)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.jibx.runtime.IUnmarshallingContextgetContext()Get initial unmarshalling context.voidmarshalVersioned(Object obj, String version)Marshal according to supplied version.voidsetIndent(int indent)Set nesting indent spaces.voidsetOutput(OutputStream outs, String enc)Set output stream and encoding.voidsetOutput(Writer outw)Set output writer.ObjectunmarshalVersioned(Class clas)Unmarshal according to document version.
-
-
-
Constructor Detail
-
BindingSelector
public BindingSelector(String uri, String name, String[] versions, String[] bindings)
Constructor.- Parameters:
uri- version selection attribute URI (nullif none)name- version selection attribute nameversions- array of version texts (first is default)bindings- array of binding names corresponding to versions
-
-
Method Detail
-
getContext
public org.jibx.runtime.IUnmarshallingContext 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
public void setOutput(OutputStream outs, String enc)
Set output stream and encoding.- Parameters:
outs- stream for document data outputenc- document output encoding, ornullfor default
-
setOutput
public void setOutput(Writer outw)
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
public void marshalVersioned(Object obj, String version) throws org.jibx.runtime.JiBXException
Marshal according to supplied version.- Parameters:
obj- root object to be marshalledversion- identifier for version to be used in marshalling- Throws:
org.jibx.runtime.JiBXException- if error in marshalling
-
unmarshalVersioned
public Object unmarshalVersioned(Class clas) throws org.jibx.runtime.JiBXException
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:
org.jibx.runtime.JiBXException- if error in unmarshalling
-
-