Wednesday 11 April 2007

API helper doc

API TESTER
Description:

It is used display all the public methods whose argument is other than collection or view in a class by giving input with the entire package structure
(i.e java.util.HashMap).

On selecting the particular method and clicking the Get Method button.

It leads to the receive input page where the text box will be displayed dynamically depending upon the no of arguments in the method.

On giving the values for the textbox it leads to the showResultpage where the result will be displayed.

If the received result is view ,it is iterator and displayed.

Implementation:
To get all the Method in a class:

Class inputClass = Class.forName(classPath);
Method methArr []= inputClass.getMethods();

using this it will display all the public methods available in a class

To find No of Arguments and its type in a method :

Method selectedMethod = methArr[methodPosition];
System.out.println(selectedMethod.getName());
selectedMethod.getParameterTypes().length;

this is used to display the textbox dynamically depending upon the no. of arguments in the selected method.

To convert to the value to theit corresponding parameter Type:

The given input value will always be a string.

This need to be typecast to their corresponding data type by

Here args[k] is the input value.

Object objArr[]=new Object[methodArgs.length];
for (int k = 0; k String argName = methodArgs[k].getName();
if (argName.endsWith(".Long") argName.equalsIgnoreCase("long")){ objArr[k] = Long.valueOf(args[k]);
}
Then the converted inputs are the stored in an object array (objArr).
To invoke the method:


Class inputClass = Class.forName(classPath);
Method methArr [] = inputClass.getMethods();
Method selectedMethod = methArr[methodPosition];
return selectedMethod.invoke(inputClass.newInstance(),objArr);

the selected method is called by invoke method by passing a object of a class and its paramater value as an object array.

Features:

1.Dynamically display the method available in a class.

2.Dynamically display the textbox for the input ,depending upon the no of argument in a method

Limitation:

1.If the returned value is collection it will not be iterated.
But the view can be iteratored.
2. collection or view cannot be given as input.

No comments: