Class FieldContact

  • All Implemented Interfaces:
    Contact, Type

    class FieldContact
    extends java.lang.Object
    implements Contact
    The FieldContact object is used to act as a contact for a field within an object. This allows a value to be set on an object field during deserialization and acquired from the same field during serialization.
    See Also:
    FieldScanner
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Cache<java.lang.annotation.Annotation> cache
      This cache contains the annotations present on the field.
      private java.lang.reflect.Field field
      This represents the field within the schema class object.
      private java.lang.annotation.Annotation label
      This is the label that marks the field within the object.
      private java.lang.annotation.Annotation[] list
      This is the list of annotations associated with the field.
      private int modifier
      This is the modifiers for the field that this represents.
      private java.lang.String name
      This is the name for this contact as taken from the field.
    • Constructor Summary

      Constructors 
      Constructor Description
      FieldContact​(java.lang.reflect.Field field, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list)
      Constructor for the FieldContact object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object get​(java.lang.Object source)
      This is used to get the specified value on the provided object.
      java.lang.annotation.Annotation getAnnotation()
      This is the annotation associated with the point of contact.
      <T extends java.lang.annotation.Annotation>
      T
      getAnnotation​(java.lang.Class<T> type)
      This is the annotation associated with the point of contact.
      private <T extends java.lang.annotation.Annotation>
      T
      getCache​(java.lang.Class<T> type)
      This is the annotation associated with the point of contact.
      java.lang.Class getDeclaringClass()
      This is the class that declares the contact.
      java.lang.Class getDependent()
      This provides the dependent class for the contact.
      java.lang.Class[] getDependents()
      This provides the dependent classes for the contact.
      java.lang.String getName()
      This is used to acquire the name of the field.
      java.lang.Class getType()
      This will provide the contact type.
      boolean isFinal()
      This is used to identify annotated methods are fields that can not be modified.
      boolean isReadOnly()
      This is used to determine if the annotated contact is for a read only variable.
      boolean isStatic()
      This is used to determine if the annotated contact is for a static field or method.
      void set​(java.lang.Object source, java.lang.Object value)
      This is used to set the specified value on the provided object.
      java.lang.String toString()
      This is used to describe the contact as it exists within the owning class.
      • Methods inherited from class java.lang.Object

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

      • cache

        private final Cache<java.lang.annotation.Annotation> cache
        This cache contains the annotations present on the field.
      • list

        private final java.lang.annotation.Annotation[] list
        This is the list of annotations associated with the field.
      • label

        private final java.lang.annotation.Annotation label
        This is the label that marks the field within the object.
      • field

        private final java.lang.reflect.Field field
        This represents the field within the schema class object.
      • name

        private final java.lang.String name
        This is the name for this contact as taken from the field.
      • modifier

        private final int modifier
        This is the modifiers for the field that this represents.
    • Constructor Detail

      • FieldContact

        public FieldContact​(java.lang.reflect.Field field,
                            java.lang.annotation.Annotation label,
                            java.lang.annotation.Annotation[] list)
        Constructor for the FieldContact object. This is used as a point of contact for a field within a schema class. Values can be read and written directly to the field with this.
        Parameters:
        field - this is the field that is the point of contact
        label - this is the annotation that is used by the field
        list - this is the list of annotations on the field
    • Method Detail

      • isReadOnly

        public boolean isReadOnly()
        This is used to determine if the annotated contact is for a read only variable. A read only variable is a field that can be set from within the constructor such as a blank final variable. It can also be a method with no set counterpart.
        Specified by:
        isReadOnly in interface Contact
        Returns:
        this returns true if the contact is a constant one
      • isStatic

        public boolean isStatic()
        This is used to determine if the annotated contact is for a static field or method. A static field or method is one that contains the "static" keyword. Any static final fields will be read only and does not require any matching annotation.
        Returns:
        this returns true if the contact is a static one
      • isFinal

        public boolean isFinal()
        This is used to identify annotated methods are fields that can not be modified. Such field will require that there is a constructor that can have the value injected in to it.
        Returns:
        this returns true if the field or method is final
      • getType

        public java.lang.Class getType()
        This will provide the contact type. The contact type is the class that is to be set and get on the object. This represents the return type for the get and the parameter for the set.
        Specified by:
        getType in interface Type
        Returns:
        this returns the type that this contact represents
      • getDependent

        public java.lang.Class getDependent()
        This provides the dependent class for the contact. This will actually represent a generic type for the actual type. For contacts that use a Collection type this will be the generic type parameter for that collection.
        Specified by:
        getDependent in interface Contact
        Returns:
        this returns the dependent type for the contact
      • getDependents

        public java.lang.Class[] getDependents()
        This provides the dependent classes for the contact. This will typically represent a generic types for the actual type. For contacts that use a Map type this will be the generic type parameter for that map type declaration.
        Specified by:
        getDependents in interface Contact
        Returns:
        this returns the dependent type for the contact
      • getDeclaringClass

        public java.lang.Class getDeclaringClass()
        This is the class that declares the contact. The declaring class is where the field represented been defined. This will typically be a class rather than an interface.
        Specified by:
        getDeclaringClass in interface Contact
        Returns:
        this returns the class the contact is declared within
      • getName

        public java.lang.String getName()
        This is used to acquire the name of the field. This will return the name of the field which can then be used to determine the XML attribute or element the contact represents. This ensures that the name provided string is internalized for performance.
        Specified by:
        getName in interface Contact
        Returns:
        this returns the name of the field represented
      • getAnnotation

        public java.lang.annotation.Annotation getAnnotation()
        This is the annotation associated with the point of contact. This will be an XML annotation that describes how the contact should be serialized and deserialized from the object.
        Specified by:
        getAnnotation in interface Contact
        Returns:
        this provides the annotation associated with this
      • getAnnotation

        public <T extends java.lang.annotation.Annotation> T getAnnotation​(java.lang.Class<T> type)
        This is the annotation associated with the point of contact. This will be an XML annotation that describes how the contact should be serialized and deserialized from the object.
        Specified by:
        getAnnotation in interface Type
        Parameters:
        type - this is the type of the annotation to acquire
        Returns:
        this provides the annotation associated with this
      • getCache

        private <T extends java.lang.annotation.Annotation> T getCache​(java.lang.Class<T> type)
        This is the annotation associated with the point of contact. This will be an XML annotation that describes how the contact should be serialized and deserialized from the object.
        Parameters:
        type - this is the type of the annotation to acquire
        Returns:
        this provides the annotation associated with this
      • set

        public void set​(java.lang.Object source,
                        java.lang.Object value)
                 throws java.lang.Exception
        This is used to set the specified value on the provided object. The value provided must be an instance of the contact class so that it can be set without a runtime class compatibility error.
        Specified by:
        set in interface Contact
        Parameters:
        source - this is the object to set the value on
        value - this is the value that is to be set on the object
        Throws:
        java.lang.Exception
      • get

        public java.lang.Object get​(java.lang.Object source)
                             throws java.lang.Exception
        This is used to get the specified value on the provided object. The value returned from this method will be an instance of the contact class type. If the returned object is of a different type then the serialization process will fail.
        Specified by:
        get in interface Contact
        Parameters:
        source - this is the object to acquire the value from
        Returns:
        this is the value that is acquired from the object
        Throws:
        java.lang.Exception
      • toString

        public java.lang.String toString()
        This is used to describe the contact as it exists within the owning class. It is used to provide error messages that can be used to debug issues that occur when processing a contact. The string provided is the generic field string.
        Specified by:
        toString in interface Contact
        Specified by:
        toString in interface Type
        Overrides:
        toString in class java.lang.Object
        Returns:
        this returns a string representation of the contact