Class AbstractPropertyInvoker

    • Field Detail

      • clazz

        private Class<?> clazz
        Class to invoke methods on.
      • properties

        private Map<String,​Method[]> properties
        Map of all properties to their getter and setter methods.
    • Constructor Detail

      • AbstractPropertyInvoker

        public AbstractPropertyInvoker()
    • Method Detail

      • initialize

        protected void initialize​(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​(Object object,
                                String name,
                                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:
        IllegalArgumentException - if an invocation exception occurs
      • convertValue

        protected abstract Object convertValue​(Class<?> type,
                                               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​(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 Set<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,
                                            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:
        IllegalArgumentException - if the supplied class name cannot create a new instance of T
      • createClass

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

        protected Object convertSimpleType​(Class<?> type,
                                           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 Enum<?> getEnum​(Class<?> clazz,
                                         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 Object createTypeFromPropertyValue​(Class<?> c,
                                                     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 Object createArrayTypeFromPropertyValue​(Class<?> c,
                                                          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 Object createArrayEnumFromPropertyValue​(Class<?> c,
                                                          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 Object invokeMethod​(Method method,
                                          Object object,
                                          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:
        IllegalArgumentException - if an error occurs invoking the method