info.bioinfweb.jphyloio.objecttranslation.implementations

## Class SimpleValueTranslator<O>

- java.lang.Object
- - info.bioinfweb.jphyloio.objecttranslation.implementations.AbstractObjectTranslator<O>
  - - info.bioinfweb.jphyloio.objecttranslation.implementations.SimpleValueTranslator<O>

- Type Parameters:
    `O` - the type of Java object this translator instance is able to handle
  All Implemented Interfaces:
    ObjectTranslator<O>
  Direct Known Subclasses:
    IllegalArgumentExceptionSimpleValueTranslator, ListTranslator, NumericValueTranslator, StringTranslator, URITranslator

      public abstract class SimpleValueTranslator<O>
      extends AbstractObjectTranslator<O>

  Abstract base class for converting simple types that can be described by strings and do not need a more complex XML representation.
  Since:
    0.0.0
  Author:
    Ben Stöver

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `MAX_STRING_REPRESENTATION_LENGTH`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleValueTranslator()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.
    `java.lang.String` | `javaToRepresentation(java.lang.Object object, WriterStreamDataProvider<?> streamDataProvider)` Converts the object by invoking its `Object.toString()` method.
    `O` | `readXMLRepresentation(javax.xml.stream.XMLEventReader reader, ReaderStreamDataProvider<?> streamDataProvider)` Reads an object from the character data available at the current position of the XML reader.
    `void` | `writeXMLRepresentation(javax.xml.stream.XMLStreamWriter writer, java.lang.Object object, WriterStreamDataProvider<?> streamDataProvider)` Writes the string representation of the specified object to an XML stream.

    - ### Methods inherited from class info.bioinfweb.jphyloio.objecttranslation.implementations.AbstractObjectTranslator

      `equals, hashCode`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface info.bioinfweb.jphyloio.objecttranslation.ObjectTranslator

      `getObjectClass, representationToJava`

- - ### Field Detail

    - #### MAX_STRING_REPRESENTATION_LENGTH

          public static final int MAX_STRING_REPRESENTATION_LENGTH

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SimpleValueTranslator

          public SimpleValueTranslator()

  - ### Method Detail

    - #### hasStringRepresentation

          public boolean hasStringRepresentation()

      Description copied from interface: `ObjectTranslator`
      Determines whether the objects handled by this instance have a simple string representation or need a more complex XML representation.

      Instances that return `false here` will throw an `UnsupportedOperationException`, if `ObjectTranslator.javaToRepresentation(Object, WriterStreamDataProvider)` is called.

      Returns:
        `true` if handled objects have a simple string representation or `false` if XML is necessary to represent the handled objects

    - #### javaToRepresentation

          public java.lang.String javaToRepresentation(java.lang.Object object,
                                                       WriterStreamDataProvider<?> streamDataProvider)
                                                throws java.lang.UnsupportedOperationException,
                                                       java.lang.ClassCastException

      Converts the object by invoking its `Object.toString()` method.
      Parameters:
        `object` - the object to be converted
        `streamDataProvider` - TODO
      Returns:
        the string representation of the object
      Throws:
        `java.lang.UnsupportedOperationException` - if objects handled by this instance can only be represented as XML
        `java.lang.ClassCastException` - if the specified object is not an instance of the supported class or does not implement the supported interface
      See Also:
        `ObjectTranslator.javaToRepresentation(java.lang.Object, WriterStreamDataProvider)`

    - #### writeXMLRepresentation

          public void writeXMLRepresentation(javax.xml.stream.XMLStreamWriter writer,
                                             java.lang.Object object,
                                             WriterStreamDataProvider<?> streamDataProvider)
                                      throws java.io.IOException,
                                             javax.xml.stream.XMLStreamException

      Writes the string representation of the specified object to an XML stream. (Calls `javaToRepresentation(Object, WriterStreamDataProvider)` internally.)
      Parameters:
        `writer` - the XML stream writer
        `object` - the object to be converted
        `streamDataProvider` - TODO
      Throws:
        `java.io.IOException` - if an I/O error occurs while trying to write to the specified writer
        `javax.xml.stream.XMLStreamException` - if an XML stream exception occurs while trying to write to the specified writer

    - #### readXMLRepresentation

          public O readXMLRepresentation(javax.xml.stream.XMLEventReader reader,
                                         ReaderStreamDataProvider<?> streamDataProvider)
                                  throws java.io.IOException,
                                         javax.xml.stream.XMLStreamException,
                                         InvalidObjectSourceDataException

      Reads an object from the character data available at the current position of the XML reader. Character data is consumed until an event different from `XMLStreamConstants.CHARACTERS` is consumed. If no event of this type is available, parsing the empty string is tried. (Calls `ObjectTranslator.representationToJava(String, ReaderStreamDataProvider)` internally.)
      Parameters:
        `reader` - the XML event reader to read the data from
        `streamDataProvider` - TODO
      Returns:
        the parsed object
      Throws:
        `JPhyloIOReaderException` - if the textual data found at the current position is longer than `MAX_STRING_REPRESENTATION_LENGTH`
        `java.io.IOException` - if an I/O error occurs while trying to read from the specified reader
        `javax.xml.stream.XMLStreamException` - if an XML stream exception occurs while trying to read from the specified reader
        `InvalidObjectSourceDataException` - if an unexpected XML event was encountered or an XML event has unexpected contents