Class ClassReference
java.lang.Object
org.netbeans.jemmy.ClassReference
Allows access to classes by reflection.
- Author:
- Alexandre Iline (alexandre.iline@sun.com)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionClass[]Returns all superclasses.Returns the field value.invokeMethod(String method_name, Object[] params, Class[] params_classes) Locates method by name and parameter types and executes it.newInstance(Object[] params, Class[] params_classes) Locates constructor by parameter types and creates an instance.voidChange a field's value.voidExecutes class'smain(java.lang.String[])method with a zero-lengthjava.lang.Stringarray as a parameter.voidstartApplication(String[] params) Executes class'smain(java.lang.String[])method.
-
Constructor Details
-
ClassReference
-
ClassReference
Contructor. The object created by this constructor can be used to access static methods and fields only.- Parameters:
className- name of class- Throws:
ClassNotFoundException
-
-
Method Details
-
startApplication
Executes class'smain(java.lang.String[])method with a zero-lengthjava.lang.Stringarray as a parameter. -
startApplication
public void startApplication(String[] params) throws InvocationTargetException, NoSuchMethodException Executes class'smain(java.lang.String[])method.- Parameters:
params- Thejava.lang.Stringarray to pass tomain(java.lang.String[]).- Throws:
NoSuchMethodExceptionInvocationTargetException
-
invokeMethod
public Object invokeMethod(String method_name, Object[] params, Class[] params_classes) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException Locates method by name and parameter types and executes it.- Parameters:
method_name- Name of method.params- Method parameters.params_classes- Method parameters types.- Returns:
- the return value from an invocation of the Method.
Ifmethod_namemethod is void,nullis returned.
Ifmethod_namemethod returns a primitive type, then return wrapper class instance. - Throws:
InvocationTargetException- when the invoked method throws an exception.NoSuchMethodException- when the method cannot be found.IllegalAccessException- when access to the class or method is lacking.SecurityException- if access to the package or method is denied.IllegalAccessExceptionNoSuchMethodExceptionInvocationTargetException
-
newInstance
public Object newInstance(Object[] params, Class[] params_classes) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException, InstantiationException Locates constructor by parameter types and creates an instance.- Parameters:
params- An array of Method parameters.params_classes- An array of Method parameter types.- Returns:
- a new class instance.
- Throws:
InvocationTargetException- when the invoked constructor throws an exception.NoSuchMethodException- when the constructor cannot be found.IllegalAccessException- when access to the class or constructor is lacking.InstantiationException- when the constructor is for an abstract class.SecurityException- if access to the package or constructor is denied.IllegalAccessExceptionNoSuchMethodExceptionInstantiationExceptionInvocationTargetException
-
getField
Returns the field value.- Parameters:
field_name- The name of the field.- Returns:
- the field value
- Throws:
NoSuchFieldException- when the field cannot be found.IllegalAccessException- when access to the class or constructor is lacking.SecurityException- if access to the package or field is denied.IllegalAccessExceptionNoSuchFieldException- See Also:
-
setField
public void setField(String field_name, Object newValue) throws NoSuchFieldException, IllegalAccessException Change a field's value.- Parameters:
field_name- The name of the field.newValue- The fields new value.- Throws:
NoSuchFieldException- when the field cannot be found.IllegalAccessException- when access to the class or constructor is lacking.SecurityException- if access to the package or field is denied.IllegalAccessExceptionNoSuchFieldException- See Also:
-
getClasses
Returns all superclasses.- Returns:
- an array of superclasses, starting with the reference class
and ending with
java.lang.Object.
-