net.christopherschultz.evaluator.util
Class DefaultEvaluationContext

java.lang.Object
  extended by net.christopherschultz.evaluator.util.DefaultEvaluationContext
All Implemented Interfaces:
EvaluationContext
Direct Known Subclasses:
ChainedEvaluationContext

public class DefaultEvaluationContext
extends Object
implements EvaluationContext

Contains important information about the current expression evaluation.

Using the loadStandard() method, you can have this EvaluationContext load "standard" functions and constants into the context from the file EvaluationContext.properties. Using the load(ResourceBundle) or load(Map) methods, you can load those constants and function definitions from arbitrary sources.

I also might need some flags, like, 'should a NULL return object result in the expression evaluation terminating, returning nulls until the final return?'. That would be useful for when you want to vail out in the case that one of your functions returns null denoting that the expression cannot currently be evaluated.

Version:
$Revision: 1.6 $ $Date: 2008-06-20 22:58:48 $
Author:
Chris Schultz

Constructor Summary
DefaultEvaluationContext()
           Creates a new EvaluationContext.
 
Method Summary
 Object get(String identifier)
          Gets the value of the specified identifier.
 Map getAll()
          Returns a Map of all bound identifiers and their values.
 Object getProperty(String key)
          Gets the specified property.
 void load(Map props)
           
 void load(ResourceBundle bundle)
           
 EvaluationContext loadStandard()
           
 Object remove(String identifier)
          Removes the value of an identifier.
 void removeProperty(Object key)
          Removes the specified property.
 Object set(String identifier, Object value)
          Sets the value of the specified identifer to the given value.
 void setProperty(String key, Object value)
          Sets the specified property to the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultEvaluationContext

public DefaultEvaluationContext()

Creates a new EvaluationContext.

Note that no functions, constants, etc. will be defined in this EvaluationContext. If you want to load all the "standard" functions and constants, as defined by EvaluationContext.properties, then call the loadStandard() method. If you want to load your own functions, constants, and properties, then use load(ResourceBundle) or load(Map).

Method Detail

get

public Object get(String identifier)
Gets the value of the specified identifier.

Specified by:
get in interface EvaluationContext
Parameters:
identifier - The identifier for the value.
Returns:
The value of the specified value.

getAll

public Map getAll()
Returns a Map of all bound identifiers and their values. The Map is not modifiable.

Specified by:
getAll in interface EvaluationContext
Returns:
A Map of all identifiers as keys and their values as the values of the Map.

set

public Object set(String identifier,
                  Object value)
Sets the value of the specified identifer to the given value.

Specified by:
set in interface EvaluationContext
Parameters:
identifier - The identifier for the value.
value - The value for the identifier.
Returns:
The value object.

remove

public Object remove(String identifier)
Description copied from interface: EvaluationContext
Removes the value of an identifier.

Specified by:
remove in interface EvaluationContext
Parameters:
identifier - The identifier whose value should be removed.
Returns:
The old value of the object, or null if there was no value.

setProperty

public void setProperty(String key,
                        Object value)
Sets the specified property to the given value.

Specified by:
setProperty in interface EvaluationContext
Parameters:
key - The name of the property.
value - The value of the property.

getProperty

public Object getProperty(String key)
Gets the specified property.

Specified by:
getProperty in interface EvaluationContext
Parameters:
key - The name of the property.
Returns:
The value of the specified property.

removeProperty

public void removeProperty(Object key)
Removes the specified property.

Specified by:
removeProperty in interface EvaluationContext
Parameters:
key - The name of the property to remove.

loadStandard

public EvaluationContext loadStandard()

load

public void load(ResourceBundle bundle)

load

public void load(Map props)