Package org.simpleframework.xml.core
Class SignatureCreator
- java.lang.Object
-
- org.simpleframework.xml.core.SignatureCreator
-
- All Implemented Interfaces:
Creator
class SignatureCreator extends java.lang.Object implements Creator
TheInstantiatorobject is used to represent an single constructor within an object. It contains the actual constructor as well as the list of parameters. Each instantiator will score its weight when given aCriteriaobject. This allows the deserialization process to find the most suitable one to use when instantiating an object.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Parameter>listThis is the list of parameters in the order of declaration.private SignaturesignatureThis is the map that contains the parameters to be used.private java.lang.ClasstypeThis is the type represented by the creator instance.
-
Constructor Summary
Constructors Constructor Description SignatureCreator(Signature signature)Constructor for theInstantiatorobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private doublegetAdjustment(double score)This will use a slight adjustment to ensure that if there are many constructors with a 100% match on parameters, the one with the most values to be injected wins.java.lang.ObjectgetInstance()This is used to instantiate the object using the default no argument constructor.java.lang.ObjectgetInstance(Criteria criteria)This is used to instantiate the object using a constructor that takes deserialized objects as arguments.private doublegetPercentage(Criteria criteria)This is used to determine what percentage of available values can be injected in to a constructor.doublegetScore(Criteria criteria)This is used to score thisInstantiatorobject so that it can be weighed amongst other constructors.SignaturegetSignature()This is the signature associated with the creator.java.lang.ClassgetType()This is the type associated with theCreatorobject.private java.lang.ObjectgetVariable(Criteria criteria, int index)This is used to acquire a variable from the criteria provided.java.lang.StringtoString()This is used to acquire a descriptive name for the instantiator.
-
-
-
Field Detail
-
list
private final java.util.List<Parameter> list
This is the list of parameters in the order of declaration.
-
signature
private final Signature signature
This is the map that contains the parameters to be used.
-
type
private final java.lang.Class type
This is the type represented by the creator instance.
-
-
Constructor Detail
-
SignatureCreator
public SignatureCreator(Signature signature)
Constructor for theInstantiatorobject. This is used to create a factory like object used for instantiating objects. Each instantiator will score its suitability using the parameters it is provided.- Parameters:
signature- this is the signature that contains parameters
-
-
Method Detail
-
getType
public java.lang.Class getType()
This is the type associated with theCreatorobject. All instances returned from this creator will be of this type.
-
getSignature
public Signature getSignature()
This is the signature associated with the creator. The signature contains all the parameters associated with the creator as well as the constructor that this represents. Exposing the signature allows the creator to be validated.- Specified by:
getSignaturein interfaceCreator- Returns:
- this is the signature associated with the creator
-
getInstance
public java.lang.Object getInstance() throws java.lang.ExceptionThis 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:
getInstancein interfaceCreator- 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 theCriteriaobject which contains the deserialized values.- Specified by:
getInstancein interfaceCreator- Parameters:
criteria- this contains the criteria to be used- Returns:
- this returns the object that has been instantiated
- Throws:
java.lang.Exception
-
getVariable
private java.lang.Object getVariable(Criteria criteria, int index) throws java.lang.Exception
This is used to acquire a variable from the criteria provided. In order to match the constructor correctly this will check to see if the if the parameter is required. If it is required then there must be a non null value or an exception is thrown.- Parameters:
criteria- this is used to acquire the parameter valueindex- this is the index to acquire the value for- Returns:
- the value associated with the specified parameter
- Throws:
java.lang.Exception
-
getScore
public double getScore(Criteria criteria) throws java.lang.Exception
This is used to score thisInstantiatorobject so that it can be weighed amongst other constructors. The instantiator that scores the highest is the one that is used for instantiation.If any read only element or attribute is not a parameter in the constructor then the constructor is discounted. This is because there is no way to set the read only entity without a constructor injection in to the instantiated object.
-
getPercentage
private double getPercentage(Criteria criteria) throws java.lang.Exception
This is used to determine what percentage of available values can be injected in to a constructor. Calculating the percentage in this manner ensures that the best possible fit will be used to construct the object. This also allows the object to define what defaults it wishes to set for the values.This will use a slight adjustment to ensure that if there are many constructors with a 100% match on parameters, the one with the most values to be injected wins. This ensures the most desirable constructor is chosen each time.
- Parameters:
criteria- this is the criteria object containing values- Returns:
- this returns the percentage match for the values
- Throws:
java.lang.Exception
-
getAdjustment
private double getAdjustment(double score)
This will use a slight adjustment to ensure that if there are many constructors with a 100% match on parameters, the one with the most values to be injected wins. This ensures the most desirable constructor is chosen each time.- Parameters:
score- this is the score from the parameter matching- Returns:
- an adjusted score to account for the signature size
-
toString
public java.lang.String toString()
This is used to acquire a descriptive name for the instantiator. Providing a name is useful in debugging and when exceptions are thrown as it describes the constructor the instantiator represents.- Overrides:
toStringin classjava.lang.Object- Returns:
- this returns the name of the constructor to be used
-
-