pnuts.lang
Class Configuration

java.lang.Object
  extended by pnuts.lang.Configuration
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ConfigurationAdapter, JavaBeansConfiguration

public abstract class Configuration
extends java.lang.Object
implements java.io.Serializable

This class defines the interface of runtime configuration, such as how to find method/field candidates, how to get the field value, how to get indexed elements, and so on.

See Also:
Serialized Form

Field Summary
protected  BinaryOperator _add
          object1 + object2
protected  UnaryOperator _add1
          object++, ++object
protected  BinaryOperator _and
          object1 & object2
protected  BinaryOperator _divide
          object1 / object2
protected  BooleanOperator _eq
          object1 == object2
protected  BooleanOperator _ge
          object1 >= object2
protected  BooleanOperator _gt
          object1 > object2
protected  BooleanOperator _le
          object1 <= object2
protected  BooleanOperator _lt
          object1 < object2
protected  BinaryOperator _mod
          object1 % object2
protected  BinaryOperator _multiply
          object1 * object2
protected  UnaryOperator _negate
          - object
protected  UnaryOperator _not
          ~object
protected  BinaryOperator _or
          object1 | object2
protected  BinaryOperator _shiftArithmetic
          object1 >>> object2
protected  BinaryOperator _shiftLeft
          object1 < < object2
protected  BinaryOperator _shiftRight
          object1 >> object2
protected  BinaryOperator _subtract
          object1 - object2
protected  UnaryOperator _subtract1
          object--, object--
protected  BinaryOperator _xor
          object1 ^ object2
protected static Configuration normalConfiguration
          The normal configuration, which is the fall-back of the default configuration.
 
Constructor Summary
Configuration()
           
 
Method Summary
abstract  java.lang.Object callConstructor(Context context, java.lang.Class c, java.lang.Object[] args, java.lang.Class[] types)
          Calls a constructor
abstract  java.lang.Object callMethod(Context context, java.lang.Class c, java.lang.String name, java.lang.Object[] args, java.lang.Class[] types, java.lang.Object target)
          Calls a method
 java.util.List createList()
           
 java.util.Map createMap(int size, Context context)
          Create a new Map object that corresponds to {key=>value} expression.
 java.lang.String formatObject(java.lang.Object obj)
          Defines how objects are printed in the interactive shell.
abstract  java.lang.reflect.Constructor[] getConstructors(java.lang.Class cls)
          Get all public constructors of the specified class.
static Configuration getDefault()
          Returns the default Configuration object.
protected  java.lang.String[] getDefaultImports()
          Subclasses may redefines default imports
abstract  java.lang.Object getElement(Context context, java.lang.Object target, java.lang.Object key)
          Gets an array element
abstract  java.lang.Object getField(Context context, java.lang.Object target, java.lang.String name)
          Gets a field value of the target object.
protected  java.lang.ClassLoader getInitialClassLoader()
           
abstract  java.lang.reflect.Method[] getMethods(java.lang.Class cls)
          Get all public methods of the specified class.
abstract  java.lang.Object getRange(Context context, java.lang.Object target, java.lang.Object idx1, java.lang.Object idx2)
          Defines the semantices of an expression like:
