Package com.sun.xml.bind.v2.runtime
Interface Transducer<ValueT>
- All Known Implementing Classes:
FilterTransducer
,InlineBinaryTransducer
,MimeTypedTransducer
,RuntimeBuiltinLeafInfoImpl
,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.
Transducer
s are immutable.
- Author:
- Kohsuke Kawaguchi ([email protected])
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Declares the namespace URIs used in the given value tow
.getTypeName
(ValueT instance) Transducers implicitly work against a single XML type, but sometimes (most notablyXMLGregorianCalendar
, an instance may choose different XML types.parse
(CharSequence lexical) Converts the lexical representation to a value object.Converts the given value to its lexical representation.boolean
If true, thisTransducer
doesn't declare any namespace, and thereforedeclareNamespace(Object, XMLSerializer)
is no-op.void
writeLeafElement
(XMLSerializer w, Name tagName, ValueT o, String fieldName) Sends the result of theprint(Object)
operation to one of theXMLSerializer.leafElement(Name, String, String)
method.void
writeText
(XMLSerializer w, ValueT o, String fieldName) Sends the result of theprint(Object)
operation to one of theXMLSerializer.text(String, String)
method, but with the best representation of the value, not necessarily String.
-
Method Details
-
useNamespace
boolean useNamespace()If true, thisTransducer
doesn't declare any namespace, and thereforedeclareNamespace(Object, XMLSerializer)
is no-op. It also means that theparse(CharSequence)
method won't use the context parameter. -
declareNamespace
Declares the namespace URIs used in the given value tow
.- Parameters:
o
- never be null.w
- may be null if!{@link #useNamespace()}
.- Throws:
AccessorException
-
print
Converts the given value to its lexical representation.- Parameters:
o
- never be null.- Returns:
- always non-null valid lexical representation.
- Throws:
AccessorException
-
parse
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 usesXmlValue
, 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, XMLStreamException, AccessorException Sends the result of theprint(Object)
operation to one of theXMLSerializer.text(String, String)
method, but with the best representation of the value, not necessarily String. -
writeLeafElement
void writeLeafElement(XMLSerializer w, Name tagName, @NotNull ValueT o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException Sends the result of theprint(Object)
operation to one of theXMLSerializer.leafElement(Name, String, String)
method. but with the best representation of the value, not necessarily String. -
getTypeName
Transducers implicitly work against a single XML type, but sometimes (most notablyXMLGregorianCalendar
, 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.
-