org.progeeks.util
Class TemplateExpressionProcessor

java.lang.Object
  extended by org.progeeks.util.TemplateExpressionProcessor

public class TemplateExpressionProcessor
extends java.lang.Object

Interacts with the SimpleExpressionLanguage to allow basic variable substitution within string template expressions. Expressions are specified with a syntax similar to what ANT uses for property references, ie: ${some.property}

Version:
$Revision: 1.13 $
Author:
Paul Speed

Nested Class Summary
protected static class TemplateExpressionProcessor.NestedExpressionElement
          A nested TemplateExpression within a TemplateExpression.
protected static class TemplateExpressionProcessor.ReferenceElement
          A variable reference within a TemplateExpression.
static class TemplateExpressionProcessor.TemplateExpression
          Represents a template expression string as a formal type that can be used to clarify method arguments, etc.
 
Field Summary
static java.lang.String[] STANDARD_EXAMPLES
           
 
Constructor Summary
TemplateExpressionProcessor(java.lang.Object target, SimpleExpressionLanguage el)
          Creates a new template processor that will operate on the specified target using the specified expression language for lookups.
TemplateExpressionProcessor(SimpleExpressionLanguage el)
          Creates an untargeted template processor that will use the specified SimpleExpressionLanguage for lookups.
 
Method Summary
 java.lang.Object evaluate(java.lang.String exp)
          Evaluates the specified template expression string and returns the value.
 java.lang.Object evaluate(TemplateExpressionProcessor.TemplateExpression exp)
          Evaluates the specified TemplateExpression and returns the value.
protected  java.lang.Object evaluateElement(java.lang.Object element)
          Evaluates a single element.
protected  java.lang.StringBuffer evaluateElements(java.util.List elements)
           
static java.lang.Object evaluateTemplateExpression(java.lang.String exp)
          Uses the thread's current context template processor to evaluate the specified template expression.
static java.lang.Object evaluateTemplateExpression(TemplateExpressionProcessor.TemplateExpression exp)
          Uses the thread's current context template processor to evaluate the specified template expression.
static TemplateExpressionProcessor getContextProcessor()
          Returns the thread's current context processor.
 SimpleExpressionLanguage getExpressionLanguage()
          Returns the expression language instance used to parse and evaluate embedded variable look-up expressions.
 java.lang.Object getTarget()
          Returns the target object used for embedded lookups.
protected  java.lang.Object lookupValue(java.lang.String expression)
          Used internally to calculate the value for a reference element.
static void main(java.lang.String[] args)
           
static void setContextProcessor(TemplateExpressionProcessor proc)
          Sets the thread's context processor.
 void setTarget(java.lang.Object target)
          Sets the target object used for embedded lookups.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STANDARD_EXAMPLES

public static final java.lang.String[] STANDARD_EXAMPLES
Constructor Detail

TemplateExpressionProcessor

public TemplateExpressionProcessor(SimpleExpressionLanguage el)
Creates an untargeted template processor that will use the specified SimpleExpressionLanguage for lookups.


TemplateExpressionProcessor

public TemplateExpressionProcessor(java.lang.Object target,
                                   SimpleExpressionLanguage el)
Creates a new template processor that will operate on the specified target using the specified expression language for lookups.

Method Detail

setContextProcessor

public static void setContextProcessor(TemplateExpressionProcessor proc)
Sets the thread's context processor.


getContextProcessor

public static TemplateExpressionProcessor getContextProcessor()
Returns the thread's current context processor.


lookupValue

protected java.lang.Object lookupValue(java.lang.String expression)
Used internally to calculate the value for a reference element. Can be overridden by subclasses to provide customized look-ups. The default implementation uses the processor's SimpleExpressionLanguage against the target object.


setTarget

public void setTarget(java.lang.Object target)
Sets the target object used for embedded lookups.


getTarget

public java.lang.Object getTarget()
Returns the target object used for embedded lookups.


getExpressionLanguage

public SimpleExpressionLanguage getExpressionLanguage()
Returns the expression language instance used to parse and evaluate embedded variable look-up expressions.


evaluateElement

protected java.lang.Object evaluateElement(java.lang.Object element)
Evaluates a single element.


evaluateElements

protected java.lang.StringBuffer evaluateElements(java.util.List elements)

evaluate

public java.lang.Object evaluate(TemplateExpressionProcessor.TemplateExpression exp)
Evaluates the specified TemplateExpression and returns the value.


evaluate

public java.lang.Object evaluate(java.lang.String exp)
Evaluates the specified template expression string and returns the value.


evaluateTemplateExpression

public static java.lang.Object evaluateTemplateExpression(TemplateExpressionProcessor.TemplateExpression exp)
Uses the thread's current context template processor to evaluate the specified template expression.


evaluateTemplateExpression

public static java.lang.Object evaluateTemplateExpression(java.lang.String exp)
Uses the thread's current context template processor to evaluate the specified template expression.


main

public static void main(java.lang.String[] args)


Copyright © 2002-2003 Paul Speed. All Rights Reserved.