Package org.simpleframework.xml.core
Class ClassInstantiator
- java.lang.Object
-
- org.simpleframework.xml.core.ClassInstantiator
-
- All Implemented Interfaces:
Instantiator
class ClassInstantiator extends java.lang.Object implements Instantiator
TheClassInstantiator
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 Summary
Fields Modifier and Type Field Description private java.util.List<Creator>
creators
This contains a list of all the creators for the class.private Detail
detail
This contains the details for the class to instantiate.private Creator
primary
This represents the default no argument constructor used.private ParameterMap
registry
This is used to acquire a parameter by the parameter name.
-
Constructor Summary
Constructors Constructor Description ClassInstantiator(java.util.List<Creator> creators, Creator primary, ParameterMap registry, Detail detail)
Constructor for theClassCreator
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Creator
getCreator(Criteria criteria)
This is used to acquire anInstantiator
which is used to instantiate the object.java.util.List<Creator>
getCreators()
This is used to acquire all of theInstantiator
objects used to create an instance of the object.java.lang.Object
getInstance()
This is used to instantiate the object using the default no argument constructor.java.lang.Object
getInstance(Criteria criteria)
This is used to instantiate the object using a constructor that takes deserialized objects as arguments.Parameter
getParameter(java.lang.String name)
This is used to acquire the namedParameter
from the creator.java.util.List<Parameter>
getParameters()
This is used to acquire all parameters annotated for the class schema.boolean
isDefault()
This is used to determine if thisCreator
has a default constructor.java.lang.String
toString()
This is used to acquire a description of the creator.
-
-
-
Field Detail
-
creators
private final java.util.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 Detail
-
ClassInstantiator
public ClassInstantiator(java.util.List<Creator> creators, Creator primary, ParameterMap registry, Detail detail)
Constructor for theClassCreator
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 availableprimary
- this is the default no argument constructorregistry
- contains all parameters for the constructorsdetail
- contains the details for the instantiated class
-
-
Method Detail
-
isDefault
public boolean isDefault()
This is used to determine if thisCreator
has a default constructor. If the class does contain a no argument constructor then this will return true.- Specified by:
isDefault
in interfaceInstantiator
- Returns:
- true if the class has a default constructor
-
getInstance
public java.lang.Object getInstance() throws java.lang.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 interfaceInstantiator
- Returns:
- this returns the object that has been instantiated
- Throws:
java.lang.Exception
-
getInstance
public java.lang.Object getInstance(Criteria criteria) throws java.lang.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 theCriteria
object which contains the deserialized values.- Specified by:
getInstance
in interfaceInstantiator
- Parameters:
criteria
- this contains the criteria to be used- Returns:
- this returns the object that has been instantiated
- Throws:
java.lang.Exception
-
getCreator
private Creator getCreator(Criteria criteria) throws java.lang.Exception
This is used to acquire anInstantiator
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:
java.lang.Exception
-
getParameter
public Parameter getParameter(java.lang.String name)
This is used to acquire the namedParameter
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 interfaceInstantiator
- Parameters:
name
- this is the name of the parameter to be acquired- Returns:
- this returns the named parameter for the creator
-
getParameters
public java.util.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 interfaceInstantiator
- Returns:
- this returns the parameters declared in the schema
-
getCreators
public java.util.List<Creator> getCreators()
This is used to acquire all of theInstantiator
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 interfaceInstantiator
- Returns:
- this returns a list of instantiators for the creator
-
toString
public java.lang.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 classjava.lang.Object
- Returns:
- this returns a visible description of the creator
-
-