Class ReflectionAPIUtils


  • public class ReflectionAPIUtils
    extends java.lang.Object
    Utility class for easier working with Java Reflection API.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object callBeanMethod​(java.lang.String globalName, java.lang.String methodName, java.lang.Object[] params, java.lang.Object bean)
      Calls a method of a EJB with given arguments
      static java.lang.Object callBeanMethod​(java.lang.String globalName, java.lang.String methodName, java.lang.Object[] params, java.lang.Object bean, boolean throwException)
      Calls a method of a EJB with given arguments
      static java.lang.Object callPluginMethod​(java.lang.String mappedName, java.lang.String methodName, java.lang.Object[] params)
      Calls a method of a plug-in with given arguments
      static java.lang.Object callPluginMethodUnchecked​(java.lang.String mappedName, java.lang.String methodName, java.lang.Object[] params)
      Calls a method of a plug-in with given arguments
      static java.lang.Object callPluginMethodWithException​(java.lang.String mappedName, java.lang.String methodName, java.lang.Object[] params, boolean throwException)
      Calls a method of a plug-in with given arguments
      static java.lang.Object callStaticMethod​(java.lang.String className, java.lang.String methodName, java.lang.Object[] params)
      Calls a static method in a class with given arguments
      static java.lang.Object callStaticMethodUnchecked​(java.lang.String className, java.lang.String methodName, java.lang.Object[] params)
      Calls a static method in a class with given arguments
      static java.lang.Object castType​(java.lang.Object obj, java.lang.Class<?> type)
      Called before method invocation on each method argument
      static boolean usesInterface​(java.lang.Class<?> clazz, java.lang.Class<?> interfaceClass)
      Checks if a class implements an interface
      static boolean usesInterface​(java.lang.Class<?> clazz, java.lang.String interfaceClassName)
      Checks if a class implements an interface
      • Methods inherited from class java.lang.Object

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

      • ReflectionAPIUtils

        public ReflectionAPIUtils()
    • Method Detail

      • usesInterface

        public static boolean usesInterface​(java.lang.Class<?> clazz,
                                            java.lang.Class<?> interfaceClass)
        Checks if a class implements an interface
        Parameters:
        clazz - class to check
        interfaceClass - interface class
        Returns:
        true if the class implements the interface
      • usesInterface

        public static boolean usesInterface​(java.lang.Class<?> clazz,
                                            java.lang.String interfaceClassName)
        Checks if a class implements an interface
        Parameters:
        clazz - class to check
        interfaceClassName - full qualified class name of the interface
        Returns:
        true if the class implements the interface
      • callStaticMethod

        public static java.lang.Object callStaticMethod​(java.lang.String className,
                                                        java.lang.String methodName,
                                                        java.lang.Object[] params)
        Calls a static method in a class with given arguments

        Exceptions will be swallowed and only create an entry in the log.

        Parameters:
        className - full name of the class
        methodName - name of the method
        params - arguments
        Returns:
        result of the method call or null in case of an exception.
      • callStaticMethodUnchecked

        public static java.lang.Object callStaticMethodUnchecked​(java.lang.String className,
                                                                 java.lang.String methodName,
                                                                 java.lang.Object[] params)
                                                          throws java.lang.Exception
        Calls a static method in a class with given arguments

        Exceptions will be passed through as is.

        Parameters:
        className - full name of the class
        methodName - name of the method
        params - arguments
        Returns:
        result of the method call
        Throws:
        java.lang.Exception - thrown if either class and method are not valid or the call fails
      • callPluginMethod

        public static java.lang.Object callPluginMethod​(java.lang.String mappedName,
                                                        java.lang.String methodName,
                                                        java.lang.Object[] params)
        Calls a method of a plug-in with given arguments

        Exceptions will be swallowed and only create an entry in the log if in debug mode.

        Parameters:
        mappedName - JNDI name of the plug-in
        methodName - name of the method
        params - arguments
        Returns:
        result of the method call or null in case of an exception.
      • callPluginMethodUnchecked

        public static java.lang.Object callPluginMethodUnchecked​(java.lang.String mappedName,
                                                                 java.lang.String methodName,
                                                                 java.lang.Object[] params)
                                                          throws ParameterInterpreterException
        Calls a method of a plug-in with given arguments

        All exceptions will be wrapped into a ParameterInterpreterException.

        Parameters:
        mappedName - JNDI name of the plug-in
        methodName - name of the method
        params - arguments
        Returns:
        result of the method call
        Throws:
        ParameterInterpreterException - is thrown if either plugin is not available or method are not valid or the call fails
      • callPluginMethodWithException

        public static java.lang.Object callPluginMethodWithException​(java.lang.String mappedName,
                                                                     java.lang.String methodName,
                                                                     java.lang.Object[] params,
                                                                     boolean throwException)
                                                              throws ParameterInterpreterException
        Calls a method of a plug-in with given arguments
        Parameters:
        mappedName - JNDI name of the plug-in
        methodName - name of the method
        params - arguments
        throwException -
        Returns:
        result of the method call
        Throws:
        ParameterInterpreterException - is thrown if either plugin is not available or method are not valid or the call fails
      • callBeanMethod

        public static java.lang.Object callBeanMethod​(java.lang.String globalName,
                                                      java.lang.String methodName,
                                                      java.lang.Object[] params,
                                                      java.lang.Object bean,
                                                      boolean throwException)
                                               throws ParameterInterpreterException
        Calls a method of a EJB with given arguments

        Exceptions will be swallowed and only create an entry in the log.

        Parameters:
        globalName -
        methodName -
        params -
        bean -
        Throws:
        ParameterInterpreterException
      • callBeanMethod

        public static java.lang.Object callBeanMethod​(java.lang.String globalName,
                                                      java.lang.String methodName,
                                                      java.lang.Object[] params,
                                                      java.lang.Object bean)
                                               throws ParameterInterpreterException
        Calls a method of a EJB with given arguments
        Parameters:
        globalName -
        methodName -
        params -
        bean -
        Returns:
        Throws:
        ParameterInterpreterException
      • castType

        public static java.lang.Object castType​(java.lang.Object obj,
                                                java.lang.Class<?> type)
        Called before method invocation on each method argument

        In case of cast problems an error string will be returned as argument content.

        Parameters:
        obj -
        type -
        Returns: