Class DetailScanner

  • All Implemented Interfaces:
    Detail

    class DetailScanner
    extends java.lang.Object
    implements Detail
    The DetailScanner is used to scan a class for methods and fields as well as annotations. Scanning a type in this way ensures that all its details can be extracted and cached in one place. This greatly improves performance on platforms that do not cache reflection well, like Android.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private DefaultType access
      This represents the default access type declared or the type.
      private NamespaceList declaration
      This represents the namespace list declared on the type.
      private java.util.List<FieldDetail> fields
      This contains a list of fields that are extracted for this.
      private java.lang.annotation.Annotation[] labels
      This represents all the annotations declared for the type.
      private java.util.List<MethodDetail> methods
      This contains a list of methods that are extracted for this.
      private java.lang.String name
      This represents the name of the type used for XML elements.
      private Namespace namespace
      This represents the namespace annotation declared on the type.
      private Order order
      This is the order annotation that is declared for the type.
      private DefaultType override
      This represents the access type override declared or the type.
      private boolean required
      This is used to determine if the default type is required.
      private Root root
      This is the root annotation that is declared for the type.
      private boolean strict
      This is used to determine if strict XML parsing is done.
      private java.lang.Class type
      This is the type that is represented by this instance.
    • Constructor Summary

      Constructors 
      Constructor Description
      DetailScanner​(java.lang.Class type)
      Constructor for the DetailScanner object.
      DetailScanner​(java.lang.Class type, DefaultType override)
      Constructor for the DetailScanner object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void access​(java.lang.annotation.Annotation label)
      This is used to set the optional Default annotation for the class.
      private void extract​(java.lang.Class type)
      This method is used to extract the annotations associated with the type.
      private void fields​(java.lang.Class type)
      This is used to scan the type for its declared fields.
      DefaultType getAccess()
      This returns the Default annotation access type that has been specified by this.
      java.lang.annotation.Annotation[] getAnnotations()
      This returns the annotations that have been declared for this type.
      java.lang.reflect.Constructor[] getConstructors()
      This returns the constructors that have been declared for this type.
      java.util.List<FieldDetail> getFields()
      This returns a list of the fields that belong to this type.
      java.util.List<MethodDetail> getMethods()
      This returns a list of the methods that belong to this type.
      java.lang.String getName()
      This returns the name of the class processed by this scanner.
      Namespace getNamespace()
      This returns the Namespace annotation that was declared on the type.
      NamespaceList getNamespaceList()
      This returns the NamespaceList annotation that was declared on the type.
      Order getOrder()
      This returns the order annotation used to determine the order of serialization of attributes and elements.
      DefaultType getOverride()
      This returns the DefaultType override used for this detail.
      Root getRoot()
      This returns the Root annotation for the class.
      java.lang.Class getSuper()
      This is used to acquire the super type for the class that is represented by this detail.
      java.lang.Class getType()
      This returns the type represented by this detail.
      private boolean isEmpty​(java.lang.String value)
      This method is used to determine if a root annotation value is an empty value.
      boolean isInstantiable()
      This is used to determine if the class is an inner class.
      boolean isPrimitive()
      This is used to determine whether this detail represents a primitive type.
      boolean isRequired()
      This is used to determine if the generated annotations are required or not.
      boolean isStrict()
      This method is used to determine whether strict mappings are required.
      private void methods​(java.lang.Class type)
      This is used to scan the type for its declared methods.
      private void namespace​(java.lang.annotation.Annotation label)
      This is use to scan for Namespace annotations on the class.
      private void order​(java.lang.annotation.Annotation label)
      This is used to set the optional Order annotation for the class.
      private void root​(java.lang.annotation.Annotation label)
      This is used to set the optional Root annotation for the class.
      private void scan​(java.lang.Class type)
      This method is used to scan the type for all of its annotations as well as its methods and fields.
      private void scope​(java.lang.annotation.Annotation label)
      This is use to scan for NamespaceList annotations on the class.
      java.lang.String toString()
      This is used to return a string representation of the detail.
      • Methods inherited from class java.lang.Object

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

      • methods

        private java.util.List<MethodDetail> methods
        This contains a list of methods that are extracted for this.
      • fields

        private java.util.List<FieldDetail> fields
        This contains a list of fields that are extracted for this.
      • declaration

        private NamespaceList declaration
        This represents the namespace list declared on the type.
      • namespace

        private Namespace namespace
        This represents the namespace annotation declared on the type.
      • labels

        private java.lang.annotation.Annotation[] labels
        This represents all the annotations declared for the type.
      • override

        private DefaultType override
        This represents the access type override declared or the type.
      • access

        private DefaultType access
        This represents the default access type declared or the type.
      • order

        private Order order
        This is the order annotation that is declared for the type.
      • root

        private Root root
        This is the root annotation that is declared for the type.
      • type

        private java.lang.Class type
        This is the type that is represented by this instance.
      • name

        private java.lang.String name
        This represents the name of the type used for XML elements.
      • required

        private boolean required
        This is used to determine if the default type is required.
      • strict

        private boolean strict
        This is used to determine if strict XML parsing is done.
    • Constructor Detail

      • DetailScanner

        public DetailScanner​(java.lang.Class type)
        Constructor for the DetailScanner object. This is used to create a detail object from a type. All of the methods fields and annotations are extracted so that they can be used many times over without the need to process them again.
        Parameters:
        type - this is the type to scan for various details
      • DetailScanner

        public DetailScanner​(java.lang.Class type,
                             DefaultType override)
        Constructor for the DetailScanner object. This is used to create a detail object from a type. All of the methods fields and annotations are extracted so that they can be used many times over without the need to process them again.
        Parameters:
        type - this is the type to scan for various details
        override - this is the override used for this detail
    • Method Detail

      • isRequired

        public boolean isRequired()
        This is used to determine if the generated annotations are required or not. By default generated parameters are required. Setting this to false means that null values are accepted by all defaulted fields or methods depending on the type.
        Specified by:
        isRequired in interface Detail
        Returns:
        this is used to determine if defaults are required
      • isStrict

        public boolean isStrict()
        This method is used to determine whether strict mappings are required. Strict mapping means that all labels in the class schema must match the XML elements and attributes in the source XML document. When strict mapping is disabled, then XML elements and attributes that do not exist in the schema class will be ignored without breaking the parser.
        Specified by:
        isStrict in interface Detail
        Returns:
        true if strict parsing is enabled, false otherwise
      • isPrimitive

        public boolean isPrimitive()
        This is used to determine whether this detail represents a primitive type. A primitive type is any type that does not extend Object, examples are int, long and double.
        Specified by:
        isPrimitive in interface Detail
        Returns:
        this returns true if no XML annotations were found
      • isInstantiable

        public boolean isInstantiable()
        This is used to determine if the class is an inner class. If the class is a inner class and not static then this returns false. Only static inner classes can be instantiated using reflection as they do not require a "this" argument.
        Specified by:
        isInstantiable in interface Detail
        Returns:
        this returns true if the class is a static inner
      • getRoot

        public Root getRoot()
        This returns the Root annotation for the class. The root determines the type of deserialization that is to be performed and also contains the name of the root element.
        Specified by:
        getRoot in interface Detail
        Returns:
        this returns the name of the object being scanned
      • getName

        public java.lang.String getName()
        This returns the name of the class processed by this scanner. The name is either the name as specified in the last found Root annotation, or if a name was not specified within the discovered root then the Java Bean class name of the last class annotated with a root annotation.
        Specified by:
        getName in interface Detail
        Returns:
        this returns the name of the object being scanned
      • getType

        public java.lang.Class getType()
        This returns the type represented by this detail. The type is the class that has been scanned for annotations, methods and fields. All super types of this are represented in the detail.
        Specified by:
        getType in interface Detail
        Returns:
        the type that this detail object represents
      • getOrder

        public Order getOrder()
        This returns the order annotation used to determine the order of serialization of attributes and elements. The order is a class level annotation that can be used only once per class XML schema. If none exists then this will return null. of the class processed by this scanner.
        Specified by:
        getOrder in interface Detail
        Returns:
        this returns the name of the object being scanned
      • getOverride

        public DefaultType getOverride()
        This returns the DefaultType override used for this detail. An override is used only when the class contains no annotations and does not have a Transform of any type associated with it. It allows serialization of external objects without the need to annotate the types.
        Specified by:
        getOverride in interface Detail
        Returns:
        this returns the access type override for this type
      • getAccess

        public DefaultType getAccess()
        This returns the Default annotation access type that has been specified by this. If no default annotation has been declared on the type then this will return null.
        Specified by:
        getAccess in interface Detail
        Returns:
        this returns the default access type for this type
      • getNamespace

        public Namespace getNamespace()
        This returns the Namespace annotation that was declared on the type. If no annotation has been declared on the type this will return null as not belonging to any.
        Specified by:
        getNamespace in interface Detail
        Returns:
        this returns the namespace this type belongs to, if any
      • getNamespaceList

        public NamespaceList getNamespaceList()
        This returns the NamespaceList annotation that was declared on the type. A list of namespaces are used to simply declare the namespaces without specifically making the type belong to any of the declared namespaces.
        Specified by:
        getNamespaceList in interface Detail
        Returns:
        this returns the namespace declarations, if any
      • getMethods

        public java.util.List<MethodDetail> getMethods()
        This returns a list of the methods that belong to this type. The methods here do not include any methods from the super types and simply provides a means of caching method data.
        Specified by:
        getMethods in interface Detail
        Returns:
        returns the list of methods declared for the type
      • getFields

        public java.util.List<FieldDetail> getFields()
        This returns a list of the fields that belong to this type. The fields here do not include any fields from the super types and simply provides a means of caching method data.
        Specified by:
        getFields in interface Detail
        Returns:
        returns the list of fields declared for the type
      • getAnnotations

        public java.lang.annotation.Annotation[] getAnnotations()
        This returns the annotations that have been declared for this type. It is preferable to acquire the declared annotations from this method as they are cached. Older versions of some runtime environments, particularly Android, are slow at this.
        Specified by:
        getAnnotations in interface Detail
        Returns:
        this returns the annotations associated with this
      • getConstructors

        public java.lang.reflect.Constructor[] getConstructors()
        This returns the constructors that have been declared for this type. It is preferable to acquire the declared constructors from this method as they are cached. Older versions of some runtime environments, particularly Android, are slow at this.
        Specified by:
        getConstructors in interface Detail
        Returns:
        this returns the constructors associated with this
      • getSuper

        public java.lang.Class getSuper()
        This is used to acquire the super type for the class that is represented by this detail. If the super type for the class is Object then this will return null.
        Specified by:
        getSuper in interface Detail
        Returns:
        returns the super type for this class or null
      • scan

        private void scan​(java.lang.Class type)
        This method is used to scan the type for all of its annotations as well as its methods and fields. Everything that is scanned is cached within the instance to ensure that it can be reused when ever an object of this type is to be scanned.
        Parameters:
        type - this is the type to scan for details
      • extract

        private void extract​(java.lang.Class type)
        This method is used to extract the annotations associated with the type. Annotations extracted include the Root annotation and the Namespace annotation as well as other annotations that are used to describe the type.
        Parameters:
        type - this is the type to extract the annotations from
      • methods

        private void methods​(java.lang.Class type)
        This is used to scan the type for its declared methods. Scanning of the methods in this way allows the detail to prepare a cache that can be used to acquire the methods and the associated annotations. This improves performance on some platforms.
        Parameters:
        type - this is the type to scan for declared annotations
      • fields

        private void fields​(java.lang.Class type)
        This is used to scan the type for its declared fields. Scanning of the fields in this way allows the detail to prepare a cache that can be used to acquire the fields and the associated annotations. This improves performance on some platforms.
        Parameters:
        type - this is the type to scan for declared annotations
      • root

        private void root​(java.lang.annotation.Annotation label)
        This is used to set the optional Root annotation for the class. The root can only be set once, so if a super type also has a root annotation define it must be ignored.
        Parameters:
        label - this is the label used to define the root
      • isEmpty

        private boolean isEmpty​(java.lang.String value)
        This method is used to determine if a root annotation value is an empty value. Rather than determining if a string is empty be comparing it to an empty string this method allows for the value an empty string represents to be changed in future.
        Parameters:
        value - this is the value to determine if it is empty
        Returns:
        true if the string value specified is an empty value
      • order

        private void order​(java.lang.annotation.Annotation label)
        This is used to set the optional Order annotation for the class. The order can only be set once, so if a super type also has a order annotation define it must be ignored.
        Parameters:
        label - this is the label used to define the order
      • access

        private void access​(java.lang.annotation.Annotation label)
        This is used to set the optional Default annotation for the class. The default can only be set once, so if a super type also has a default annotation define it must be ignored.
        Parameters:
        label - this is the label used to define the defaults
      • namespace

        private void namespace​(java.lang.annotation.Annotation label)
        This is use to scan for Namespace annotations on the class. Once a namespace has been located then it is used to populate the internal namespace decorator. This can then be used to decorate any output node that requires it.
        Parameters:
        label - the XML annotation to scan for the namespace
      • scope

        private void scope​(java.lang.annotation.Annotation label)
        This is use to scan for NamespaceList annotations on the class. Once a namespace list has been located then it is used to populate the internal namespace decorator. This can then be used to decorate any output node that requires it.
        Parameters:
        label - the XML annotation to scan for namespace lists
      • toString

        public java.lang.String toString()
        This is used to return a string representation of the detail. The string returned from this is the same that is returned from the toString of the type represented.
        Overrides:
        toString in class java.lang.Object
        Returns:
        this returns the string representation of the type