org.jibx.extras
Class BindingSelector

java.lang.Object
  extended byorg.jibx.extras.BindingSelector

public class BindingSelector
extends java.lang.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

Field Summary
private  java.lang.String m_attributeName
          Name of version selection attribute.
private  java.lang.String m_attributeUri
          URI of version selection attribute.
private  UnmarshallingContext m_context
          Basic unmarshalling context used to determine document version.
private  java.lang.String m_outputEncoding
          Encoding for output stream.
private  int m_outputIndent
          Indentation for marshalling.
private  java.io.OutputStream m_outputStream
          Stream for marshalling output.
private  java.io.Writer m_outputWriter
          Output writer for marshalling.
private  java.lang.String[] m_versionBindings
          Array of bindings corresponding to versions.
private  java.lang.String[] m_versionTexts
          Array of version names.
 
Constructor Summary
BindingSelector(java.lang.String uri, java.lang.String name, java.lang.String[] versions, java.lang.String[] bindings)
          Constructor.
 
Method Summary
 IUnmarshallingContext getContext()
          Get initial unmarshalling context.
 void marshalVersioned(java.lang.Object obj, java.lang.String version)
          Marshal according to supplied version.
 void setIndent(int indent)
          Set nesting indent spaces.
 void setOutput(java.io.OutputStream outs, java.lang.String enc)
          Set output stream and encoding.
 void setOutput(java.io.Writer outw)
          Set output writer.
 java.lang.Object unmarshalVersioned(java.lang.Class clas)
          Unmarshal according to document version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_attributeUri

private final java.lang.String m_attributeUri
URI of version selection attribute.


m_attributeName

private final java.lang.String m_attributeName
Name of version selection attribute.


m_versionTexts

private final java.lang.String[] m_versionTexts
Array of version names.


m_versionBindings

private final java.lang.String[] m_versionBindings
Array of bindings corresponding to versions.


m_context

private final UnmarshallingContext m_context
Basic unmarshalling context used to determine document version.


m_outputStream

private java.io.OutputStream m_outputStream
Stream for marshalling output.


m_outputEncoding

private java.lang.String m_outputEncoding
Encoding for output stream.


m_outputWriter

private java.io.Writer m_outputWriter
Output writer for marshalling.


m_outputIndent

private int m_outputIndent
Indentation for marshalling.

Constructor Detail

BindingSelector

public BindingSelector(java.lang.String uri,
                       java.lang.String name,
                       java.lang.String[] versions,
                       java.lang.String[] bindings)
Constructor.

Parameters:
uri - version selection attribute URI (null if none)
name - version selection attribute name
versions - array of version texts (first is default)
bindings - array of binding names corresponding to versions
Method Detail

getContext

public 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 calling unmarshalVersioned(java.lang.Class).

Returns:
initial unmarshalling context

setOutput

public void setOutput(java.io.OutputStream outs,
                      java.lang.String enc)
Set output stream and encoding.

Parameters:
outs - stream for document data output
enc - document output encoding, or null for default

setOutput

public void setOutput(java.io.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(java.lang.Object obj,
                             java.lang.String version)
                      throws JiBXException
Marshal according to supplied version.

Parameters:
obj - root object to be marshalled
version - identifier for version to be used in marshalling
Throws:
JiBXException - if error in marshalling

unmarshalVersioned

public java.lang.Object unmarshalVersioned(java.lang.Class clas)
                                    throws 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:
JiBXException - if error in unmarshalling


Project Web Site