Class ReflectionHelper

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map

    public class ReflectionHelper
    extends java.util.HashMap
    A helper class that allows creating new object instances and getting/setting object's properties via reflection
    Since:
    MicroStrategy Web 8.0.1
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addAllowedClassName​(java.lang.String fqcn)
      Add a fully qualified class name into the allowed class name set, so that it could be used through Java Reflection
      static void addAllowedClassNames​(java.util.Collection<java.lang.String> collection)  
      static java.lang.Class classForName​(java.lang.String className)
      Return a Class object for the class with the given name.
      protected static java.lang.Class classForName​(java.lang.String className, boolean skipValidation)  
      static java.lang.Object get​(java.lang.Object ob, java.lang.String name)
      Gets the object's property value
      static java.lang.String getEnumerationValue​(java.lang.String enumValue)
      Returns the value of the constant defined in the Java fully qualified class name and constant name received as a parameter.
      static java.lang.reflect.Method getSetterMethod​(java.lang.Class type, java.lang.String name)  
      static java.lang.Object invokeGetter​(java.lang.Object ob, java.lang.String name)  
      static java.lang.Object newInstance​(java.lang.String className)
      Creates a new instance for the class with the given name.
      protected static java.lang.Object newInstance​(java.lang.String className, boolean skipValidation)  
      static java.lang.Object newInstance​(java.lang.String className, java.lang.Class[] parameterTypes, java.lang.Object[] initargs)
      Creates a new instance for the class with the given name.
      protected static java.lang.Object newInstance​(java.lang.String className, java.lang.Class[] parameterTypes, java.lang.Object[] initargs, boolean skipValidation)  
      static void set​(java.lang.Object ob, java.lang.String propName, java.lang.Object value)
      Gets the object's property value
      • Methods inherited from class java.util.HashMap

        clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        equals, hashCode
    • Constructor Detail

      • ReflectionHelper

        public ReflectionHelper()
    • Method Detail

      • addAllowedClassName

        public static void addAllowedClassName​(java.lang.String fqcn)
        Add a fully qualified class name into the allowed class name set, so that it could be used through Java Reflection
        Parameters:
        fqcn - The fully qualified class name
      • addAllowedClassNames

        public static void addAllowedClassNames​(java.util.Collection<java.lang.String> collection)
      • newInstance

        public static java.lang.Object newInstance​(java.lang.String className)
                                            throws java.lang.ClassNotFoundException
        Creates a new instance for the class with the given name. The corresponding class needs to have a public non arguments constructor in order to successfully use this method.
        Parameters:
        className - A fully qualified class name
        Returns:
        Object An instance of the given class.
        Throws:
        java.lang.ClassNotFoundException - If the class is not found in the class path
        Since:
        MicroStrategy Web 9.0.0
      • newInstance

        protected static java.lang.Object newInstance​(java.lang.String className,
                                                      boolean skipValidation)
                                               throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • newInstance

        public static java.lang.Object newInstance​(java.lang.String className,
                                                   java.lang.Class[] parameterTypes,
                                                   java.lang.Object[] initargs)
                                            throws java.lang.ClassNotFoundException,
                                                   java.lang.NoSuchMethodException
        Creates a new instance for the class with the given name. The class is created using a constructor that expects the given list of parameters.
        Parameters:
        className - A fully qualified class name
        parameterTypes - An array with the parameter types
        initargs - An array with the values that shall be passed to the contructor. Clearly each argument needs to match the types passed in parameterTypes.
        Returns:
        Object An instance of the given class.
        Throws:
        java.lang.ClassNotFoundException - If the class is not found in the class path
        java.lang.NoSuchMethodException
        Since:
        MicroStrategy Web 9.0.0
        See Also:
        Class.getConstructor(java.lang.Class<?>...)
      • newInstance

        protected static java.lang.Object newInstance​(java.lang.String className,
                                                      java.lang.Class[] parameterTypes,
                                                      java.lang.Object[] initargs,
                                                      boolean skipValidation)
                                               throws java.lang.ClassNotFoundException,
                                                      java.lang.NoSuchMethodException
        Throws:
        java.lang.ClassNotFoundException
        java.lang.NoSuchMethodException
      • classForName

        public static java.lang.Class classForName​(java.lang.String className)
                                            throws java.lang.ClassNotFoundException
        Return a Class object for the class with the given name.
        Parameters:
        className - A fully qualified class name
        Throws:
        java.lang.ClassNotFoundException - If the class is not found in the class-path (this includes the extended class path that includes all customizations).
        Since:
        MicroStrategy Web 9.0.0
        See Also:
        Class.forName(java.lang.String), Customizations.getClassLoader()
      • classForName

        protected static java.lang.Class classForName​(java.lang.String className,
                                                      boolean skipValidation)
                                               throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • get

        public static java.lang.Object get​(java.lang.Object ob,
                                           java.lang.String name)
        Gets the object's property value
        Parameters:
        ob - object
        name - property name
        Returns:
        property value;
      • set

        public static void set​(java.lang.Object ob,
                               java.lang.String propName,
                               java.lang.Object value)
        Gets the object's property value
        Parameters:
        ob - object
        propName - property name
        value - new value
      • invokeGetter

        public static java.lang.Object invokeGetter​(java.lang.Object ob,
                                                    java.lang.String name)
      • getEnumerationValue

        public static java.lang.String getEnumerationValue​(java.lang.String enumValue)
        Returns the value of the constant defined in the Java fully qualified class name and constant name received as a parameter. The value is always returned as a String regardless of the original data type. If the class cannot be resolved or the data member does not exist, null is returned.
        Parameters:
        enumValue - FCN of the data member to resolved. i.e. com.microstrategy.web.beans.EnumReportBeanEvents.REPORT_EVENT_EXECUTE
        Returns:
        String object containing the value of the FCN memmber provided. For the previous example, the return value is "4001"
        Since:
        MicroStrategy Web 9.0.0
      • getSetterMethod

        public static java.lang.reflect.Method getSetterMethod​(java.lang.Class type,
                                                               java.lang.String name)
        Since:
        MicroStrategy Web 8.1.0