Example #1
0
 /**
  * Returns the value of a field of a desired class of an object
  *
  * @param instance Target object
  * @param className Name of the desired target class
  * @param packageType Package where the desired target class is located
  * @param declared Whether the desired field is declared or not
  * @param fieldName Name of the desired field
  * @return The value of field of the target object
  * @throws IllegalArgumentException If the target object does not feature the desired field
  * @throws IllegalAccessException If the desired field cannot be accessed
  * @throws NoSuchFieldException If the desired field of the desired class cannot be found
  * @throws SecurityException If the desired field cannot be made accessible
  * @throws ClassNotFoundException If the desired target class with the specified name and package
  *     cannot be found
  * @see #getValue(Object, Class, boolean, String)
  */
 public static Object getValue(
     Object instance,
     String className,
     PackageType packageType,
     boolean declared,
     String fieldName)
     throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException,
         SecurityException, ClassNotFoundException {
   return getValue(instance, packageType.getClass(className), declared, fieldName);
 }
Example #2
0
 /**
  * Invokes a method of a desired class on an object with the given arguments
  *
  * @param instance Target object
  * @param className Name of the desired target class
  * @param packageType Package where the desired target class is located
  * @param methodName Name of the desired method
  * @param arguments Arguments which are used to invoke the desired method
  * @return The result of invoking the desired method on the target object
  * @throws IllegalAccessException If the desired method cannot be accessed due to certain
  *     circumstances
  * @throws IllegalArgumentException If the types of the arguments do not match the parameter types
  *     of the method (this should not occur since it searches for a method with the types of the
  *     arguments)
  * @throws InvocationTargetException If the desired method cannot be invoked on the target object
  * @throws NoSuchMethodException If the desired method of the desired target class with the
  *     specified name and arguments cannot be found
  * @throws ClassNotFoundException If the desired target class with the specified name and package
  *     cannot be found
  * @see #invokeMethod(Object, Class, String, Object...)
  */
 public static Object invokeMethod(
     Object instance,
     String className,
     PackageType packageType,
     String methodName,
     Object... arguments)
     throws IllegalAccessException, IllegalArgumentException, InvocationTargetException,
         NoSuchMethodException, ClassNotFoundException {
   return invokeMethod(instance, packageType.getClass(className), methodName, arguments);
 }
Example #3
0
 /**
  * Returns the constructor of a desired class with the given parameter types
  *
  * @param className Name of the desired target class
  * @param packageType Package where the desired target class is located
  * @param parameterTypes Parameter types of the desired constructor
  * @return The constructor of the desired target class with the specified parameter types
  * @throws NoSuchMethodException If the desired constructor with the specified parameter types
  *     cannot be found
  * @throws ClassNotFoundException ClassNotFoundException If the desired target class with the
  *     specified name and package cannot be found
  * @see #getConstructor(Class, Class...)
  */
 public static Constructor<?> getConstructor(
     String className, PackageType packageType, Class<?>... parameterTypes)
     throws NoSuchMethodException, ClassNotFoundException {
   return getConstructor(packageType.getClass(className), parameterTypes);
 }
Example #4
0
 /**
  * Returns a field of a desired class with the given name
  *
  * @param className Name of the desired target class
  * @param packageType Package where the desired target class is located
  * @param declared Whether the desired field is declared or not
  * @param fieldName Name of the desired field
  * @return The field of the desired target class with the specified name
  * @throws NoSuchFieldException If the desired field of the desired class cannot be found
  * @throws SecurityException If the desired field cannot be made accessible
  * @throws ClassNotFoundException If the desired target class with the specified name and package
  *     cannot be found
  * @see #getField(Class, boolean, String)
  */
 public static Field getField(
     String className, PackageType packageType, boolean declared, String fieldName)
     throws NoSuchFieldException, SecurityException, ClassNotFoundException {
   return getField(packageType.getClass(className), declared, fieldName);
 }
Example #5
0
 /**
  * Returns a method of a desired class with the given parameter types
  *
  * @param className Name of the desired target class
  * @param packageType Package where the desired target class is located
  * @param methodName Name of the desired method
  * @param parameterTypes Parameter types of the desired method
  * @return The method of the desired target class with the specified name and parameter types
  * @throws NoSuchMethodException If the desired method of the desired target class with the
  *     specified name and parameter types cannot be found
  * @throws ClassNotFoundException If the desired target class with the specified name and package
  *     cannot be found
  * @see #getMethod(Class, String, Class...)
  */
 public static Method getMethod(
     String className, PackageType packageType, String methodName, Class<?>... parameterTypes)
     throws NoSuchMethodException, ClassNotFoundException {
   return getMethod(packageType.getClass(className), methodName, parameterTypes);
 }
Example #6
0
 /**
  * Returns an instance of a desired class with the given arguments
  *
  * @param className Name of the desired target class
  * @param packageType Package where the desired target class is located
  * @param arguments Arguments which are used to construct an object of the desired target class
  * @return The instance of the desired target class with the specified arguments
  * @throws InstantiationException If you cannot create an instance of the desired target class due
  *     to certain circumstances
  * @throws IllegalAccessException If the desired constructor cannot be accessed due to certain
  *     circumstances
  * @throws IllegalArgumentException If the types of the arguments do not match the parameter types
  *     of the constructor (this should not occur since it searches for a constructor with the
  *     types of the arguments)
  * @throws InvocationTargetException If the desired constructor cannot be invoked
  * @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be
  *     found
  * @throws ClassNotFoundException If the desired target class with the specified name and package
  *     cannot be found
  * @see #instantiateObject(Class, Object...)
  */
 public static Object instantiateObject(
     String className, PackageType packageType, Object... arguments)
     throws InstantiationException, IllegalAccessException, IllegalArgumentException,
         InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
   return instantiateObject(packageType.getClass(className), arguments);
 }