Package com.microstrategy.utils
Class ReflectionHelper
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap
-
- com.microstrategy.utils.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
-
-
Constructor Summary
Constructors Constructor Description ReflectionHelper()
-
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 Reflectionstatic 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.static java.lang.Object
get(java.lang.Object ob, java.lang.String name)
Gets the object's property valuestatic 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.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.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
-
-
-
-
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
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 nameparameterTypes
- An array with the parameter typesinitargs
- 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 pathjava.lang.NoSuchMethodException
- Since:
- MicroStrategy Web 9.0.0
- See Also:
Class.getConstructor(java.lang.Class<?>...)
-
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()
-
get
public static java.lang.Object get(java.lang.Object ob, java.lang.String name)
Gets the object's property value- Parameters:
ob
- objectname
- 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
- objectpropName
- property namevalue
- 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
-
-