com.sun.xml.bind.v2.runtime
Interface Transducer<ValueT>

All Known Implementing Classes:
FilterTransducer, InlineBinaryTransducer, MimeTypedTransducer, RuntimeBuiltinLeafInfoImpl, RuntimeEnumLeafInfoImpl, SchemaTypeTransducer

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
 void declareNamespace(ValueT o, XMLSerializer w)
          Declares the namespace URIs used in the given value to w.
 QName getTypeName(ValueT instance)
          Transducers implicitly work against a single XML type, but sometimes (most notably XMLGregorianCalendar, an instance may choose different XML types.
 boolean isDefault()
          If this Transducer is the default transducer for the ValueT, this method returns true.
 ValueT parse(CharSequence lexical)
          Converts the lexical representation to a value object.
 CharSequence print(ValueT o)
          Converts the given value to its lexical representation.
 boolean useNamespace()
          If true, this Transducer doesn't declare any namespace, and therefore declareNamespace(Object, XMLSerializer) is no-op.
 void writeLeafElement(XMLSerializer w, Name tagName, ValueT o, String fieldName)
          Sends the result of the print(Object) operation to one of the XMLSerializer.leafElement(Name, String, String) method.
 void writeText(XMLSerializer w, ValueT o, String fieldName)
          Sends the result of the print(Object) operation to one of the XMLSerializer.text(String, String) method, but with the best representation of the value, not necessarily String.
 

Method Detail

isDefault

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


useNamespace

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


declareNamespace

void declareNamespace(ValueT o,
                      XMLSerializer w)
                      throws AccessorException
Declares the namespace URIs used in the given value to w.

Parameters:
o - never be null.
w - may be null if !{@link #useNamespace()}.
Throws:
AccessorException

print

@NotNull
CharSequence print(@NotNull
                           ValueT o)
                   throws AccessorException
Converts the given value to its lexical representation.

Parameters:
o - never be null.
Returns:
always non-null valid lexical representation.
Throws:
AccessorException

parse

ValueT parse(CharSequence lexical)
             throws AccessorException,
                    SAXException
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.)

writeText

void writeText(XMLSerializer w,
               ValueT o,
               String fieldName)
               throws IOException,
                      SAXException,
                      javax.xml.stream.XMLStreamException,
                      AccessorException
Sends the result of the print(Object) operation to one of the XMLSerializer.text(String, String) method, but with the best representation of the value, not necessarily String.

Throws:
IOException
SAXException
javax.xml.stream.XMLStreamException
AccessorException

writeLeafElement

void writeLeafElement(XMLSerializer w,
                      Name tagName,
                      @NotNull
                      ValueT o,
                      String fieldName)
                      throws IOException,
                             SAXException,
                             javax.xml.stream.XMLStreamException,
                             AccessorException
Sends the result of the print(Object) operation to one of the XMLSerializer.leafElement(Name, String, String) method. but with the best representation of the value, not necessarily String.

Throws:
IOException
SAXException
javax.xml.stream.XMLStreamException
AccessorException

getTypeName

QName getTypeName(@NotNull
                  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.