org.netbeans.jemmy
Class ClassReference

java.lang.Object
  extended by org.netbeans.jemmy.ClassReference

public class ClassReference
extends Object

Allows access to classes by reflection.

Author:
Alexandre Iline (alexandre.iline@sun.com)

Constructor Summary
ClassReference(Object o)
          Constructor.
ClassReference(String className)
          Contructor.
 
Method Summary
 Class[] getClasses()
          Returns all superclasses.
 Object getField(String field_name)
          Returns the field value.
 Object invokeMethod(String method_name, Object[] params, Class[] params_classes)
          Locates method by name and parameter types and executes it.
 Object newInstance(Object[] params, Class[] params_classes)
          Locates constructor by parameter types and creates an instance.
 void setField(String field_name, Object newValue)
          Change a field's value.
 void startApplication()
          Executes class's main(java.lang.String[]) method with a zero-length java.lang.String array as a parameter.
 void startApplication(String[] params)
          Executes class's main(java.lang.String[]) method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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,
                             NoSuchMethodException
Executes class's main(java.lang.String[]) method with a zero-length java.lang.String array as a parameter.

Throws:
NoSuchMethodException
InvocationTargetException

startApplication

public void startApplication(String[] params)
                      throws InvocationTargetException,
                             NoSuchMethodException
Executes class's main(java.lang.String[]) method.

Parameters:
params - The java.lang.String array to pass to main(java.lang.String[]).
Throws:
NoSuchMethodException
InvocationTargetException

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.
If method_name method is void, null is returned.
If method_name method 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.
IllegalAccessException
NoSuchMethodException
InvocationTargetException

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.
IllegalAccessException
NoSuchMethodException
InstantiationException
InvocationTargetException

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.
IllegalAccessException
NoSuchFieldException
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.
IllegalAccessException
NoSuchFieldException
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.