Class SignatureCreator

java.lang.Object
org.simpleframework.xml.core.SignatureCreator
All Implemented Interfaces:
Creator

class SignatureCreator extends Object implements 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
    Modifier and Type
    Field
    Description
    private final List<Parameter>
    This is the list of parameters in the order of declaration.
    private final Signature
    This is the map that contains the parameters to be used.
    private final Class
    This is the type represented by the creator instance.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the Instantiator object.
  • Method Summary

    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.
    This is used to instantiate the object using the default no argument constructor.
    This is used to instantiate the object using a constructor that takes deserialized objects as arguments.
    private double
    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 this Instantiator object so that it can be weighed amongst other constructors.
    This is the signature associated with the creator.
    This is the type associated with the Creator object.
    private Object
    getVariable(Criteria criteria, int index)
    This is used to acquire a variable from the criteria provided.
    This is used to acquire a descriptive name for the instantiator.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • list

      private final 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 Class type
      This is the type represented by the creator instance.
  • Constructor Details

    • SignatureCreator

      public SignatureCreator(Signature signature)
      Constructor for the Instantiator 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

      public Class getType()
      This is the type associated with the Creator object. All instances returned from this creator will be of this type.
      Specified by:
      getType in interface Creator
      Returns:
      this returns the type associated with this creator
    • 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 interface Creator
      Returns:
      this is the signature associated with the creator
    • 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 Creator
      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 Creator
      Parameters:
      criteria - this contains the criteria to be used
      Returns:
      this returns the object that has been instantiated
      Throws:
      Exception
    • getVariable

      private Object getVariable(Criteria criteria, int index) throws 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 value
      index - this is the index to acquire the value for
      Returns:
      the value associated with the specified parameter
      Throws:
      Exception
    • getScore

      public double getScore(Criteria criteria) throws Exception
      This is used to score this Instantiator 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.

      Specified by:
      getScore in interface Creator
      Parameters:
      criteria - this contains the criteria to be used
      Returns:
      this returns the score based on the criteria provided
      Throws:
      Exception
    • getPercentage

      private double getPercentage(Criteria criteria) throws 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:
      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 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 class Object
      Returns:
      this returns the name of the constructor to be used