Class ReflectionUtil


  • public final class ReflectionUtil
    extends java.lang.Object
    Defines the reflection utility.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> java.lang.Object callMethod​(java.lang.Object classInstance, java.lang.String className, java.lang.String methodName, java.lang.Class<?>[] paramType, java.lang.Object[] param)
      Calls the given method on the given instance
      void disableAccessWarnings()
      Disable access warnings
      <T> java.lang.Class<T> getClassObject​(java.lang.String className)
      Load a class by given name
      static ReflectionUtil getInstance()
      Get the instance
      <T> java.lang.reflect.Method getMethod​(java.lang.String className, java.lang.String methodName, java.lang.Class<?>[] paramType)
      Gets the defined method back
      boolean isClassAvailable​(java.lang.String className)
      Check if the given class exists
      <T> T newInstance​(java.lang.Class<T> clazz)
      Create a new instance of a given class
      • Methods inherited from class java.lang.Object

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

      • getInstance

        public static ReflectionUtil getInstance()
        Get the instance
        Returns:
        the instance
      • isClassAvailable

        public boolean isClassAvailable​(java.lang.String className)
                                 throws java.lang.IllegalArgumentException
        Check if the given class exists
        Parameters:
        className - the name of the class to check
        Returns:
        true if the class exists; otherwise false
        Throws:
        java.lang.IllegalArgumentException - In case of an invalid class name
      • getClassObject

        public <T> java.lang.Class<T> getClassObject​(java.lang.String className)
                                              throws java.lang.IllegalArgumentException,
                                                     java.lang.ClassNotFoundException
        Load a class by given name
        Type Parameters:
        T - the generic type
        Parameters:
        className - the name of the class
        Returns:
        the loaded class
        Throws:
        java.lang.IllegalArgumentException - In case of an invalid class name
        java.lang.ClassNotFoundException - in case of error
      • newInstance

        public <T> T newInstance​(java.lang.Class<T> clazz)
                          throws java.lang.IllegalArgumentException,
                                 java.lang.SecurityException,
                                 java.lang.InstantiationException,
                                 java.lang.IllegalAccessException
        Create a new instance of a given class
        Type Parameters:
        T - the generic type
        Parameters:
        clazz - the class
        Returns:
        the instance
        Throws:
        java.lang.IllegalArgumentException - In case of an invalid class name
        java.lang.SecurityException - in case of error
        java.lang.reflect.InvocationTargetException - in case of error
        java.lang.IllegalArgumentException - in case of error
        java.lang.IllegalAccessException - in case of error
        java.lang.InstantiationException - in case of error
      • getMethod

        public <T> java.lang.reflect.Method getMethod​(java.lang.String className,
                                                      java.lang.String methodName,
                                                      java.lang.Class<?>[] paramType)
                                               throws java.lang.SecurityException,
                                                      java.lang.NoSuchMethodException,
                                                      java.lang.ClassNotFoundException
        Gets the defined method back
        Type Parameters:
        T - the generic type
        Parameters:
        className - the class name
        methodName - the method name
        paramType - the parameter type
        Returns:
        the method
        Throws:
        java.lang.IllegalArgumentException - In case of an invalid class or method name
        java.lang.SecurityException - in case of error
        java.lang.NoSuchMethodException - in case of error
        java.lang.ClassNotFoundException - in case of error
      • callMethod

        public <T> java.lang.Object callMethod​(java.lang.Object classInstance,
                                               java.lang.String className,
                                               java.lang.String methodName,
                                               java.lang.Class<?>[] paramType,
                                               java.lang.Object[] param)
                                        throws java.lang.SecurityException,
                                               java.lang.NoSuchMethodException,
                                               java.lang.IllegalArgumentException,
                                               java.lang.IllegalAccessException,
                                               java.lang.reflect.InvocationTargetException,
                                               java.lang.ClassNotFoundException
        Calls the given method on the given instance
        Type Parameters:
        T - the generic type
        Parameters:
        classInstance - the instance of the class where the method should be called
        className - the name of the class
        methodName - the method name
        paramType - the parameter type
        param - the parameter values
        Returns:
        the result
        Throws:
        java.lang.SecurityException - in case of error
        java.lang.NoSuchMethodException - in case of error
        java.lang.reflect.InvocationTargetException - in case of error
        java.lang.IllegalAccessException - in case of error
        java.lang.IllegalArgumentException - in case of error
        java.lang.ClassNotFoundException - in case of error
      • disableAccessWarnings

        public void disableAccessWarnings()
        Disable access warnings