The behavior of field access, index access, and method/constructor call, and binary/unary operations can be customized by changing an attribute of a Context object.
A Configuration of a context can be set up with Context.setConfiguration(Configuration) method.
Context context = new Context(); context.setConfiguration(new NonPublicMemberAccessor()); ...
pnuts.lang.Configuration defines the default behavior of basic expressions. A subclass may override its methods to define its own behavior.
- public Object getField( Context context , Object target , String name );
- public void putField( Context context, Object target , String name, Object value );
- public Object getStaticField( Context context, Class target , String name );
- public void putStaticField( Context context, Class target , String name, Object value );
- public Object getElement( Context context, Object target , Object key );
- public void setElement( Context context , Object target , Object key, Object value);
- public Object callConstructor( Context context, Class c , Object[] args , Class[] types );
- public Object callMethod( Context context , Object target , Object[] args , Class[] types );
- protected BinaryOperator _add, _subtract, _multiply, _divide, _mod, _and, _or, _xor, _shiftLeft, _shiftRight, _shiftArithmetic;
- protected UnaryOperator _add1, _subtract1, _negate, _not;
- protected BooleanOperator _lt, _le, _gt, _ge, _eq;
The following classes are defined in pnuts.lang package, each of which defines a behavior of Java API access.
- pnuts.lang.Configuration
- The default configuration, which can access Beans proeprties, Beans methods, context-local variables, and pnuts.lang.Property's attributes. On Java2 platform, it can access Map entries as well.
- pnuts.ext.PublicMemberAccessor
- Same as the default configuration, except that it can access public members instead of Beans properties.
- pnuts.ext.NonPublicMemberAccessor
- It can access non-public methods and fields. It requires Java2 environment.
- pnuts.awt.EventQueueConfiguration
- Use AWT Event thread to access Java API.
If the system property, pnuts.lang.defaultConfiguraion, is a valid Configuration subclass when Pnuts API is first loaded, the specified Configuration is used as the default configuration.
For example, if the Pnuts interpreter is started as the following command line, all field access in the scripts will be interpreted as access to public members.
% java -Dpnuts.lang.defaultConfiguration=pnuts.lang.PublicMemberConfiguration pnuts.tools.MainSee also 'Setting up a Context'.
Since Java API accesses are likely to assume a particular configuration, scripts should be executed in the same configuration as the one which was used when the scripts were loaded. Therefore, function defined in a script is executed in the configuration in which the function is defined.