Top Description Methods
org.glassfish.jaxb.runtime.v2.runtime

public Interface Transducer<ValueT>

Known Direct Implementers
org.glassfish.jaxb.runtime.v2.model.impl.RuntimeBuiltinLeafInfoImpl, org.glassfish.jaxb.runtime.v2.model.impl.RuntimeClassInfoImpl.TransducerImpl, org.glassfish.jaxb.runtime.v2.model.impl.RuntimeEnumLeafInfoImpl, org.glassfish.jaxb.runtime.v2.runtime.FilterTransducer
Imports
com.sun.istack.NotNull, org.glassfish.jaxb.runtime.api.AccessorException, jakarta.xml.bind.annotation.XmlValue, org.xml.sax.SAXException, javax.xml.datatype.XMLGregorianCalendar, javax.xml.namespace.QName, javax.xml.stream.XMLStreamException, java.io.IOException

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.

Author
Kohsuke Kawaguchi ([email protected])

Method Summary

Modifier and TypeMethod and Description
public void
declareNamespace(ValueT
never be null.
o
,
XMLSerializer
may be null if !{@link #useNamespace()}.
w
)

Declares the namespace URIs used in the given value to w.

public QName

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.
getTypeName
(ValueT instance)

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

public ValueT
parse(CharSequence
never be null.
lexical
)

Converts the lexical representation to a value object.

public boolean
useNamespace()

If true, this doesn't declare any namespace, and therefore declareNamespace(Object, XMLSerializer) is no-op.

public 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.

public 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

declareNamespaceback to summary
public void declareNamespace(ValueT o, XMLSerializer w) throws AccessorException

Declares the namespace URIs used in the given value to w.

Parameters
o:ValueT

never be null.

w:XMLSerializer

may be null if !{@link #useNamespace()}.

getTypeNameback to summary
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:QName

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.

parseback to summary
public ValueT parse(CharSequence lexical) throws AccessorException, SAXException

Converts the lexical representation to a value object.

Parameters
lexical:CharSequence

never be null.

Exceptions
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.)
useNamespaceback to summary
public boolean useNamespace()

If true, this 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.

writeLeafElementback to summary
public void writeLeafElement(XMLSerializer w, Name tagName, ValueT o, String fieldName) throws IOException, SAXException, 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.

writeTextback to summary
public void writeText(XMLSerializer w, ValueT o, String fieldName) throws IOException, SAXException, 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.