Class ObjectInstance

java.lang.Object
org.simpleframework.xml.core.ObjectInstance
All Implemented Interfaces:
Instance

class ObjectInstance extends Object implements Instance
The ObjectInstance is used to instantiate an object from the criteria provided in the given Value. If the value contains a reference then the reference is provided from this type. For performance the Context object is used to instantiate the object as it contains a reflection cache of constructors.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Context
    This is the context that is used to create the instance.
    private final Class
    This is the new class that is used for the instantiation.
    private final Value
    This is the value object that will be wrapped by this.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ObjectInstance(Context context, Value value)
    Constructor for the ObjectInstance 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 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

    • context

      private final Context context
      This is the context that is used to create the instance.
    • value

      private final Value value
      This is the value object that will be wrapped by this.
    • type

      private final Class type
      This is the new class that is used for the instantiation.
  • Constructor Details

    • ObjectInstance

      public ObjectInstance(Context context, Value value)
      Constructor for the ObjectInstance object. This is used to create an instance of the type described by the value object. If the value object contains a reference then this will simply provide that reference.
      Parameters:
      context - this is used to instantiate the object
      value - this is the value describing the instance
  • 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
    • getInstance

      public Object getInstance(Class type) 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.
      Parameters:
      type - this is the type that is to be instantiated
      Returns:
      an instance of the type this object represents
      Throws:
      Exception
    • setInstance

      public Object setInstance(Object object)
      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:
      object - this is the object to insert as the value
      Returns:
      an instance of the type this object represents
    • 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. Types that are references could be substitutes objects are existing ones.
      Specified by:
      isReference in interface Instance
      Returns:
      this returns true if the object is a reference
    • 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