com.taco.text
Class StringToBeanShellInstanceConverter

java.lang.Object
  extended by com.taco.text.AbstractStringToObjectConverter
      extended by com.taco.text.StringToInstanceConverter
          extended by com.taco.text.StringToBeanShellInstanceConverter
All Implemented Interfaces:
ICommonRegexConstants, IStringToObjectConverter, IObjectMapper, java.io.Serializable, java.lang.Cloneable

public class StringToBeanShellInstanceConverter
extends StringToInstanceConverter

A converter from a string that specifies an instance of an object to an object. The string may have the syntax as in StringToInstanceConverter, as well as be a BeanShell expression enclosed in '{' and '}'. Each conversion attempt uses a new BeanShell interpreter.

See Also:
Serialized Form

Field Summary
protected  java.util.Map _environment
          A map of variables to values to be put into the bean shell environment before execution.
protected  java.util.Collection _imports
          An ordered collection of strings which are the imports to be added to the bean shell environment before execution.
protected  java.util.Collection _staticImports
          An ordered collection of strings which are the static imports to be added to the bean shell environment before execution.
static StringToBeanShellInstanceConverter instance
          The singleton instance of this class, which does not impose any type constraint, does not put any variables in the BeanShell environment, and does not add any imports to the BeanShell environment.
 
Fields inherited from class com.taco.text.StringToInstanceConverter
_returnType
 
Fields inherited from interface com.taco.text.ICommonRegexConstants
BOOLEAN_REGEX_STRING, CHAR_REGEX_STRING, FLOAT_REGEX_STRING, HEX_NUMBER_REGEX_STRING, INTEGER_REGEX_STRING, JAVA_CLASS_NAME_REGEX_STRING, LONG_HEX_REGEX_STRING, LONG_INTEGER_REGEX_STRING, NON_NEGATIVE_FLOAT_REGEX_STRING, PROPERTY_PREFIX_PATTERN, PROPERTY_PREFIX_REGEX_STRING, QUOTED_STRING_REGEX_STRING, WHITESPACE_PATTERN
 
Constructor Summary
protected StringToBeanShellInstanceConverter()
          Construct an instance that does not impose a type constraint on returned objects, puts no variables into the BeanShell environment, and adds no imports to the BeanShell environment.
  StringToBeanShellInstanceConverter(java.lang.Class returnType)
          Construct an instance that imposes a type constraint on returned objects and puts no variables into the BeanShell environment.
  StringToBeanShellInstanceConverter(java.lang.Class returnType, java.util.Collection imports)
          Construct an instance that imposes a type constraint on returned objects.
  StringToBeanShellInstanceConverter(java.lang.Class returnType, java.util.Map environment)
          Construct an instance that imposes a type constraint on returned objects.
  StringToBeanShellInstanceConverter(java.lang.Class returnType, java.util.Map environment, java.util.Collection imports)
          Construct an instance that imposes a type constraint on returned objects.
  StringToBeanShellInstanceConverter(java.lang.Class returnType, java.util.Map environment, java.util.Collection imports, java.util.Collection staticImports)
          Construct an instance that imposes a type constraint on returned objects.
  StringToBeanShellInstanceConverter(java.util.Collection imports)
          Construct an instance that does not impose a type constraint on returned objects, puts no variables into the BeanShell environment.
  StringToBeanShellInstanceConverter(java.util.Map environment)
          Construct an instance that does not impose a type constraint on returned objects.
  StringToBeanShellInstanceConverter(java.util.Map environment, java.util.Collection imports)
          Construct an instance that does not impose a type constraint on returned objects.
 
Method Summary
protected  void _addImports(bsh.Interpreter interpreter)
          Add the return type and the imports in _imports to the argument BeanShell interpreter.
protected  void _addStaticImports(bsh.Interpreter interpreter)
          Add the static imports in _staticImports to the argument BeanShell interpreter.
protected  bsh.Interpreter _getInterpreter()
          Return a BeanShell interpreter suitable for evaluating a BeanShell expression.
protected  void _setEnvironment(bsh.Interpreter interpreter)
          Add the variables in _environment to the argument BeanShell interpreter.
protected  java.lang.Object _toObject(java.lang.String s)
          If the string starts with a brace, evaluate the string using the BeanShell intepreter returned by _getInterpreter().
 java.lang.Object clone()
           
 
Methods inherited from class com.taco.text.StringToInstanceConverter
_checkType, _parseInstanceString, _parseJavaLiteral, main, toObject
 
Methods inherited from class com.taco.text.AbstractStringToObjectConverter
map
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_environment

protected java.util.Map _environment
A map of variables to values to be put into the bean shell environment before execution.


_imports

protected java.util.Collection _imports
An ordered collection of strings which are the imports to be added to the bean shell environment before execution.


_staticImports

protected java.util.Collection _staticImports
An ordered collection of strings which are the static imports to be added to the bean shell environment before execution.


instance

public static final StringToBeanShellInstanceConverter instance
The singleton instance of this class, which does not impose any type constraint, does not put any variables in the BeanShell environment, and does not add any imports to the BeanShell environment.

Constructor Detail

StringToBeanShellInstanceConverter

