Package org.simpleframework.xml.core
Class SignatureCreator
java.lang.Object
org.simpleframework.xml.core.SignatureCreator
- All Implemented Interfaces:
Creator
The
Instantiator
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 a Criteria
object. This allows
the deserialization process to find the most suitable one to
use when instantiating an object.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSignatureCreator
(Signature signature) Constructor for theInstantiator
object. -
Method Summary
Modifier and TypeMethodDescriptionprivate 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 is used to instantiate the object using the default no argument constructor.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
This is used to score thisInstantiator
object so that it can be weighed amongst other constructors.This is the signature associated with the creator.getType()
This is the type associated with theCreator
object.private Object
getVariable
(Criteria criteria, int index) This is used to acquire a variable from the criteria provided.toString()
This is used to acquire a descriptive name for the instantiator.
-
Field Details
-
list
This is the list of parameters in the order of declaration. -
signature
This is the map that contains the parameters to be used. -
type
This is the type represented by the creator instance.
-
-
Constructor Details
-
SignatureCreator
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 Details
-
getType
This is the type associated with theCreator
object. All instances returned from this creator will be of this type. -
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
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:
Exception
-
getInstance
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:
Exception
-
getVariable
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:
Exception
-
getScore
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
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:
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
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.
-