Package i5.las2peer.execution
Class ServiceHelper
java.lang.Object
i5.las2peer.execution.ServiceHelper
static helper methods for invocation of service methods via reflection
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
Executes a service method.static Object
Executes a service method.static String
getParameterString
(Object[] params) Creates a string with all classes from an array of parameters.static Class<?>
getUnwrappedClass
(Class<?> c) returns the native class for a wrapperstatic Class<?>
getWrapperClass
(Class<?> c) returns the wrapper class for a native classstatic boolean
isSubclass
(Class<?> subClass, Class<?> superClass) check, if the first given class is a subclass of the second onestatic boolean
isWrapperClass
(Class<?> c) checks if the given class is a wrapper class for a java nativestatic Method
searchMethod
(Class<? extends Service> serviceClass, String methodName, Object[] params) Searches the service method fitting to the given parameter classes.
-
Constructor Details
-
ServiceHelper
public ServiceHelper()
-
-
Method Details
-
getWrapperClass
returns the wrapper class for a native class- Parameters:
c
- a Class- Returns:
- a Class
-
isWrapperClass
checks if the given class is a wrapper class for a java native- Parameters:
c
- a Class- Returns:
- a boolean
-
isSubclass
check, if the first given class is a subclass of the second one- Parameters:
subClass
- A class to checksuperClass
- A super class to check- Returns:
- true, if the first parameter class is a subclass of the second one
-
getUnwrappedClass
returns the native class for a wrapper- Parameters:
c
- a Class- Returns:
- a Class
-
execute
public static Object execute(Service service, String method) throws ServiceMethodNotFoundException, IllegalArgumentException, IllegalAccessException, InvocationTargetException Executes a service method.- Parameters:
service
- A service to usemethod
- the service method- Returns:
- result of the method invocation
- Throws:
ServiceMethodNotFoundException
- If the method was not found in the given classIllegalArgumentException
- Thrown to indicate that a method has been passed an illegal or inappropriate argument.IllegalAccessException
- if this Method object is enforcing Java language access control and the underlying method is inaccessible.InvocationTargetException
- if the underlying method throws an exception.
-
execute
public static Object execute(Service service, String method, Object... parameters) throws ServiceMethodNotFoundException, IllegalArgumentException, IllegalAccessException, InvocationTargetException Executes a service method.- Parameters:
service
- A service to usemethod
- the service methodparameters
- A bunch of parameters- Returns:
- result of the method invocation
- Throws:
ServiceMethodNotFoundException
- If the method was not found in the given classIllegalArgumentException
- Thrown to indicate that a method has been passed an illegal or inappropriate argument.IllegalAccessException
- if this Method object is enforcing Java language access control and the underlying method is inaccessible.InvocationTargetException
- if the underlying method throws an exception.
-
searchMethod
public static Method searchMethod(Class<? extends Service> serviceClass, String methodName, Object[] params) throws ServiceMethodNotFoundException Searches the service method fitting to the given parameter classes.- Parameters:
serviceClass
- A service class to search inmethodName
- the service methodparams
- A bunch of parameters- Returns:
- a Method
- Throws:
ServiceMethodNotFoundException
- If the method was not found in the given class
-
getParameterString
Creates a string with all classes from an array of parameters.- Parameters:
params
- A bunch of parameters- Returns:
- a string describing a parameter list for the given actual parameters
-