Class ReflectionAPIUtils

java.lang.Object
com.priint.pubserver.parameterparser.ReflectionAPIUtils

public class ReflectionAPIUtils extends Object
Utility class for easier working with Java Reflection API.
  • Constructor Details

    • ReflectionAPIUtils

      public ReflectionAPIUtils()
  • Method Details

    • usesInterface

      public static boolean usesInterface(Class<?> clazz, 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(Class<?> clazz, 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 Object callStaticMethod(String className, String methodName, 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 Object callStaticMethodUnchecked(String className, String methodName, Object[] params) throws 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:
      Exception - thrown if either class and method are not valid or the call fails
    • callPluginMethod

      public static Object callPluginMethod(String mappedName, String methodName, 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 Object callPluginMethodUnchecked(String mappedName, String methodName, 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 Object callPluginMethodWithException(String mappedName, String methodName, 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 Object callBeanMethod(String globalName, String methodName, Object[] params, 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 Object callBeanMethod(String globalName, String methodName, Object[] params, Object bean) throws ParameterInterpreterException
      Calls a method of a EJB with given arguments
      Parameters:
      globalName -
      methodName -
      params -
      bean -
      Returns:
      Throws:
      ParameterInterpreterException
    • castType

      public static Object castType(Object obj, 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: