Package org.netbeans.jemmy
Class ClassReference
- java.lang.Object
-
- org.netbeans.jemmy.ClassReference
-
public class ClassReference extends Object
Allows access to classes by reflection.- Author:
- Alexandre Iline (alexandre.iline@sun.com)
-
-
Constructor Summary
Constructors Constructor Description ClassReference(Object o)Constructor.ClassReference(String className)Contructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Class[]getClasses()Returns all superclasses.ObjectgetField(String field_name)Returns the field value.ObjectinvokeMethod(String method_name, Object[] params, Class[] params_classes)Locates method by name and parameter types and executes it.ObjectnewInstance(Object[] params, Class[] params_classes)Locates constructor by parameter types and creates an instance.voidsetField(String field_name, Object newValue)Change a field's value.voidstartApplication()Executes 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 Detail
-
ClassReference
public ClassReference(Object o)
Constructor.- Parameters:
o- Object to work with.
-
ClassReference
public ClassReference(String className) throws ClassNotFoundException
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 Detail
-
startApplication
public void startApplication() throws InvocationTargetException, NoSuchMethodExceptionExecutes 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
public Object getField(String field_name) throws NoSuchFieldException, IllegalAccessException
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(java.lang.String, java.lang.Object)
-
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:
getField(java.lang.String)
-
getClasses
public Class[] getClasses()
Returns all superclasses.- Returns:
- an array of superclasses, starting with the reference class
and ending with
java.lang.Object.
-
-