Class ClassTransform

java.lang.Object
org.simpleframework.xml.transform.ClassTransform
All Implemented Interfaces:
Transform<Class>

class ClassTransform extends Object implements Transform<Class>
The ClassTransform object is used to transform class values to and from string representations, which will be inserted in the generated XML document as the value place holder. The value must be readable and writable in the same format. Fields and methods annotated with the XML attribute annotation will use this to persist and retrieve the value to and from the XML source.
 
    @Attribute
    private Class target;
    
 
As well as the XML attribute values using transforms, fields and methods annotated with the XML element annotation will use this. Aside from the obvious difference, the element annotation has an advantage over the attribute annotation in that it can maintain any references using the CycleStrategy object.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    This is the string that represents the class for a boolean.
    private static final String
    This is the string that represents the class for a byte.
    private static final String
    This is the string that represents the class for a character.
    private static final String
    This is the string that represents the class for a double.
    private static final String
    This is the string that represents the class for a float.
    private static final String
    This is the string that represents the class for an integer.
    private static final String
    This is the string that represents the class for a long.
    private static final String
    This is the string that represents the class for a short.
    private static final String
    This is the string that represents the class for a void.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private ClassLoader
    This is used to acquire the caller class loader for this object.
    private static ClassLoader
    This is used to acquire the thread context class loader.
    read(String target)
    This method is used to convert the string value given to an appropriate representation.
    private Class
    This method is used to convert the string value given to an appropriate representation.
    write(Class target)
    This method is used to convert the provided value into an XML usable format.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ClassTransform

      ClassTransform()
  • Method Details

    • read

      public Class read(String target) throws Exception
      This method is used to convert the string value given to an appropriate representation. This is used when an object is being deserialized from the XML document and the value for the string representation is required.
      Specified by:
      read in interface Transform<Class>
      Parameters:
      target - this is the string representation of the class
      Returns:
      this returns an appropriate instanced to be used
      Throws:
      Exception
    • readPrimitive

      private Class readPrimitive(String target) throws Exception
      This method is used to convert the string value given to an appropriate representation. This is used when an object is being deserialized from the XML document and the value for the string representation is required.
      Parameters:
      target - this is the string representation of the class
      Returns:
      this returns an appropriate instanced to be used
      Throws:
      Exception
    • write

      public String write(Class target) throws Exception
      This method is used to convert the provided value into an XML usable format. This is used in the serialization process when there is a need to convert a field value in to a string so that that value can be written as a valid XML entity.
      Specified by:
      write in interface Transform<Class>
      Parameters:
      target - this is the value to be converted to a string
      Returns:
      this is the string representation of the given value
      Throws:
      Exception
    • getCallerClassLoader

      private ClassLoader getCallerClassLoader()
      This is used to acquire the caller class loader for this object. Typically this is only used if the thread context class loader is set to null. This ensures that there is at least some class loader available to the strategy to load the class.
      Returns:
      this returns the loader that loaded this class
    • getClassLoader

      private static ClassLoader getClassLoader()
      This is used to acquire the thread context class loader. This is the default class loader used by the cycle strategy. When using the thread context class loader the caller can switch the class loader in use, which allows class loading customization.
      Returns:
      this returns the loader used by the calling thread