pnuts.ext
Class ConfigurationAdapter

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

public class ConfigurationAdapter
extends Configuration

See Also:
Serialized Form

Field Summary
protected  Configuration base
           
 
Fields inherited from class pnuts.lang.Configuration
_add, _add1, _and, _divide, _eq, _ge, _gt, _le, _lt, _mod, _multiply, _negate, _not, _or, _shiftArithmetic, _shiftLeft, _shiftRight, _subtract, _subtract1, _xor, normalConfiguration
 
Constructor Summary
ConfigurationAdapter()
          Constructor
ConfigurationAdapter(Configuration base)
          Constructor
 
Method Summary
 java.lang.Object callConstructor(Context context, java.lang.Class c, java.lang.Object[] args, java.lang.Class[] types)
          Call a constructor.
 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)
          Call a method.
 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 target)
          String representation of an object
 java.lang.reflect.Constructor[] getConstructors(java.lang.Class cls)
          Get all public constructors of the specified class.
 java.lang.Object getElement(Context context, java.lang.Object target, java.lang.Object key)
          Gets an array element
 java.lang.Object getField(Context context, java.lang.Object target, java.lang.String name)
          Gets a field of the specified class.
 java.lang.reflect.Method[] getMethods(java.lang.Class cls)
          Get all public methods of the specified class.
 Configuration getParent()
          Returns the parent configuration
 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:
 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.
 java.lang.Object makeArray(java.lang.Object[] array, Context context)
          Return the value of an array expression.
 void putField(Context context, java.lang.Object target, java.lang.String name, java.lang.Object value)
          Sets a field of the specified class.
 void putStaticField(Context context, java.lang.Class clazz, java.lang.String name, java.lang.Object value)
          Sets a field of the specified class.
 void setElement(Context context, java.lang.Object target, java.lang.Object key, java.lang.Object value)
          Sets an array element
 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:
 Callable toCallable(java.lang.Object obj)
          Convert an object to Callable.
 java.util.Enumeration toEnumeration(java.lang.Object obj)
          Convert an object to Enumeration.
 
Methods inherited from class pnuts.lang.Configuration
createList, getDefault, getDefaultImports, getInitialClassLoader, initializeOperators, invokeMethod
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

base

protected Configuration base
Constructor Detail

ConfigurationAdapter

public ConfigurationAdapter()
Constructor


ConfigurationAdapter

public ConfigurationAdapter(Configuration base)
Constructor

Parameters:
base - the base configuration
Method Detail

getParent

public Configuration getParent()
Returns the parent configuration


getField

public java.lang.Object getField(Context context,
                                 java.lang.Object target,
                                 java.lang.String name)
Gets a field of the specified class.

Specified by:
getField in class Configuration
Parameters:
target - the target objecgt
name - the field name
context - the context in which the field is read
Returns:
the field value

putField

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

Specified by:
putField in class Configuration
Parameters:
context - the context in which the field is written.
target - the target objecgt
name - the field name
value - the field value

getStaticField

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

Specified by:
getStaticField in class Configuration
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 void putStaticField(Context context,
                           java.lang.Class clazz,
                           java.lang.String name,
                           java.lang.Object value)
Sets a field of the specified class.

Specified by:
putStaticField in class Configuration
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

callMethod

public 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)
Call a method.

Specified by:
callMethod in class Configuration
Parameters:
context - the context
c - the class of the target object
name - the name of the method
args - the arguments
types - the type information of arguments
target - the target of the method call
Returns:
the methods return value

callConstructor

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

Specified by:
callConstructor in class Configuration
Parameters:
args - the arguments
context - the context
c - class of the constructor
types - type information of each arguments
Returns:
the newly created and initialized object

getElement

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

Specified by:
getElement in class Configuration
Parameters:
target - the target object (an array)
key - a key or an index of the element
context - the context
Returns:
the value of the element

setElement

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

Specified by:
setElement in class Configuration
Parameters:
target - the target object (an array)
key - a key or an index of the element
value - the new value of the element
context - the context

getMethods

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

Specified by:
getMethods in class Configuration
Parameters:
cls - the class
Returns:
an array of Method objects

getConstructors

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

Specified by:
getConstructors in class Configuration
Parameters:
cls - the class
Returns:
an array of Constructor objects

toEnumeration

public 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.

Specified by:
toEnumeration in class Configuration

toCallable

public 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.

Specified by:
toCallable in class Configuration

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.

Overrides:
handleUndefinedSymbol in class Configuration
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[] array,
                                  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.

Overrides:
makeArray in class Configuration
Parameters:
array - the elements in the array expression
context - the context
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.

Overrides:
createMap in class Configuration
Parameters:
size - the map size
Returns:
a new Map object

formatObject

public java.lang.String formatObject(java.lang.Object target)
String representation of an object

Overrides:
formatObject in class Configuration
Parameters:
target - the target object to print
Returns:
the string representation of the target object

getRange

public 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]
  
 

Specified by:
getRange in class Configuration
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 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
  
 

Specified by:
setRange in class Configuration
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