org.apache.commons.betwixt.expression
Class Context

java.lang.Object
  extended by org.apache.commons.betwixt.expression.Context
Direct Known Subclasses:
ReadContext

public class Context
extends java.lang.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.

Author:
James Strachan

Constructor Summary
Context()
          Construct context with default log
Context(Context context)
          Construct a cloned context.
Context(java.lang.Object bean, org.apache.commons.logging.Log log)
          Deprecated. 0.5 use constructor which takes a BindingConfiguration
Context(java.lang.Object bean, org.apache.commons.logging.Log log, BindingConfiguration bindingConfiguration)
          Convenience constructor sets evaluted bean and log.
Context(java.lang.Object bean, java.util.Map variables, org.apache.commons.logging.Log log)
          Deprecated. 0.5 use constructor which takes a converter
Context(java.lang.Object bean, java.util.Map variables, org.apache.commons.logging.Log log, BindingConfiguration bindingConfiguration)
          Convenience constructor sets evaluted bean, context variables and log.
 
Method Summary
 java.lang.Object getBean()
          Gets the current bean.
 java.lang.String getClassNameAttribute()
          The name of the attribute which can be specified in the XML to override the type of a bean used at a certain point in the schema.
 IdStoringStrategy getIdMappingStrategy()
          Gets the strategy used to manage storage and retrieval of id's.
 java.lang.String getInheritedOption(java.lang.String name)
          Gets the value of the first option with this name.
 org.apache.commons.logging.Log getLog()
          Gets the current log.
 boolean getMapIDs()
          Should ID's and IDREF attributes be used to cross-reference matching objects?
 ObjectStringConverter getObjectStringConverter()
          Gets object <-> string converter.
 Options getOptions()
          Gets the current Options.
 ValueSuppressionStrategy getValueSuppressionStrategy()
          Gets the ValueSuppressionStrategy.
 java.lang.Object getVariable(java.lang.String name)
          Gets the value of a particular context variable.
 java.util.Map getVariables()
          Gets context variables.
 Context newContext(java.lang.Object newBean)
          Returns a new child context with the given bean but the same log and variables.
 void popOptions()
          Pops the current options from the stack.
 void pushOptions(Options options)
          Pushes the given Options onto the stack.
 void setBean(java.lang.Object bean)
          Set the current bean.
 void setClassNameAttribute(java.lang.String classNameAttribute)
          Sets the name of the attribute which can be specified in the XML to override the type of a bean used at a certain point in the schema.
 void setLog(org.apache.commons.logging.Log log)
          Set the log implementation to which this class logs
 void setValueSuppressionStrategy(ValueSuppressionStrategy valueSuppressionStrategy)
          Sets the ValueSuppressionStrategy.
 void setVariable(java.lang.String name, java.lang.Object value)
          Sets the value of a particular context variable.
 void setVariables(java.util.Map variables)
          Sets context variables.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Context

public Context()
Construct context with default log


Context

public Context(java.lang.Object bean,
               org.apache.commons.logging.Log log)
Deprecated. 0.5 use constructor which takes a BindingConfiguration

Convenience constructor sets evaluted bean and log.

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

Context

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

Parameters:
bean - evaluate expressions against this bean
log - log to this logger
bindingConfiguration - not null

Context

public Context(Context context)
Construct a cloned context. The constructed context should share bean, variables, log and binding configuration.

Parameters:
context - duplicate the attributes of this bean

Context

public Context(java.lang.Object bean,
               java.util.Map variables,
               org.apache.commons.logging.Log log)
Deprecated. 0.5 use constructor which takes a converter

Convenience constructor sets evaluted bean, context variables and log.

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

Context

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

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

newContext

public Context newContext(java.lang.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 java.lang.Object getBean()
Gets the current bean.

Returns:
the bean against which expressions are evaluated

setBean

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

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

getVariables

public java.util.Map getVariables()
Gets context variables.

Returns:
map containing variable values keyed by variable name

setVariables

public void setVariables(java.util.Map variables)
Sets context variables.

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

getVariable

public java.lang.Object getVariable(java.lang.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(java.lang.String name,
                        java.lang.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

getObjectStringConverter

public ObjectStringConverter getObjectStringConverter()
Gets object <-> string converter.

Returns:
the Converter to be used for conversions, not null
Since:
0.5

getMapIDs

public boolean getMapIDs()
Should ID's and IDREF attributes be used to cross-reference matching objects?

Returns:
true if ID and IDREF attributes should be used to cross-reference instances
Since:
0.5

getClassNameAttribute

public java.lang.String getClassNameAttribute()
The name of the attribute which can be specified in the XML to override the type of a bean used at a certain point in the schema.

The default value is 'className'.

Returns:
The name of the attribute used to overload the class name of a bean
Since:
0.5

setClassNameAttribute

public void setClassNameAttribute(java.lang.String classNameAttribute)
Sets the name of the attribute which can be specified in the XML to override the type of a bean used at a certain point in the schema.

The default value is 'className'.

Parameters:
classNameAttribute - The name of the attribute used to overload the class name of a bean
Since:
0.5

getValueSuppressionStrategy

public ValueSuppressionStrategy getValueSuppressionStrategy()
Gets the ValueSuppressionStrategy. This is used to control the expression of attributes with certain values.

Returns:
ValueSuppressionStrategy, not null
Since:
0.7

setValueSuppressionStrategy

public void setValueSuppressionStrategy(ValueSuppressionStrategy valueSuppressionStrategy)
Sets the ValueSuppressionStrategy. This is used to control the expression of attributes with certain values.

Parameters:
valueSuppressionStrategy - ValueSuppressionStrategy, not null
Since:
0.7

getIdMappingStrategy

public IdStoringStrategy getIdMappingStrategy()
Gets the strategy used to manage storage and retrieval of id's.

Returns:
Returns the idStoringStrategy, not null
Since:
0.7

getOptions

public Options getOptions()
Gets the current Options.

Returns:
Options that currently apply or null if there are no current options.
Since:
0.7

pushOptions

public void pushOptions(Options options)

Pushes the given Options onto the stack.

Note that code calling push should ensure that popOptions() is called once the options are no longer current. This ensures that the previous options are reinstated.

Parameters:
options - newly current Options, not null
Since:
0.7

popOptions

public void popOptions()

Pops the current options from the stack. The previously current options (if any exist) will be reinstated by this method.

Note code calling this method should have previsouly called popOptions().

Since:
0.7

getInheritedOption

public java.lang.String getInheritedOption(java.lang.String name)
Gets the value of the first option with this name. The stack of inherited options is search (starting from the current option) until an option with a non-null value for the named option is found.

Parameters:
name - the name of the option to be found
Returns:
option value or null if this value is never set
Since:
0.8


Copyright © 2002-2008 The Apache Software Foundation. All Rights Reserved.