Class InstantiatorBuilder

java.lang.Object
org.simpleframework.xml.core.InstantiatorBuilder

class InstantiatorBuilder extends Object
The InstantiatorBuilder object is used to resolve labels based on a provided parameter. Resolution of labels is done using a set of mappings based on the names of the labels. Because many labels might have the same name, this will only map a label if it has unique name. As well as resolving by name, this can resolve using the path of the parameter.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private LabelMap
    This is used to maintain the mappings for the attribute labels.
    private Comparer
    This is used for validation to compare annotations used.
    private Detail
    This is the detail the instantiator uses to create objects.
    private LabelMap
    This is used to maintain the mappings for the element labels.
    private Instantiator
    This is the single instance of the instantiator to be built.
    private List<Creator>
    This is the list of creators representing an object constructor.
    private Scanner
    This is used to acquire the signatures created for the type.
    private LabelMap
    This is used to maintain the mappings for the text labels.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    This is used to build the Instantiator object that will be used to instantiate objects.
    private Instantiator
    build(Detail detail)
    This is used to build the Instantiator object that will be used to instantiate objects.
    private boolean
    contains(String[] list, String value)
    This is used to determine if a value exists within an array.
    private Instantiator
    create(Detail detail)
    This is used to create the Instantiator object that will be used to instantiate objects.
    private Parameter
    create(Parameter original)
    This is used to create a Parameter based on the currently registered labels.
    private Creator
    create(Signature signature)
    This is used to create a new Creator object from the provided signature.
    private void
    populate(Detail detail)
    This used to populate replace the parameters extracted from the scanning process with ones matched with registered labels.
    private void
    populate(Signature signature)
    This used to populate replace the parameters extracted from the scanning process with ones matched with registered labels.
    void
    register(Label label)
    This register method is used to register a label based on its name and path.
    private void
    register(Label label, LabelMap map)
    This register method is used to register a label based on its name and path.
    private Label
    resolve(Parameter parameter)
    This resolve method is used to find a label based on the name and path of the provided parameter.
    private Label
    resolve(Parameter parameter, LabelMap map)
    This resolve method is used to find a label based on the name and path of the provided parameter.
    private void
    validate(Detail detail)
    This is used to ensure that for each parameter in the builder there is a matching method or field.
    private void
    validateAnnotations(Label label, Parameter parameter)
    This is used to validate the annotations associated with a field and a matching constructor parameter.
    private void
    This is used to ensure that final methods and fields have a constructor parameter that allows the value to be injected in to.
    private void
    This is used to ensure that final methods and fields have a constructor parameter that allows the value to be injected in to.
    private void
    This is used when there are only default constructors.
    private void
    This is used to ensure that final methods and fields have a constructor parameter that allows the value to be injected in to.
    private void
    validateNames(Label label, Parameter parameter)
    This is used to validate the names associated with the parameters.
    private void
    validateParameter(Label label, Parameter parameter)
    This is used to validate the Parameter object that exist in the constructors.

    Methods inherited from class java.lang.Object

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

    • options

      private List<Creator> options
      This is the list of creators representing an object constructor.
    • factory

      private Instantiator factory
      This is the single instance of the instantiator to be built.
    • attributes

      private LabelMap attributes
      This is used to maintain the mappings for the attribute labels.
    • elements

      private LabelMap elements
      This is used to maintain the mappings for the element labels.
    • texts

      private LabelMap texts
      This is used to maintain the mappings for the text labels.
    • comparer

      private Comparer comparer
      This is used for validation to compare annotations used.
    • scanner

      private Scanner scanner
      This is used to acquire the signatures created for the type.
    • detail

      private Detail detail
      This is the detail the instantiator uses to create objects.
  • Constructor Details

    • InstantiatorBuilder

      public InstantiatorBuilder(Scanner scanner, Detail detail)
      Constructor for the InstantiatorBuilder object. This is used to create an object that can resolve a label using a parameter. Resolution is performed using either the name of the parameter or the path of the parameter.
      Parameters:
      scanner - this is the scanner to acquire signatures from
      detail - contains the details instantiators are built with
  • Method Details

    • build

      public Instantiator build() throws Exception
      This is used to build the Instantiator object that will be used to instantiate objects. Validation is performed on all of the parameters as well as the Creator objects associated with the type. This validation ensures that the labels and constructor parameters match based on annotations.
      Returns:
      this returns the instance that has been built
      Throws:
      Exception
    • build

      private Instantiator build(Detail detail) throws Exception
      This is used to build the Instantiator object that will be used to instantiate objects. Validation is performed on all of the parameters as well as the Creator objects associated with the type. This validation ensures that the labels and constructor parameters match based on annotations.
      Parameters:
      detail - contains the details instantiators are built with
      Throws:
      Exception
    • create

      private Instantiator create(Detail detail) throws Exception
      This is used to create the Instantiator object that will be used to instantiate objects. Validation is performed on all of the parameters as well as the Creator objects associated with the type. This validation ensures that the labels and constructor parameters match based on annotations.
      Parameters:
      detail - contains the details instantiators are built with
      Returns:
      this returns the instance that has been created
      Throws:
      Exception
    • create

      private Creator create(Signature signature)
      This is used to create a new Creator object from the provided signature. Once created the instance is added to the list of available creators which can be used to instantiate an object instance.
      Parameters:
      signature - this is the signature that is to be used
      Returns:
      this returns the creator associated with this builder
    • create

      private Parameter create(Parameter original) throws Exception
      This is used to create a Parameter based on the currently registered labels. Creating a replacement in this way ensures that all parameters are keyed in the exact same way that the label is, making it easier and quicker to match them.
      Parameters:
      original - this is the original parameter to replace
      Returns:
      this returns the replacement parameter object
      Throws:
      Exception
    • populate

      private void populate(Detail detail) throws Exception
      This used to populate replace the parameters extracted from the scanning process with ones matched with registered labels. By replacing parameters in this way the parameters can be better matched with the associated labels using the label keys.
      Parameters:
      detail - contains the details instantiators are built with
      Throws:
      Exception
    • populate

      private void populate(Signature signature) throws Exception
      This used to populate replace the parameters extracted from the scanning process with ones matched with registered labels. By replacing parameters in this way the parameters can be better matched with the associated labels using the label keys.
      Parameters:
      signature - this is the signature used for a creator
      Throws:
      Exception
    • validate

      private void validate(Detail detail) throws Exception
      This is used to ensure that for each parameter in the builder there is a matching method or field. This ensures that the class schema is fully readable and writable. If not method or field annotation exists for the parameter validation fails.
      Parameters:
      detail - contains the details instantiators are built with
      Throws:
      Exception
    • validateParameter

      private void validateParameter(Label label, Parameter parameter) throws Exception
      This is used to validate the Parameter object that exist in the constructors. Validation is performed against the annotated methods and fields to ensure that they match up.
      Parameters:
      label - this is the annotated method or field to validate
      parameter - this is the parameter to validate with
      Throws:
      Exception
    • validateNames

      private void validateNames(Label label, Parameter parameter) throws Exception
      This is used to validate the names associated with the parameters. Validation is performed by checking that the parameter name is present in the list of names the label is known by. This is used to ensure that the if the label is a union the parameter is one of the names declared within the union.
      Parameters:
      label - this is the label to validate the parameter against
      parameter - this is the parameter that is to be validated
      Throws:
      Exception
    • validateAnnotations

      private void validateAnnotations(Label label, Parameter parameter) throws Exception
      This is used to validate the annotations associated with a field and a matching constructor parameter. Each constructor parameter paired with an annotated field or method must be the same annotation type and must also contain the same name.
      Parameters:
      label - this is the label associated with the parameter
      parameter - this is the constructor parameter to use
      Throws:
      Exception
    • validateConstructors

      private void validateConstructors() throws Exception
      This is used to ensure that final methods and fields have a constructor parameter that allows the value to be injected in to. Validating the constructor in this manner ensures that the class schema remains fully serializable and deserializable.
      Throws:
      Exception
    • validateConstructors

      private void validateConstructors(LabelMap map) throws Exception
      This is used when there are only default constructors. It will check to see if any of the annotated fields or methods is read only. If a read only method or field is found then this will throw an exception to indicate that it is not valid.
      Parameters:
      map - this is the map of values that is to be validated
      Throws:
      Exception
    • validateConstructors

      private void validateConstructors(LabelMap map, List<Creator> list) throws Exception
      This is used to ensure that final methods and fields have a constructor parameter that allows the value to be injected in to. Validating the constructor in this manner ensures that the class schema remains fully serializable and deserializable.
      Parameters:
      map - this is the map that contains the labels to validate
      list - this is the list of builders to validate
      Throws:
      Exception
    • validateConstructor

      private void validateConstructor(Label label, List<Creator> list) throws Exception
      This is used to ensure that final methods and fields have a constructor parameter that allows the value to be injected in to. Validating the constructor in this manner ensures that the class schema remains fully serializable and deserializable.
      Parameters:
      label - this is the variable to check in constructors
      list - this is the list of builders to validate
      Throws:
      Exception
    • register

      public void register(Label label) throws Exception
      This register method is used to register a label based on its name and path. Registration like this is done to ensure that the label can be resolved based on a parameter name or path.
      Parameters:
      label - this is the label that is to be registered
      Throws:
      Exception
    • register

      private void register(Label label, LabelMap map) throws Exception
      This register method is used to register a label based on its name and path. Registration like this is done to ensure that the label can be resolved based on a parameter name or path.

      Registration here ensures a parameter can be resolved on both name and path. However, because we want these mappings to be unique we do not allow multiple names to be mapped to the same label. For example, say we have 'x/@a' and 'y/@a', these both have the same name 'a' even though the point/put( to different things. Here we would not allow a mapping from 'a' and keep only mappings based on the full path. This means that any parameters specified must declare the full path also.

      Parameters:
      label - this is the label that is to be registered
      map - this is the map that the label is registered with
      Throws:
      Exception
    • resolve

      private Label resolve(Parameter parameter) throws Exception
      This resolve method is used to find a label based on the name and path of the provided parameter. If it can not be found then this will return null.
      Parameters:
      parameter - this is the parameter used for resolution
      Returns:
      the label that has been resolved, or null
      Throws:
      Exception
    • resolve

      private Label resolve(Parameter parameter, LabelMap map) throws Exception
      This resolve method is used to find a label based on the name and path of the provided parameter. If it can not be found then this will return null.
      Parameters:
      parameter - this is the parameter used for resolution
      map - this is the map that is used for resolution
      Returns:
      the label that has been resolved, or null
      Throws:
      Exception
    • contains

      private boolean contains(String[] list, String value) throws Exception
      This is used to determine if a value exists within an array. Searching the array like this is required when no collections are available to use on the list of attributes.
      Parameters:
      list - this is the list to begin searching for a value
      value - this is the value to be searched for
      Returns:
      true if the list contains the specified value
      Throws:
      Exception