Class ArrayFactory


  • class ArrayFactory
    extends Factory
    The ArrayFactory is used to create object array types that are compatible with the field type. This simply requires the type of the array in order to instantiate that array. However, this also performs a check on the field type to ensure that the array component types are compatible.
    • Constructor Detail

      • ArrayFactory

        public ArrayFactory​(Context context,
                            Type type)
        Constructor for the ArrayFactory object. This is given the array component type as taken from the field type of the source object. Each request for an array will return an array which uses a compatible component type.
        Parameters:
        context - this is the context object for serialization
        type - the array component type for the field object
    • Method Detail

      • getInstance

        public java.lang.Object getInstance()
                                     throws java.lang.Exception
        This is used to create a default instance of the field type. It is up to the subclass to determine how to best instantiate an object of the field type that best suits. This is used when the empty value is required or to create the default type instance.
        Overrides:
        getInstance in class Factory
        Returns:
        a type which is used to instantiate the collection
        Throws:
        java.lang.Exception
      • getInstance

        public Instance getInstance​(InputNode node)
                             throws java.lang.Exception
        Creates the array type to use. This will use the provided XML element to determine the array type and provide a means for creating an array with the Value object. If the array size cannot be determined an exception is thrown.
        Parameters:
        node - this is the input node for the array element
        Returns:
        the object array type used for the instantiation
        Throws:
        java.lang.Exception
      • getInstance

        private Instance getInstance​(Value value,
                                     java.lang.Class entry)
                              throws java.lang.Exception
        Creates the array type to use. This will use the provided XML element to determine the array type and provide a means for creating an array with the Value object. If the array types are not compatible an exception is thrown.
        Parameters:
        value - this is the type object with the array details
        entry - this is the entry type for the array instance
        Returns:
        this object array type used for the instantiation
        Throws:
        java.lang.Exception
      • getComponentType

        private java.lang.Class getComponentType()
                                          throws java.lang.Exception
        This is used to extract the component type for the array class this factory represents. This is used when an array is to be instantiated. If the class provided to the factory is not an array then this will throw an exception.
        Returns:
        this returns the component type for the array
        Throws:
        java.lang.Exception