Class Reference

java.lang.Object
org.simpleframework.xml.strategy.Reference
All Implemented Interfaces:
Value

class Reference extends Object implements Value
The Reference object represents an object that is used to provide a reference to an already instantiated value. This is what is used if there is a cycle in the object graph. The getValue method of this object will simply return the object instance that was previously created.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Class
    This is the type of the object that this references.
    private Object
    This is the object instance that has already be created.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Reference(Object value, Class type)
    Constructor for the Reference object.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    This returns zero as this is a reference and will typically not be used to instantiate anything.
    This returns the type for the object that this references.
    This is used to acquire a reference to the instance that is taken from the created object graph.
    boolean
    This always returns true for this object.
    void
    This method is used set the value within this object.

    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 is the object instance that has already be created.
    • type

      private Class type
      This is the type of the object that this references.
  • Constructor Details

    • Reference

      public Reference(Object value, Class type)
      Constructor for the Reference object. This is used to create a value that will produce the specified value when the getValue method is invoked.
      Parameters:
      value - the value for the reference this represents
      type - this is the type value for the instance
  • Method Details

    • getValue

      public Object getValue()
      This is used to acquire a reference to the instance that is taken from the created object graph. This enables any cycles in the graph to be reestablished from the persisted XML.
      Specified by:
      getValue in interface Value
      Returns:
      this returns a reference to the created instance
    • setValue

      public void setValue(Object value)
      This method is used set the value within this object. Once this is set then the getValue method will return the object that has been provided. Typically this will not be set as this represents a reference value.
      Specified by:
      setValue in interface Value
      Parameters:
      value - this is the value to insert as the type
    • getType

      public Class getType()
      This returns the type for the object that this references. This will basically return the getClass class from the referenced instance. This is used to ensure that the type this represents is compatible to the object field.
      Specified by:
      getType in interface Value
      Returns:
      this returns the type for the referenced object
    • getLength

      public int getLength()
      This returns zero as this is a reference and will typically not be used to instantiate anything. If the reference is an an array then this can not be used to instantiate it.
      Specified by:
      getLength in interface Value
      Returns:
      this returns zero regardless of the value type
    • isReference

      public boolean isReference()
      This always returns true for this object. This indicates to the deserialization process that there should be not further deserialization of the object from the XML source stream.
      Specified by:
      isReference in interface Value
      Returns:
      because this is a reference this is always true