org.apache.commons.betwixt.expression
Class Context

java.lang.Object
  extended byorg.apache.commons.betwixt.expression.Context

public class Context
extends Object

Context describes the context used to evaluate bean expressions. This is mostly a bean together with a number of context variables. Context variables are named objects. In other words, a context variable associates an object with a string.

Logging during expression evaluation is done through the logging instance held by this class. The object initiating the evaluation should control this logging and so passing a Log instance is enforced by the constructors.

Context is a natural place to include shared evaluation code. One of the problems that you get with object graphs is that they can be cyclic. Xml cannot (directly) include cycles. Therefore betwixt needs to find and deal properly with cycles. The algorithm used is to check the parentage of a new child. If the child is a parent then that operation fails.

Version:
$Revision: 1.4 $
Author:
James Strachan

Field Summary
private  Object bean
          Evaluate this bean
private  org.apache.commons.logging.Log log
          Logging uses commons-logging Log named org.apache.commons.betwixt
private  Map variables
          Variables map
 
Constructor Summary
Context()
          Construct context with default log
Context(Object bean, org.apache.commons.logging.Log log)
          Convenience constructor sets evaluted bean and log.
Context(Object bean, Map variables, org.apache.commons.logging.Log log)
          Convenience constructor sets evaluted bean, context variables and log.
 
Method Summary
 Object getBean()
          Gets the current bean.
 org.apache.commons.logging.Log getLog()
          Gets the current log.
 Object getVariable(String name)
          Gets the value of a particular context variable.
 Map getVariables()
          Gets context variables.
 Context newContext(Object newBean)
          Returns a new child context with the given bean but the same log and variables.
 void setBean(Object bean)
          Set the current bean.
 void setLog(org.apache.commons.logging.Log log)
          Set the log implementation to which this class logs
 void setVariable(String name, Object value)
          Sets the value of a particular context variable.
 void setVariables(Map variables)
          Sets context variables.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bean

private Object bean
Evaluate this bean


variables

private Map variables
Variables map


log

private org.apache.commons.logging.Log log
Logging uses commons-logging Log named org.apache.commons.betwixt

Constructor Detail

Context

public Context()
Construct context with default log


Context

public Context(Object bean,
               org.apache.commons.logging.Log log)
Convenience constructor sets evaluted bean and log.

Parameters:
bean - evaluate expressions against this bean
log - log to this logger

Context

public Context(Object bean,
               Map variables,
               org.apache.commons.logging.Log log)
Convenience constructor sets evaluted bean, context variables and log.

Parameters:
bean - evaluate expressions against this bean
variables - context variables
log - log to this logger
Method Detail

newContext

public Context newContext(Object newBean)
Returns a new child context with the given bean but the same log and variables.

Parameters:
newBean - create a child context for this bean
Returns:
new Context with new bean but shared variables

getBean

public Object getBean()
Gets the current bean.

Returns:
the bean against which expressions are evaluated

setBean

public void setBean(Object bean)
Set the current bean.

Parameters:
bean - the Object against which expressions will be evaluated

getVariables

public Map getVariables()
Gets context variables.

Returns:
map containing variable values keyed by variable name

setVariables

public void setVariables(Map variables)
Sets context variables.

Parameters:
variables - map containing variable values indexed by varibable name Strings

getVariable

public Object getVariable(String name)
Gets the value of a particular context variable.

Parameters:
name - the name of the variable whose value is to be returned
Returns:
the variable value or null if the variable isn't set

setVariable

public void setVariable(String name,
                        Object value)
Sets the value of a particular context variable.

Parameters:
name - the name of the variable
value - the value of the variable

getLog

public org.apache.commons.logging.Log getLog()
Gets the current log.

Returns:
the implementation to which this class logs

setLog

public void setLog(org.apache.commons.logging.Log log)
Set the log implementation to which this class logs

Parameters:
log - the implemetation that this class should log to