Class ContainerFieldHandler

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int MODE_AUTO
      Automatically choose the mode to use.
      static int MODE_CHILD_LINK
      The mode for a ContainerElement.
      static int MODE_PARENT_LINK
      When the field is not a ContainerElement, this mode is used.
    • Constructor Summary

      Constructors 
      Constructor Description
      ContainerFieldHandler​(FieldHandler handler)
      Creates a new ContainerFieldHandler with the given FieldHandler.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void checkValidity​(java.lang.Object object)
      Checks the field validity.
      java.lang.Object getValue​(java.lang.Object object)
      Returns the value of the field from the object.
      java.lang.Object newInstance​(java.lang.Object parent)
      Creates a new instance of the object described by this field.
      void resetValue​(java.lang.Object object)
      Sets the value of the field to a default value.
      void setValue​(java.lang.Object object, java.lang.Object value)
      Sets the value of the field on the object.
      • Methods inherited from class java.lang.Object

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

      • MODE_AUTO

        public static final int MODE_AUTO
        Automatically choose the mode to use.
        See Also:
        Constant Field Values
      • MODE_PARENT_LINK

        public static final int MODE_PARENT_LINK
        When the field is not a ContainerElement, this mode is used.
        See Also:
        Constant Field Values
      • MODE_CHILD_LINK

        public static final int MODE_CHILD_LINK
        The mode for a ContainerElement. getValue and setValue operate on the parent.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ContainerFieldHandler

        public ContainerFieldHandler​(FieldHandler handler)
        Creates a new ContainerFieldHandler with the given FieldHandler.
        Parameters:
        handler - The field handler to delegate to.
    • Method Detail

      • getValue

        public java.lang.Object getValue​(java.lang.Object object)
                                  throws java.lang.IllegalStateException
        Returns the value of the field from the object. If mode is MODE_CHILD_LINK or mode is MODE_AUTO and the object is a ContainerElement, then the value of the parent is returned. Otherwise, a new ContainerElement is returned. The value of this new ContainerElement is the value of the provided object and the parent of the new ContainerElement is the provided object.
        Specified by:
        getValue in interface FieldHandler
        Parameters:
        object - The object to get the value of
        Returns:
        The value of the field
        Throws:
        java.lang.IllegalStateException - The Java object has changed and is no longer supported by this handler, or the handler is not compatible with the Java object
      • newInstance

        public java.lang.Object newInstance​(java.lang.Object parent)
                                     throws java.lang.IllegalStateException
        Creates a new instance of the object described by this field. Of the object provided is a ContainerElement, then a new isntance of the parent object is returned. Otherwise a new ContainerElement is created and returned, with the parent set to the provided object.
        Specified by:
        newInstance in interface FieldHandler
        Parameters:
        parent - The object for which the field is created
        Returns:
        A new instance of the field's value
        Throws:
        java.lang.IllegalStateException - This field is a simple type and cannot be instantiated
      • resetValue

        public void resetValue​(java.lang.Object object)
                        throws java.lang.IllegalStateException
        Sets the value of the field to a default value.

        Reference fields are set to null, primitive fields are set to their default value, collection fields are emptied of all elements.

        Specified by:
        resetValue in interface FieldHandler
        Parameters:
        object - The object
        Throws:
        java.lang.IllegalStateException - The Java object has changed and is no longer supported by this handler, or the handler is not compatiable with the Java object
      • setValue

        public void setValue​(java.lang.Object object,
                             java.lang.Object value)
                      throws java.lang.IllegalStateException,
                             java.lang.IllegalArgumentException
        Sets the value of the field on the object. That is, sets the value of the container parent to the provided value.
        Specified by:
        setValue in interface FieldHandler
        Parameters:
        object - The object whose value to set.
        value - The new value
        Throws:
        java.lang.IllegalStateException - The Java object has changed and is no longer supported by this handler, or the handler is not compatiable with the Java object
        java.lang.IllegalArgumentException - The value passed is not of a supported type
      • checkValidity

        public void checkValidity​(java.lang.Object object)
                           throws ValidityException,
                                  java.lang.IllegalStateException
        Checks the field validity. Returns successfully if the field can be stored, is valid, etc, throws an exception otherwise.
        Specified by:
        checkValidity in interface FieldHandler
        Parameters:
        object - The object
        Throws:
        ValidityException - The field is invalid, is required and null, or any other validity violation
        java.lang.IllegalStateException - The Java object has changed and is no longer supported by this handler, or the handler is not compatiable with the Java object