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
TheInstantiator
object 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 aCriteria
object. 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>
list
This is the list of parameters in the order of declaration.private Signature
signature
This is the map that contains the parameters to be used.private java.lang.Class
type
This is the type represented by the creator instance.
-
Constructor Summary
Constructors Constructor Description SignatureCreator(Signature signature)
Constructor for theInstantiator
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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.private double
getPercentage(Criteria criteria)
This is used to determine what percentage of available values can be injected in to a constructor.double
getScore(Criteria criteria)
This is used to score thisInstantiator
object so that it can be weighed amongst other constructors.Signature
getSignature()
This is the signature associated with the creator.java.lang.Class
getType()
This is the type associated with theCreator
object.private java.lang.Object
getVariable(Criteria criteria, int index)
This is used to acquire a variable from the criteria provided.java.lang.String
toString()
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 theInstantiator
object. 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 theCreator
object. 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:
getSignature
in interfaceCreator
- Returns:
- this is the signature associated with the creator
-
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 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 theCriteria
object which contains the deserialized values.- Specified by:
getInstance
in 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 thisInstantiator
object 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:
toString
in classjava.lang.Object
- Returns:
- this returns the name of the constructor to be used
-
-