|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.objectwave.tools.MethodBuilder
This class is used to provide some rudimentary scripting capabilities. Supports... Arrays, local variables, direct field access, constructors,
Nested Class Summary | |
static class |
MethodBuilder.Test
Test case. |
Field Summary | |
static java.lang.Integer |
EOF
|
protected java.util.Hashtable |
variables
|
Constructor Summary | |
MethodBuilder()
Create a new instance and initialize two 'global' variables of "System" and "Class". |
Method Summary | |
protected boolean |
addMethod(java.lang.String className,
java.lang.String methodName,
java.lang.String key,
java.lang.Class[] types)
Define a method in our list of methods. |
void |
configure(java.util.Properties p)
Configure the MethodBuilder with property information. |
void |
defineMethods(java.io.LineNumberReader rdr)
By default, the key to the method list is the method name. |
void |
defineMethods(java.lang.String fileName)
Define methods of the format ClassName.methodName(parameterType, parameterType) |
protected java.lang.Object |
determineVarValue(java.lang.String varDecl,
java.io.LineNumberReader rdr,
java.lang.Object obj,
int[] idxHldr)
|
protected java.lang.Object |
doCalculation(java.lang.String varDecl)
The parameter may be math that needs to be processed. |
protected java.lang.String |
firstNonBlankLine(java.lang.String varDecl,
java.io.LineNumberReader rdr)
Starting with the varDecl parameter, find the fist non blank line in the rdr. |
protected java.lang.Class[] |
getArgumentTypes(java.lang.String line)
Extract all of the fully qualified class names separated by a ',' and turn them into classes. |
protected java.lang.reflect.Field |
getFieldFor(java.lang.String fieldName,
java.lang.Object obj)
Find the field specified in the object. |
protected java.lang.Object |
getFieldReference(java.lang.String varDecl,
int idx,
java.lang.Object targetObject)
Get the value represented by this string. |
java.lang.Object[] |
getLastMethod()
The last method invoked and arguments that were supplied. |
protected java.lang.reflect.Method |
getMethod(java.lang.String methodKey,
java.lang.String methodName,
java.lang.Object obj)
Look for a declared method at that method key. |
protected java.lang.Object[] |
getMethodArgs(java.io.LineNumberReader rdr,
java.lang.String firstLine,
java.lang.Class[] types,
java.lang.Object obj)
Get the object values that are to be the parameters to the method. |
protected java.lang.reflect.Method |
getMethodByName(java.lang.Class c,
java.lang.String methodName)
First, look for a method that takes no arguments with that method name. |
protected void |
initializePrintMethods()
Common methods that should not require definition by the user. |
protected java.lang.Object |
invokeConstructor(java.io.LineNumberReader rdr,
java.lang.String className,
java.lang.String parameterString,
java.lang.Object obj)
Invoke a constrcutor to create a new instance. |
java.lang.Object |
invokeMethod(java.lang.Object obj,
java.io.LineNumberReader rdr)
Invoke a method upon the target object. |
protected java.lang.Object |
invokeMethod(java.lang.Object obj,
java.io.LineNumberReader rdr,
java.lang.String firstLine,
int idx)
Actually invoke the method. |
protected java.lang.Class |
primitiveClass(java.lang.String className)
Get the primitive version of the className. |
protected void |
setFieldReference(java.lang.String key,
int idx,
java.lang.Object value)
Set the field reference to the parameter value. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.util.Hashtable variables
public static final java.lang.Integer EOF
Constructor Detail |
public MethodBuilder()
Method Detail |
protected boolean addMethod(java.lang.String className, java.lang.String methodName, java.lang.String key, java.lang.Class[] types) throws java.lang.ClassNotFoundException
className
- The class upon which the method is declared.methodName
- The name of the method.key
- The key for the method cache.types
- The method parameter classes.
java.lang.ClassNotFoundException
public void configure(java.util.Properties p) throws java.io.IOException, java.lang.ClassNotFoundException, java.io.FileNotFoundException
p
- java.util.Properties The source of the property information.
java.io.IOException
java.lang.ClassNotFoundException
java.io.FileNotFoundException
public void defineMethods(java.lang.String fileName) throws java.io.IOException, java.lang.ClassNotFoundException, java.io.FileNotFoundException
fileName
- String Name of a file that contains methodDefinitions.
java.io.IOException
java.lang.ClassNotFoundException
java.io.FileNotFoundException
defineMethods(java.io.LineNumberReader)
public void defineMethods(java.io.LineNumberReader rdr) throws java.lang.ClassNotFoundException, java.io.IOException
rdr
-
java.lang.ClassNotFoundException
java.io.IOException
protected java.lang.Object determineVarValue(java.lang.String varDecl, java.io.LineNumberReader rdr, java.lang.Object obj, int[] idxHldr) throws java.io.IOException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.NoSuchFieldException
varDecl
- rdr
- obj
- idxHldr
-
java.io.IOException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.NoSuchFieldException
protected java.lang.Object doCalculation(java.lang.String varDecl) throws java.text.ParseException
varDecl
- String Perhaps math. Ex. "x + 10".
java.text.ParseException
- The provided string is not a
mathematical formula.protected java.lang.String firstNonBlankLine(java.lang.String varDecl, java.io.LineNumberReader rdr) throws java.io.IOException
varDecl
- A line already read from the rdr.rdr
- The source of additional lines of data.
java.io.IOException
protected java.lang.Class[] getArgumentTypes(java.lang.String line) throws java.lang.ClassNotFoundException
line
- String A line of argument types. Ex. "java.lang.String, int,
float" Three arguments with two primitive classes.
java.lang.ClassNotFoundException
protected java.lang.reflect.Field getFieldFor(java.lang.String fieldName, java.lang.Object obj) throws java.lang.NoSuchFieldException, java.lang.IllegalAccessException
fieldName
- String name of an attribute.obj
- The object containing the field.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
protected java.lang.Object getFieldReference(java.lang.String varDecl, int idx, java.lang.Object targetObject)
varDecl
- A string that may be a field reference. Ex. aValue.aFieldidx
- The index of the period in the varDecl parameter.targetObject
-
public java.lang.Object[] getLastMethod()
protected java.lang.reflect.Method getMethod(java.lang.String methodKey, java.lang.String methodName, java.lang.Object obj) throws java.lang.NoSuchMethodException
methodKey
- java.lang.String The key used in the dictionary.methodName
- Name of the method for which we are searching.obj
- The object we expect to have the target method.
java.lang.NoSuchMethodException
protected java.lang.Object[] getMethodArgs(java.io.LineNumberReader rdr, java.lang.String firstLine, java.lang.Class[] types, java.lang.Object obj) throws java.io.IOException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.NoSuchFieldException
rdr
- The source to read more lines if necessary.types
- Expected types of the parameters.firstLine
- obj
-
java.io.IOException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.lang.NoSuchFieldException
protected java.lang.reflect.Method getMethodByName(java.lang.Class c, java.lang.String methodName)
c
- java.lang.Class The class upon which we are searching for a
method.methodName
- java.lang.String Name of method for which we are to look
protected void initializePrintMethods()
protected java.lang.Object invokeConstructor(java.io.LineNumberReader rdr, java.lang.String className, java.lang.String parameterString, java.lang.Object obj) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException, java.io.IOException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.NoSuchFieldException
rdr
- The source of the script data.className
- The fully qualified name of the class we are constructing.parameterString
- Potential parameters for the constructor.obj
- The object that is the current target of the method builder.
java.lang.reflect.InvocationTargetException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.io.IOException
java.lang.NoSuchMethodException
java.lang.NoSuchFieldException
protected java.lang.Object invokeMethod(java.lang.Object obj, java.io.LineNumberReader rdr, java.lang.String firstLine, int idx) throws java.io.IOException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.NoSuchFieldException
firstLine
- The first line has likely been read already, so it is
passed into this method.idx
- The index of the '(' character.rdr
- LineNumberReader Source from which this can get more
information.obj
- The target object.
java.lang.reflect.InvocationTargetException
- An exception during the method
invocation.
java.io.IOException
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.NoSuchFieldException
public java.lang.Object invokeMethod(java.lang.Object obj, java.io.LineNumberReader rdr) throws java.io.IOException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.NoSuchFieldException
rdr
- java.io.LineNumberReader The source from which this class will
read data to determine what methods to invoke.obj
- Object the target object.
java.lang.reflect.InvocationTargetException
- An exception during the reflected
invocation.
java.io.IOException
java.lang.NoSuchMethodException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.lang.NoSuchFieldException
protected java.lang.Class primitiveClass(java.lang.String className)
className
- String potentionally representing a primivitive value.
Such as "int".
protected void setFieldReference(java.lang.String key, int idx, java.lang.Object value) throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException
value
- Object to be set.idx
- The index of the period in the varDecl parameter.key
- The new fieldReference value
java.lang.IllegalAccessException
java.lang.NoSuchFieldException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |