Class AbstractPropertyInvoker

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.Object convertSimpleType​(java.lang.Class<?> type, java.lang.String value)
      Converts simple types that are common to all property invokers.
      protected abstract java.lang.Object convertValue​(java.lang.Class<?> type, java.lang.String value)
      Converts the supplied string value into an Object of the supplied type.
      protected java.lang.Object createArrayEnumFromPropertyValue​(java.lang.Class<?> c, java.lang.String s)
      Returns the enum array which represents the supplied class given the supplied string representation.
      protected java.lang.Object createArrayTypeFromPropertyValue​(java.lang.Class<?> c, java.lang.String s)
      Returns the object which represents an array of the supplied class given the supplied string representation.
      static java.lang.Class<?> createClass​(java.lang.String className)
      Creates the class with the supplied name.
      protected java.lang.Object createTypeFromPropertyValue​(java.lang.Class<?> c, java.lang.String s)
      Returns the object which represents the supplied class given the supplied string representation.
      protected static java.lang.Enum<?> getEnum​(java.lang.Class<?> clazz, java.lang.String value)
      Returns the enum for the supplied type and value.
      java.util.Set<java.lang.String> getProperties()
      Returns the property keys for this invoker.
      boolean hasProperty​(java.lang.String name)
      Returns whether the supplied property exists for this invoker.
      protected void initialize​(java.lang.Class<?> c)
      Initializes the properties cache with the supplied class.
      static <T> T instantiateType​(T type, java.lang.String className)
      Creates an instance of the supplied type.
      static java.lang.Object invokeMethod​(java.lang.reflect.Method method, java.lang.Object object, java.lang.Object arg)
      Invokes the supplied method on the supplied object with the supplied argument.
      void setProperty​(java.lang.Object object, java.lang.String name, java.lang.String value)
      This invokes the setter method for the supplied property name with the supplied value.
      • Methods inherited from class java.lang.Object

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

      • AbstractPropertyInvoker

        public AbstractPropertyInvoker()
    • Method Detail

      • initialize

        protected void initialize​(java.lang.Class<?> c)
        Initializes the properties cache with the supplied class. The cache contains a map of properties to an array of the setter and getter methods. If a method named 'initialize' is found, it is also cached.
        Parameters:
        c - to read methods from
      • setProperty

        public void setProperty​(java.lang.Object object,
                                java.lang.String name,
                                java.lang.String value)
        This invokes the setter method for the supplied property name with the supplied value.
        Specified by:
        setProperty in interface PropertyInvoker
        Parameters:
        object - to invoke method on
        name - of the property
        value - of the property
        Throws:
        java.lang.IllegalArgumentException - if an invocation exception occurs
      • convertValue

        protected abstract java.lang.Object convertValue​(java.lang.Class<?> type,
                                                         java.lang.String value)
        Converts the supplied string value into an Object of the supplied type. If value cannot be converted it is returned as is.
        Parameters:
        type - of object to convert value into
        value - to parse
        Returns:
        object of the supplied type
      • hasProperty

        public boolean hasProperty​(java.lang.String name)
        Returns whether the supplied property exists for this invoker.
        Specified by:
        hasProperty in interface PropertyInvoker
        Parameters:
        name - to check
        Returns:
        whether the supplied property exists
      • getProperties

        public java.util.Set<java.lang.String> getProperties()
        Returns the property keys for this invoker.
        Specified by:
        getProperties in interface PropertyInvoker
        Returns:
        set of property names
      • instantiateType

        public static <T> T instantiateType​(T type,
                                            java.lang.String className)
        Creates an instance of the supplied type.
        Type Parameters:
        T - type of class returned
        Parameters:
        type - of class to create
        className - to create
        Returns:
        class of type T
        Throws:
        java.lang.IllegalArgumentException - if the supplied class name cannot create a new instance of T
      • createClass

        public static java.lang.Class<?> createClass​(java.lang.String className)
        Creates the class with the supplied name.
        Parameters:
        className - to create
        Returns:
        class
        Throws:
        java.lang.IllegalArgumentException - if the supplied class name cannot be created
      • convertSimpleType

        protected java.lang.Object convertSimpleType​(java.lang.Class<?> type,
                                                     java.lang.String value)
        Converts simple types that are common to all property invokers. If value cannot be converted it is returned as is.
        Parameters:
        type - of object to convert value into
        value - to parse
        Returns:
        object of the supplied type
      • getEnum

        protected static java.lang.Enum<?> getEnum​(java.lang.Class<?> clazz,
                                                   java.lang.String value)
        Returns the enum for the supplied type and value.
        Parameters:
        clazz - of the enum
        value - of the enum
        Returns:
        enum that matches the supplied value
      • createTypeFromPropertyValue

        protected java.lang.Object createTypeFromPropertyValue​(java.lang.Class<?> c,
                                                               java.lang.String s)
        Returns the object which represents the supplied class given the supplied string representation.
        Parameters:
        c - type to instantiate
        s - property value to parse
        Returns:
        the supplied type or null
      • createArrayTypeFromPropertyValue

        protected java.lang.Object createArrayTypeFromPropertyValue​(java.lang.Class<?> c,
                                                                    java.lang.String s)
        Returns the object which represents an array of the supplied class given the supplied string representation.
        Parameters:
        c - type to instantiate
        s - property value to parse
        Returns:
        an array or null
      • createArrayEnumFromPropertyValue

        protected java.lang.Object createArrayEnumFromPropertyValue​(java.lang.Class<?> c,
                                                                    java.lang.String s)
        Returns the enum array which represents the supplied class given the supplied string representation.
        Parameters:
        c - type to instantiate
        s - property value to parse
        Returns:
        Enum[] of the supplied type or null
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.reflect.Method method,
                                                    java.lang.Object object,
                                                    java.lang.Object arg)
        Invokes the supplied method on the supplied object with the supplied argument.
        Parameters:
        method - to invoke
        object - to invoke method on
        arg - to invoke method with
        Returns:
        object produced by the invocation
        Throws:
        java.lang.IllegalArgumentException - if an error occurs invoking the method