Class InstantiatorBuilder


  • class InstantiatorBuilder
    extends java.lang.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:
    StructureBuilder
    • Field Summary

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

      Constructors 
      Constructor Description
      InstantiatorBuilder​(Scanner scanner, Detail detail)
      Constructor for the InstantiatorBuilder object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Instantiator build()
      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​(java.lang.String[] list, java.lang.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 validateConstructor​(Label label, java.util.List<Creator> list)
      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 validateConstructors()
      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 validateConstructors​(LabelMap map)
      This is used when there are only default constructors.
      private void validateConstructors​(LabelMap map, java.util.List<Creator> list)
      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 Detail

      • options

        private java.util.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 Detail

      • 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 Detail

      • build

        public Instantiator build()
                           throws java.lang.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:
        java.lang.Exception
      • build

        private Instantiator build​(Detail detail)
                            throws java.lang.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:
        java.lang.Exception
      • create

        private Instantiator create​(Detail detail)
                             throws java.lang.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:
        java.lang.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 java.lang.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:
        java.lang.Exception
      • populate

        private void populate​(Detail detail)
                       throws java.lang.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:
        java.lang.Exception
      • populate

        private void populate​(Signature signature)
                       throws java.lang.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:
        java.lang.Exception
      • validate

        private void validate​(Detail detail)
                       throws java.lang.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:
        java.lang.Exception
      • validateParameter

        private void validateParameter​(Label label,
                                       Parameter parameter)
                                throws java.lang.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:
        java.lang.Exception
      • validateNames

        private void validateNames​(Label label,
                                   Parameter parameter)
                            throws java.lang.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:
        java.lang.Exception
      • validateAnnotations

        private void validateAnnotations​(Label label,
                                         Parameter parameter)
                                  throws java.lang.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:
        java.lang.Exception
      • validateConstructors

        private void validateConstructors()
                                   throws java.lang.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:
        java.lang.Exception
      • validateConstructors

        private void validateConstructors​(LabelMap map)
                                   throws java.lang.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:
        java.lang.Exception
      • validateConstructors

        private void validateConstructors​(LabelMap map,
                                          java.util.List<Creator> list)
                                   throws java.lang.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:
        java.lang.Exception
      • validateConstructor

        private void validateConstructor​(Label label,
                                         java.util.List<Creator> list)
                                  throws java.lang.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:
        java.lang.Exception
      • register

        public void register​(Label label)
                      throws java.lang.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:
        java.lang.Exception
      • register

        private void register​(Label label,
                              LabelMap map)
                       throws java.lang.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:
        java.lang.Exception
      • resolve

        private Label resolve​(Parameter parameter)
                       throws java.lang.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:
        java.lang.Exception
      • resolve

        private Label resolve​(Parameter parameter,
                              LabelMap map)
                       throws java.lang.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:
        java.lang.Exception
      • contains

        private boolean contains​(java.lang.String[] list,
                                 java.lang.String value)
                          throws java.lang.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:
        java.lang.Exception