Class ClassInstantiator

java.lang.Object
org.simpleframework.xml.core.ClassInstantiator
All Implemented Interfaces:
Instantiator

class ClassInstantiator extends Object implements Instantiator
The ClassInstantiator is used for instantiating objects using either the default no argument constructor or one that takes deserialized values as parameters. This also exposes the parameters and constructors used to instantiate the object.
  • Field Details

    • creators

      private final List<Creator> creators
      This contains a list of all the creators for the class.
    • registry

      private final ParameterMap registry
      This is used to acquire a parameter by the parameter name.
    • primary

      private final Creator primary
      This represents the default no argument constructor used.
    • detail

      private final Detail detail
      This contains the details for the class to instantiate.
  • Constructor Details

    • ClassInstantiator

      public ClassInstantiator(List<Creator> creators, Creator primary, ParameterMap registry, Detail detail)
      Constructor for the ClassCreator object. This is used to create an object that contains all information that relates to the construction of an instance.
      Parameters:
      creators - contains the list of all constructors available
      primary - this is the default no argument constructor
      registry - contains all parameters for the constructors
      detail - contains the details for the instantiated class
  • Method Details

    • isDefault

      public boolean isDefault()
      This is used to determine if this Creator has a default constructor. If the class does contain a no argument constructor then this will return true.
      Specified by:
      isDefault in interface Instantiator
      Returns:
      true if the class has a default constructor
    • getInstance

      public Object getInstance() throws Exception
      This is used to instantiate the object using the default no argument constructor. If for some reason the object can not be instantiated then this will throw an exception with the reason.
      Specified by:
      getInstance in interface Instantiator
      Returns:
      this returns the object that has been instantiated
      Throws:
      Exception
    • getInstance

      public Object getInstance(Criteria criteria) throws Exception
      This is used to instantiate the object using a constructor that takes deserialized objects as arguments. The object that have been deserialized can be taken from the Criteria object which contains the deserialized values.
      Specified by:
      getInstance in interface Instantiator
      Parameters:
      criteria - this contains the criteria to be used
      Returns:
      this returns the object that has been instantiated
      Throws:
      Exception
    • getCreator

      private Creator getCreator(Criteria criteria) throws Exception
      This is used to acquire an Instantiator which is used to instantiate the object. If there is no match for the instantiator then the default constructor is provided.
      Parameters:
      criteria - this contains the criteria to be used for this
      Returns:
      this returns the instantiator that has been matched
      Throws:
      Exception
    • getParameter

      public Parameter getParameter(String name)
      This is used to acquire the named Parameter from the creator. A parameter is taken from the constructor which contains annotations for each object that is required. These parameters must have a matching field or method.
      Specified by:
      getParameter in interface Instantiator
      Parameters:
      name - this is the name of the parameter to be acquired
      Returns:
      this returns the named parameter for the creator
    • getParameters

      public List<Parameter> getParameters()
      This is used to acquire all parameters annotated for the class schema. Providing all parameters ensures that they can be validated against the annotated methods and fields to ensure that each parameter is valid and has a corresponding match.
      Specified by:
      getParameters in interface Instantiator
      Returns:
      this returns the parameters declared in the schema
    • getCreators

      public List<Creator> getCreators()
      This is used to acquire all of the Instantiator objects used to create an instance of the object. Each represents a constructor and contains the parameters to the constructor. This is primarily used to validate each constructor against the fields and methods annotated to ensure they are compatible.
      Specified by:
      getCreators in interface Instantiator
      Returns:
      this returns a list of instantiators for the creator
    • toString

      public String toString()
      This is used to acquire a description of the creator. This is useful when debugging an issue as it allows a representation of the instance to be viewed with the class it represents.
      Overrides:
      toString in class Object
      Returns:
      this returns a visible description of the creator