protected StringToBeanShellInstanceConverter()
Construct an instance that does not impose a type constraint on returned objects, puts no variables into the BeanShell environment, and adds no imports to the BeanShell environment.


StringToBeanShellInstanceConverter

public StringToBeanShellInstanceConverter(java.util.Map environment)
Construct an instance that does not impose a type constraint on returned objects. Each key in environment is interpreted as a variable name, with a value which is the corresponding value in environment. All these variables are put into the BeanShell enviornment before it interprets expression strings. The environment is only referenced, so the caller must be sure not to modify it afterwards.


StringToBeanShellInstanceConverter

public StringToBeanShellInstanceConverter(java.lang.Class returnType)
Construct an instance that imposes a type constraint on returned objects and puts no variables into the BeanShell environment. The return type will be explicitly imported into the BeanShell environment before interpreting expression strings.


StringToBeanShellInstanceConverter

public StringToBeanShellInstanceConverter(java.util.Collection imports)
Construct an instance that does not impose a type constraint on returned objects, puts no variables into the BeanShell environment. If imports is not null, The strings in imports are also added to the BeanShell environment. No variables are set in the BeanShell environment.


StringToBeanShellInstanceConverter

public StringToBeanShellInstanceConverter(java.lang.Class returnType,
                                          java.util.Map environment)
Construct an instance that imposes a type constraint on returned objects. The return type will be explicitly imported into the BeanShell environment before interpreting expression strings. Each key in environment is interpreted as a variable name, with a value which is the corresponding value in environment. All these variables are put into the BeanShell environment before it interprets expression strings. The environment is only referenced, so the caller must be sure not to modify it afterwards. No additional imports are added to the BeanShell environment.


StringToBeanShellInstanceConverter

public StringToBeanShellInstanceConverter(java.lang.Class returnType,
                                          java.util.Collection imports)
Construct an instance that imposes a type constraint on returned objects. The return type will be explicitly imported into the BeanShell environment before interpreting expression strings. If imports is not null, The strings in imports are also added to the BeanShell environment. The imports are only referenced, so the caller must be sure not to modify them afterwards. No variables are set in the BeanShell environment.


StringToBeanShellInstanceConverter

public StringToBeanShellInstanceConverter(java.util.Map environment,
                                          java.util.Collection imports)
Construct an instance that does not impose a type constraint on returned objects. If imports is not null, The strings in imports are also added to the BeanShell environment. If environment is not null, each key in environment is interpreted as a variable name, with a value which is the corresponding value in environment. All these variables are put into the BeanShell environment before it interprets expression strings. The environment and the imports are only referenced, so the caller must be sure not to modify them afterwards.


StringToBeanShellInstanceConverter

public StringToBeanShellInstanceConverter(java.lang.Class returnType,
                                          java.util.Map environment,
                                          java.util.Collection imports)
Construct an instance that imposes a type constraint on returned objects. The return type will be explicitly imported into the BeanShell environment before interpreting expression strings. If imports is not null, The strings in imports are also added to the BeanShell environment. If environment is not null, each key in environment is interpreted as a variable name, with a value which is the corresponding value in environment. All these variables are put into the BeanShell environment before it interprets expression strings. The environment and the imports are only referenced, so the caller must be sure not to modify them afterwards.


StringToBeanShellInstanceConverter

public StringToBeanShellInstanceConverter(java.lang.Class returnType,
                                          java.util.Map environment,
                                          java.util.Collection imports,
                                          java.util.Collection staticImports)
Construct an instance that imposes a type constraint on returned objects. The return type will be explicitly imported into the BeanShell environment before interpreting expression strings. If imports is not null, The strings in imports are imported into the BeanShell environment. If staticImports is not null, The strings in staticImports are staticly imported into the BeanShell environment. If environment is not null, each key in environment is interpreted as a variable name, with a value which is the corresponding value in environment. All these variables are put into the BeanShell environment before it interprets expression strings. The environment, the imports, and the static imports are only referenced, so the caller must be sure not to modify them afterwards.

Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class StringToInstanceConverter
Throws:
java.lang.CloneNotSupportedException

_toObject

protected java.lang.Object _toObject(java.lang.String s)
                              throws java.text.ParseException
If the string starts with a brace, evaluate the string using the BeanShell intepreter returned by _getInterpreter(). Otherwise, use the superclass's implementation.

Overrides:
_toObject in class StringToInstanceConverter
Throws:
java.text.ParseException

_getInterpreter

protected bsh.Interpreter _getInterpreter()
Return a BeanShell interpreter suitable for evaluating a BeanShell expression. This method is called by _toObject() to get an interpreter after is determined that the string to convert is a BeanShell expression. This implementation constructs a new one, imports the return type, adds the imports in _imports, and sets the variables defined by _environment. Subclasses may choose to share interpreters by overriding this method.


_addImports

protected void _addImports(bsh.Interpreter interpreter)
Add the return type and the imports in _imports to the argument BeanShell interpreter.


_addStaticImports

protected void _addStaticImports(bsh.Interpreter interpreter)
Add the static imports in _staticImports to the argument BeanShell interpreter.


_setEnvironment

protected void _setEnvironment(bsh.Interpreter interpreter)
Add the variables in _environment to the argument BeanShell interpreter.