org.progeeks.util
Class SimpleExpressionLanguage

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

public class SimpleExpressionLanguage
extends java.lang.Object

Enables a simple expression language that can be used to access object properties through PropertyAccess implementations. The expression language is based on a simple dot and index notation.

Examples:

foo.bar.baz:

foo.bar[12].baz:

foo\.bar[12].baz:

foo\\.bar[12].baz:

foo.bar\[12\].baz:

foo.bar[].baz:

Version:
$Revision: 1.8 $
Author:
Paul Speed

Nested Class Summary
static interface SimpleExpressionLanguage.ExpressionElement
           
static class SimpleExpressionLanguage.IndexedExpressionElement
           
static class SimpleExpressionLanguage.NamedExpressionElement
           
 
Constructor Summary
SimpleExpressionLanguage(PropertyAccess access)
           
 
Method Summary
protected static java.lang.String createSyntaxErrorMessage(java.lang.String value, int position)
           
 java.lang.String elementsToString(java.util.List expressions)
          Converts a list of ExpressionElements back to their unparsed form... basically, this is an "unparse" method.
 java.lang.Object getProperty(java.lang.Object object, java.util.List expressionElements)
          Uses a PropertyAccess object to access the value at the end of a sequence of nested properties specified by the pre-parsed list of expression elements.
 java.lang.Object getProperty(java.lang.Object object, java.lang.String expression)
          Uses a PropertyAccess object to access the value at the end of a sequence of nested properties specified by the string expression.
 java.lang.Class getPropertyClass(java.lang.Object object, java.util.List expressionElements)
          Uses a PropertyAccess object to access the property class at the end of a sequence of nested properties specified by the pre-parsed list of expression elements.
 java.lang.Class getPropertyClass(java.lang.Object object, java.lang.String expression)
          Uses a PropertyAccess object to access the property class at the end of a sequence of nested properties specified by the string expression.
static void main(java.lang.String[] args)
          For testing expression parsing as a command-line tool.
 java.util.List parseExpression(java.lang.String expression)
          Parses the expression and returns a list of elements found.
 void setProperty(java.lang.Object object, java.util.List expressionElements, java.lang.Object value)
          Uses bean introspection via org.progeeks.util.Inspector to access a sequence of nested properties specified by the string expression and set the last property in the chain.
 void setProperty(java.lang.Object object, java.lang.String expression, java.lang.Object value)
          Uses bean introspection via org.progeeks.util.Inspector to access a sequence of nested properties specified by the string expression and set the last property in the chain.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleExpressionLanguage

public SimpleExpressionLanguage(PropertyAccess access)
Method Detail

parseExpression

public java.util.List parseExpression(java.lang.String expression)
Parses the expression and returns a list of elements found. Otherwose, throws a RuntimeException.


getProperty

public java.lang.Object getProperty(java.lang.Object object,
                                    java.util.List expressionElements)
Uses a PropertyAccess object to access the value at the end of a sequence of nested properties specified by the pre-parsed list of expression elements. Returns the single value at the end of the chain. If the chain ends early then null is returned.


getProperty

public java.lang.Object getProperty(java.lang.Object object,
                                    java.lang.String expression)
Uses a PropertyAccess object to access the value at the end of a sequence of nested properties specified by the string expression. Returns the single value at the end of the chain. If the chain ends early then null is returned.


getPropertyClass

public java.lang.Class getPropertyClass(java.lang.Object object,
                                        java.util.List expressionElements)
Uses a PropertyAccess object to access the property class at the end of a sequence of nested properties specified by the pre-parsed list of expression elements. Returns the perceived property class at the end of the chain. If the chain ends early then null is returned.


getPropertyClass

public java.lang.Class getPropertyClass(java.lang.Object object,
                                        java.lang.String expression)
Uses a PropertyAccess object to access the property class at the end of a sequence of nested properties specified by the string expression. Returns the perceived property class at the end of the chain. If the chain ends early then null is returned.


setProperty

public void setProperty(java.lang.Object object,
                        java.lang.String expression,
                        java.lang.Object value)
Uses bean introspection via org.progeeks.util.Inspector to access a sequence of nested properties specified by the string expression and set the last property in the chain.


setProperty

public void setProperty(java.lang.Object object,
                        java.util.List expressionElements,
                        java.lang.Object value)
Uses bean introspection via org.progeeks.util.Inspector to access a sequence of nested properties specified by the string expression and set the last property in the chain.


elementsToString

public java.lang.String elementsToString(java.util.List expressions)
Converts a list of ExpressionElements back to their unparsed form... basically, this is an "unparse" method. It should be symetric too.
  String s =...;
  String t = elementsToString( parseExpression( s ) );
  s.equals(t) should be true.
  


createSyntaxErrorMessage

protected static java.lang.String createSyntaxErrorMessage(java.lang.String value,
                                                           int position)

main

public static void main(java.lang.String[] args)
For testing expression parsing as a command-line tool.



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