Class ReflectionUtility



  • public final class ReflectionUtility
    extends java.lang.Object
    The Class ReflectionUtility.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ReflectionUtility.NonExistingValueClass
      This class indicates a non existing value in the name-to-value mapping.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean hasGetterAttribute​(java.lang.Object anObject, java.lang.String anAttributeName, java.lang.Class<?> aReturnType)
      This method tests whether the given java beans getter attribute is found for the given object.
      static boolean hasSetterAttribute​(java.lang.Object anObject, java.lang.String anAttributeName, java.lang.Class<?> anAttributeType)
      This method tests whether the given java beans setter attribute is found for the given object.
      static void setAttribute​(java.lang.Object anObject, java.lang.String anAttributeName, java.lang.Object anAttributeValue)
      This method sets a java beans attribute for the given object.
      static void setAttribute​(java.lang.Object anObject, org.refcodes.structure.Attribute anAttributeValueStruct)
      This method sets a java beans attribute for the given object.
      static org.refcodes.structure.Attribute[] toBeanAttributes​(java.lang.Object anObject)
      This method uses reflection on order to analyze a given object.
      • Methods inherited from class java.lang.Object

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

      • toBeanAttributes

        public static org.refcodes.structure.Attribute[] toBeanAttributes​(java.lang.Object anObject)
        This method uses reflection on order to analyze a given object. The java beans attributes and their values are retrieved and returned in an array of name-to-value pairs.
        Parameters:
        anObject - The object to be analyzed.
        Returns:
        An array of objects containing the java beans name-to-value pairs.
      • setAttribute

        public static void setAttribute​(java.lang.Object anObject,
                                        java.lang.String anAttributeName,
                                        java.lang.Object anAttributeValue)
                                 throws java.lang.NoSuchMethodException
        This method sets a java beans attribute for the given object. The corresponding java beans method must begin with a 'set', the following letter must be in upper case and it must only take one argument being of the same (or super-) type as the attribute's type.
        Parameters:
        anObject - The object which's java beans method is to be called.
        anAttributeName - The attribute name of the java beans method.
        anAttributeValue - The value of the attribute to be set.
        Throws:
        java.lang.NoSuchMethodException - Description of the Exception
      • setAttribute

        public static void setAttribute​(java.lang.Object anObject,
                                        org.refcodes.structure.Attribute anAttributeValueStruct)
                                 throws java.lang.NoSuchMethodException
        This method sets a java beans attribute for the given object.
        Parameters:
        anObject - The object which's attribute is to be set.
        anAttributeValueStruct - The name-to-value struct for the attrubute to be set.
        Throws:
        java.lang.NoSuchMethodException - Description of the Exception
      • hasSetterAttribute

        public static boolean hasSetterAttribute​(java.lang.Object anObject,
                                                 java.lang.String anAttributeName,
                                                 java.lang.Class<?> anAttributeType)
        This method tests whether the given java beans setter attribute is found for the given object.
        Parameters:
        anObject - The object which is to be tested.
        anAttributeName - The attribute name.
        anAttributeType - The expected (sub-) type of the attribute
        Returns:
        True if the object has a method with the given java beans name which can be called with an argument of the given type.
      • hasGetterAttribute

        public static boolean hasGetterAttribute​(java.lang.Object anObject,
                                                 java.lang.String anAttributeName,
                                                 java.lang.Class<?> aReturnType)
        This method tests whether the given java beans getter attribute is found for the given object.
        Parameters:
        anObject - The object which is to be tested.
        anAttributeName - The attribute name.
        aReturnType - The expected (sub-) type of the return value
        Returns:
        True if the object has a method with the given java beans name which returns the given (super-) type.