com.sun.xml.bind.v2.runtime

Interface Transducer<ValueT>

public interface Transducer<ValueT>

Responsible for converting a Java object to a lexical representation and vice versa.

An implementation of this interface hides how this conversion happens.

Transducers are immutable.

Method Summary
voiddeclareNamespace(ValueT o, XMLSerializer w)
Declares the namespace URIs used in the given value to {@code w}.
QNamegetTypeName(ValueT instance)
Transducers implicitly work against a single XML type, but sometimes (most notably XMLGregorianCalendar, an instance may choose different XML types.
booleanisDefault()
If this Transducer is the default transducer for the ValueT, this method returns true.
ValueTparse(CharSequence lexical)
Converts the lexical representation to a value object.
CharSequenceprint(ValueT o)
Converts the given value to its lexical representation.
booleanuseNamespace()
If true, this Transducer doesn't declare any namespace, and therefore Transducer is no-op.
voidwriteLeafElement(XMLSerializer w, Name tagName, ValueT o, String fieldName)
Sends the result of the Transducer operation to one of the XMLSerializer method. but with the best representation of the value, not necessarily String.
voidwriteText(XMLSerializer w, ValueT o, String fieldName)
Sends the result of the Transducer operation to one of the XMLSerializer method, but with the best representation of the value, not necessarily String.

Method Detail

declareNamespace

public void declareNamespace(ValueT o, XMLSerializer w)
Declares the namespace URIs used in the given value to {@code w}.

Parameters: o never be null. w may be null if {@code !useNamespace}.

getTypeName

public QName getTypeName(ValueT instance)
Transducers implicitly work against a single XML type, but sometimes (most notably XMLGregorianCalendar, an instance may choose different XML types.

Returns: return non-null from this method allows transducers to specify the type it wants to marshal to. Most of the time this method returns null, in which case the implicitly associated type will be used.

isDefault

public boolean isDefault()
If this Transducer is the default transducer for the ValueT, this method returns true. Used exclusively by get

parse

public ValueT parse(CharSequence lexical)
Converts the lexical representation to a value object.

Parameters: lexical never be null.

Throws: AccessorException if the transducer is used to parse an user bean that uses XmlValue, then this exception may occur when it tries to set the leaf value to the bean. SAXException if the lexical form is incorrect, the error should be reported and SAXException may thrown (or it can return null to recover.)

print

public CharSequence print(ValueT o)
Converts the given value to its lexical representation.

Parameters: o never be null.

Returns: always non-null valid lexical representation.

useNamespace

public boolean useNamespace()
If true, this Transducer doesn't declare any namespace, and therefore Transducer is no-op. It also means that the parse method won't use the context parameter.

writeLeafElement

public void writeLeafElement(XMLSerializer w, Name tagName, ValueT o, String fieldName)
Sends the result of the Transducer operation to one of the XMLSerializer method. but with the best representation of the value, not necessarily String.

writeText

public void writeText(XMLSerializer w, ValueT o, String fieldName)
Sends the result of the Transducer operation to one of the XMLSerializer method, but with the best representation of the value, not necessarily String.