O
- the type of Java object this translator instance is able to handlepublic abstract class SimpleValueTranslator<O> extends AbstractObjectTranslator<O>
Modifier and Type | Field and Description |
---|---|
static int |
MAX_STRING_REPRESENTATION_LENGTH |
Constructor and Description |
---|
SimpleValueTranslator() |
Modifier and Type | Method and Description |
---|---|
boolean |
hasStringRepresentation()
Determines whether the objects handled by this instance have a simple string representation or need a more complex
XML representation.
|
String |
javaToRepresentation(Object object,
WriterStreamDataProvider<?> streamDataProvider)
Converts the object by invoking its
Object.toString() method. |
O |
readXMLRepresentation(XMLEventReader reader,
ReaderStreamDataProvider<?> streamDataProvider)
Reads an object from the character data available at the current position of the XML reader.
|
void |
writeXMLRepresentation(XMLStreamWriter writer,
Object object,
WriterStreamDataProvider<?> streamDataProvider)
Writes the string representation of the specified object to an XML stream.
|
equals, hashCode
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getObjectClass, representationToJava
public static final int MAX_STRING_REPRESENTATION_LENGTH
public SimpleValueTranslator()
public boolean hasStringRepresentation()
ObjectTranslator
Instances that return false here
will throw an UnsupportedOperationException
, if
ObjectTranslator.javaToRepresentation(Object, WriterStreamDataProvider)
is called.
true
if handled objects have a simple string representation or false
if XML is necessary to
represent the handled objectspublic String javaToRepresentation(Object object, WriterStreamDataProvider<?> streamDataProvider) throws UnsupportedOperationException, ClassCastException
Object.toString()
method.object
- the object to be convertedstreamDataProvider
- TODOUnsupportedOperationException
- if objects handled by this instance can only be represented as XMLClassCastException
- if the specified object is not an instance of the supported class or does not implement the supported
interfaceObjectTranslator.javaToRepresentation(java.lang.Object, WriterStreamDataProvider)
public void writeXMLRepresentation(XMLStreamWriter writer, Object object, WriterStreamDataProvider<?> streamDataProvider) throws IOException, XMLStreamException
javaToRepresentation(Object, WriterStreamDataProvider)
internally.)writer
- the XML stream writerobject
- the object to be convertedstreamDataProvider
- TODOIOException
- if an I/O error occurs while trying to write to the specified writerXMLStreamException
- if an XML stream exception occurs while trying to write to the specified writerpublic O readXMLRepresentation(XMLEventReader reader, ReaderStreamDataProvider<?> streamDataProvider) throws IOException, XMLStreamException, InvalidObjectSourceDataException
XMLStreamConstants.CHARACTERS
is consumed. If no event of this type is available, parsing the
empty string is tried. (Calls ObjectTranslator.representationToJava(String, ReaderStreamDataProvider)
internally.)reader
- the XML event reader to read the data fromstreamDataProvider
- TODOJPhyloIOReaderException
- if the textual data found at the current position is longer than
MAX_STRING_REPRESENTATION_LENGTH
IOException
- if an I/O error occurs while trying to read from the specified readerXMLStreamException
- if an XML stream exception occurs while trying to read from the specified readerInvalidObjectSourceDataException
- if an unexpected XML event was encountered or an XML event has unexpected contents