Class InstanceFactory.ClassInstance

java.lang.Object
org.simpleframework.xml.core.InstanceFactory.ClassInstance
All Implemented Interfaces:
Instance
Enclosing class:
InstanceFactory

private class InstanceFactory.ClassInstance extends Object implements Instance
The ClassInstance object is used to create an object by using a Class to determine the type. If the given class can not be instantiated then this throws an exception when the instance is requested. For performance an instantiator is given as it contains a reflection cache for constructors.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Class
    This is the type of the instance that is to be created.
    private Object
    This represents the value of the instance if it is set.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the ClassInstance object.
  • Method Summary

    Modifier and Type
    Method
    Description
    This method is used to acquire an instance of the type that is defined by this object.
    This is the type of the object instance that will be created by the getInstance method.
    boolean
    This is used to determine if the type is a reference type.
    This method is used acquire the value from the type and if possible replace the value for the type.

    Methods inherited from class java.lang.Object

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

    • value

      private Object value
      This represents the value of the instance if it is set.
    • type

      private Class type
      This is the type of the instance that is to be created.
  • Constructor Details

    • ClassInstance

      public ClassInstance(Class type)
      Constructor for the ClassInstance object. This is used to create an instance of the specified type. If the given type can not be instantiated then an exception is thrown.
      Parameters:
      type - this is the type that is to be instantiated
  • Method Details

    • getInstance

      public Object getInstance() throws Exception
      This method is used to acquire an instance of the type that is defined by this object. If for some reason the type can not be instantiated an exception is thrown from this.
      Specified by:
      getInstance in interface Instance
      Returns:
      an instance of the type this object represents
      Throws:
      Exception
    • setInstance

      public Object setInstance(Object value) throws Exception
      This method is used acquire the value from the type and if possible replace the value for the type. If the value can not be replaced then an exception should be thrown. This is used to allow primitives to be inserted into a graph.
      Specified by:
      setInstance in interface Instance
      Parameters:
      value - this is the value to insert as the type
      Returns:
      an instance of the type this object represents
      Throws:
      Exception
    • getType

      public Class getType()
      This is the type of the object instance that will be created by the getInstance method. This allows the deserialization process to perform checks against the field.
      Specified by:
      getType in interface Instance
      Returns:
      the type of the object that will be instantiated
    • isReference

      public boolean isReference()
      This is used to determine if the type is a reference type. A reference type is a type that does not require any XML deserialization based on its annotations. Values that are references could be substitutes objects or existing ones.
      Specified by:
      isReference in interface Instance
      Returns:
      this returns true if the object is a reference