public class

Context

extends Object
java.lang.Object
   ↳ org.apache.commons.betwixt.expression.Context
Known Direct Subclasses

Class Overview

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.

Summary

Public Constructors
Context()
Construct context with default log
Context(Object bean, Log log)
This constructor is deprecated. 0.5 use constructor which takes a BindingConfiguration
Context(Object bean, Log log, BindingConfiguration bindingConfiguration)
Convenience constructor sets evaluted bean and log.
Context(Context context)
Construct a cloned context.
Context(Object bean, Map variables, Log log)
This constructor is deprecated. 0.5 use constructor which takes a converter
Context(Object bean, Map variables, Log log, BindingConfiguration bindingConfiguration)
Convenience constructor sets evaluted bean, context variables and log.
Public Methods
Object getBean()
Gets the current bean.
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.
String getInheritedOption(String name)
Gets the value of the first option with this name.
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.
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 popOptions()

Pops the current options from the stack.

void pushOptions(Options options)

Pushes the given Options onto the stack.

void setBean(Object bean)
Set the current bean.
void setClassNameAttribute(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(Log log)
Set the log implementation to which this class logs
void setValueSuppressionStrategy(ValueSuppressionStrategy valueSuppressionStrategy)
Sets the ValueSuppressionStrategy.
void setVariable(String name, Object value)
Sets the value of a particular context variable.
void setVariables(Map variables)
Sets context variables.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Context ()

Construct context with default log

public Context (Object bean, Log log)

This constructor is 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

public Context (Object bean, 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

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

public Context (Object bean, Map variables, Log log)

This constructor is 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

public Context (Object bean, Map variables, 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

Public Methods

public Object getBean ()

Gets the current bean.

Returns
  • the bean against which expressions are evaluated

public 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

public IdStoringStrategy getIdMappingStrategy ()

Gets the strategy used to manage storage and retrieval of id's.

Returns
  • Returns the idStoringStrategy, not null

public String getInheritedOption (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

public Log getLog ()

Gets the current log.

Returns
  • the implementation to which this class logs

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

public ObjectStringConverter getObjectStringConverter ()

Gets object <-> string converter.

Returns
  • the Converter to be used for conversions, not null

public Options getOptions ()

Gets the current Options.

Returns
  • Options that currently apply or null if there are no current options.

public ValueSuppressionStrategy getValueSuppressionStrategy ()

Gets the ValueSuppressionStrategy. This is used to control the expression of attributes with certain values.

Returns
  • ValueSuppressionStrategy, not null

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

public Map getVariables ()

Gets context variables.

Returns
  • map containing variable values keyed by variable name

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

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().

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

public void setBean (Object bean)

Set the current bean.

Parameters
bean the Object against which expressions will be evaluated

public void setClassNameAttribute (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

public void setLog (Log log)

Set the log implementation to which this class logs

Parameters
log the implemetation that this class should log to

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

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

public void setVariables (Map variables)

Sets context variables.

Parameters
variables map containing variable values indexed by varibable name Strings