abstract  java.lang.Object getStaticField(Context context, java.lang.Class clazz, java.lang.String name)
          Get the value of a static field.
 java.lang.Object handleUndefinedSymbol(java.lang.String symbol, Context context)
          Handle an "not.defined" error This method can be redefined by a subclass so that a special value (e.g.
protected  void initializeOperators()
           
protected static java.lang.Object invokeMethod(Context context, java.lang.Class c, java.lang.String name, java.lang.Object[] args, java.lang.Class[] types, java.lang.Object target)
           
 java.lang.Object makeArray(java.lang.Object[] parameters, Context context)
          Return the value of an array expression.
abstract  void putField(Context context, java.lang.Object target, java.lang.String name, java.lang.Object value)
          Sets a field value of the specified object.
abstract  void putStaticField(Context context, java.lang.Class clazz, java.lang.String name, java.lang.Object value)
          Sets a value to the static field of the specified class.
abstract  void setElement(Context context, java.lang.Object target, java.lang.Object key, java.lang.Object value)
          Sets an element
abstract  java.lang.Object setRange(Context context, java.lang.Object target, java.lang.Object idx1, java.lang.Object idx2, java.lang.Object value)
          Defines the semantices of an expression like:
abstract  Callable toCallable(java.lang.Object obj)
          Convert an object to Callable.
abstract  java.util.Enumeration toEnumeration(java.lang.Object obj)
          Convert an object to Enumeration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

normalConfiguration

protected static final Configuration normalConfiguration
The normal configuration, which is the fall-back of the default configuration.


_add

protected BinaryOperator _add
object1 + object2


_subtract

protected BinaryOperator _subtract
object1 - object2


_multiply

protected BinaryOperator _multiply
object1 * object2


_mod

protected BinaryOperator _mod
object1 % object2


_divide

protected BinaryOperator _divide
object1 / object2


_shiftArithmetic

protected BinaryOperator _shiftArithmetic
object1 >>> object2


_shiftLeft

protected BinaryOperator _shiftLeft
object1 < < object2


_shiftRight

protected BinaryOperator _shiftRight
object1 >> object2


_and

protected BinaryOperator _and
object1 & object2


_or

protected BinaryOperator _or
object1 | object2


_xor

protected BinaryOperator _xor
object1 ^ object2


_add1

protected UnaryOperator _add1
object++, ++object


_subtract1

protected UnaryOperator _subtract1
object--, object--


_not

protected UnaryOperator _not
~object


_negate

protected UnaryOperator _negate
- object


_eq

protected BooleanOperator _eq
object1 == object2


_lt

protected BooleanOperator _lt
object1 < object2


_le

protected BooleanOperator _le
object1 <= object2


_gt

protected BooleanOperator _gt
object1 > object2


_ge

protected BooleanOperator _ge
object1 >= object2

Constructor Detail

Configuration

public Configuration()
Method Detail

getDefault

public static Configuration getDefault()
Returns the default Configuration object.

Returns:
the current default configuration

getDefaultImports

protected java.lang.String[] getDefaultImports()
Subclasses may redefines default imports

Returns:
an array of imported classes, package, or statics

initializeOperators

protected void initializeOperators()

getStaticField

public abstract java.lang.Object getStaticField(Context context,
                                                java.lang.Class clazz,
                                                java.lang.String name)
Get the value of a static field.

Parameters:
context - the context in which the field is accessed
clazz - the class in which the static field is defined
name - the name of the static field
Returns:
the value

putStaticField

public abstract void putStaticField(Context context,
                                    java.lang.Class clazz,
                                    java.lang.String name,
                                    java.lang.Object value)
Sets a value to the static field of the specified class.

Parameters:
context - the context in which the field is written.
clazz - the class in which the static field is defined
name - the field name
value - the field value

getElement

public abstract java.lang.Object getElement(Context context,
                                            java.lang.Object target,
                                            java.lang.Object key)
Gets an array element

Parameters:
context - the context
target - the target object (an array)
key - the key or the index of the element
Returns:
the value of the element

setElement

public abstract void setElement(Context context,
                                java.lang.Object target,
                                java.lang.Object key,
                                java.lang.Object value)
Sets an element

Parameters:
context - the context
target - the target object (an array)
key - the key or the index of the element
value - the new value of the element

callMethod

public abstract java.lang.Object callMethod(Context context,
                                            java.lang.Class c,
                                            java.lang.String name,
                                            java.lang.Object[] args,
                                            java.lang.Class[] types,
                                            java.lang.Object target)
Calls a method

Parameters:
context - the contexct
c - the class of the method
name - the name of the method
args - arguments
types - type information of each arguments
target - the target object of the method call
Returns:
the result of the method call

callConstructor

public abstract java.lang.Object callConstructor(Context context,
                                                 java.lang.Class c,
                                                 java.lang.Object[] args,
                                                 java.lang.Class[] types)
Calls a constructor

Parameters:
context - the context
c - class of the constructor
args - the arguments
types - type information of each arguments
Returns:
the result

getMethods

public abstract java.lang.reflect.Method[] getMethods(java.lang.Class cls)
Get all public methods of the specified class.

Parameters:
cls - the class
Returns:
an array of Method objects

getConstructors

public abstract java.lang.reflect.Constructor[] getConstructors(java.lang.Class cls)
Get all public constructors of the specified class.

Parameters:
cls - the class
Returns:
an array of Constructor objects

getRange

public abstract java.lang.Object getRange(Context context,
                                          java.lang.Object target,
                                          java.lang.Object idx1,
                                          java.lang.Object idx2)
Defines the semantices of an expression like:
 
  target[idx1..idx2]
  
 

Parameters:
context - the context
target - the target object
idx1 - the start index
idx2 - the end index. null in idx2 means open-ended.
Returns:
the result

setRange

public abstract java.lang.Object setRange(Context context,
                                          java.lang.Object target,
                                          java.lang.Object idx1,
                                          java.lang.Object idx2,
                                          java.lang.Object value)
Defines the semantices of an expression like:
 
  target[idx1..idx2] = value
  
 

Parameters:
context - the context in which the assignment is done
target - the target object
idx1 - the start index
idx2 - the end index. null in idx2 means open-ended.
value - the new value of the indexed element
Returns:
the result

getField

public abstract java.lang.Object getField(Context context,
                                          java.lang.Object target,
                                          java.lang.String name)
Gets a field value of the target object.

Parameters:
context - the context in which the field is read
target - the target object
name - the field name
Returns:
the field value

putField

public abstract void putField(Context context,
                              java.lang.Object target,
                              java.lang.String name,
                              java.lang.Object value)
Sets a field value of the specified object.

Parameters:
context - the context in which the field is written.
target - the target object
name - the field name
value - the field value

toEnumeration

public abstract java.util.Enumeration toEnumeration(java.lang.Object obj)
Convert an object to Enumeration. This method is used by foreach statements. Subclasses can override this method to customize the behavior of foreach statements.


toCallable

public abstract Callable toCallable(java.lang.Object obj)
Convert an object to Callable. This method is used by call expression, e.g. obj(arg1, ...). Subclasses can override this method to register custom callable objects.


handleUndefinedSymbol

public java.lang.Object handleUndefinedSymbol(java.lang.String symbol,
                                              Context context)
Handle an "not.defined" error This method can be redefined by a subclass so that a special value (e.g. null) is returned when undefined symbol is referenced.

Parameters:
symbol - the undefined symbol
context - the context in which the symbol is referenced
Returns:
the value to be returned

makeArray

public java.lang.Object makeArray(java.lang.Object[] parameters,
                                  Context context)
Return the value of an array expression. e.g. [a,b,c] {1,2,3} This method can be redefined by a subclass so that array expression returns different type of object, such as java.util.List.

Parameters:
parameters - the elements in the array expression
Returns:
the value of the array expression

createMap

public java.util.Map createMap(int size,
                               Context context)
Create a new Map object that corresponds to {key=>value} expression.

Parameters:
size - the map size
Returns:
a new Map object

createList

public java.util.List createList()

formatObject

public java.lang.String formatObject(java.lang.Object obj)
Defines how objects are printed in the interactive shell.

Parameters:
obj - the target object to print
Returns:
the string representation of the target object

invokeMethod

protected static java.lang.Object invokeMethod(Context context,
                                               java.lang.Class c,
                                               java.lang.String name,
                                               java.lang.Object[] args,
                                               java.lang.Class[] types,
                                               java.lang.Object target)

getInitialClassLoader

protected java.lang.ClassLoader getInitialClassLoader()