|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectariba.util.expr.Expr
public abstract class Expr
This class provides static methods for parsing and interpreting AribaExpr expressions.
The simplest use of the Expr class is to get the value of an expression from an object, without extra context or pre-parsing.
import ariba.util.expr.Expr; import ariba.util.expr.ExprException; try { result = Expr.getValue(expression, root); } catch (ExprException ex) { // Report error or recover }
This will parse the expression given and evaluate it against the root object
given, returning the result. If there is an error in the expression, such
as the property is not found, the exception is encapsulated into an
ExprException
.
Other more sophisticated uses of Expr can pre-parse expressions. This
provides two advantages: in the case of user-supplied expressions it
allows you to catch parse errors before evaluation and it allows you to
cache parsed expressions into an AST for better speed during repeated use.
The pre-parsed expression is always returned as an Object
to simplify use for programs that just wish to store the value for
repeated use and do not care that it is an AST. If it does care
it can always safely cast the value to an AST
type.
The Expr class also takes a context map as one of the parameters
to the set and get methods. This allows you to put your own variables
into the available namespace for AribaExpr expressions. The default context
contains only the THIS
and #context
keys,
which are required to be present. The addDefaultContext(Object, Map)
method will alter an existing Map
to put the defaults in.
Here is an example that shows how to extract the documentName
property out of the root object and append a string with the current user
name in parens:
private Map context = new HashMap(); public void setUserName(String value) { context.put("userName", value); } try { // get value using our own custom context map result = Expr.getValue("documentName + \" (\" + ((#userName == null) ? \"<nobody>\" : #userName) + \")\"", context, root); } catch (ExprException ex) { // Report error or recover }
Method Summary | |
---|---|
static java.util.Map |
addDefaultContext(java.lang.Object root,
ClassResolver classResolver,
java.util.Map context)
Appends the standard naming context for evaluating an AribaExpr expression into the context given so that cached maps can be used as a context. |
static java.util.Map |
addDefaultContext(java.lang.Object root,
ClassResolver classResolver,
TypeConverter converter,
java.util.Map context)
Appends the standard naming context for evaluating an AribaExpr expression into the context given so that cached maps can be used as a context. |
static java.util.Map |
addDefaultContext(java.lang.Object root,
ClassResolver classResolver,
TypeConverter converter,
MemberAccess memberAccess,
java.util.Map context)
Appends the standard naming context for evaluating an AribaExpr expression into the context given so that cached maps can be used as a context. |
static java.util.Map |
addDefaultContext(java.lang.Object root,
java.util.Map context)
Appends the standard naming context for evaluating an AribaExpr expression into the context given so that cached maps can be used as a context. |
static java.util.Map |
createDefaultContext(java.lang.Object root)
Creates and returns a new standard naming context for evaluating an AribaExpr expression. |
static java.util.Map |
createDefaultContext(java.lang.Object root,
ClassResolver classResolver)
Creates and returns a new standard naming context for evaluating an AribaExpr expression. |
static java.util.Map |
createDefaultContext(java.lang.Object root,
ClassResolver classResolver,
TypeConverter converter)
Creates and returns a new standard naming context for evaluating an AribaExpr expression. |
static java.util.Map |
createDefaultContext(java.lang.Object root,
ClassResolver classResolver,
TypeConverter converter,
MemberAccess memberAccess)
Creates and returns a new standard naming context for evaluating an AribaExpr expression. |
static java.util.Map |
createDefaultContext(java.lang.Object root,
SymbolTable symbolTable)
Creates and returns a new standard naming context for evaluating an AribaExpr expression. |
static ClassResolver |
getClassResolver(java.util.Map context)
|
static Evaluation |
getLastEvaluation(java.util.Map context)
|
static MemberAccess |
getMemberAccess(java.util.Map context)
|
static java.lang.Object |
getRoot(java.util.Map context)
|
static TypeConverter |
getTypeConverter(java.util.Map context)
|
static java.lang.Object |
getValue(java.lang.Object tree,
java.util.Map context,
java.lang.Object root)
Evaluates the given AribaExpr expression tree to extract a value from the given root object. |
static java.lang.Object |
getValue(java.lang.Object tree,
java.util.Map context,
java.lang.Object root,
java.lang.Class resultType)
Evaluates the given AribaExpr expression tree to extract a value from the given root object. |
static java.lang.Object |
getValue(java.lang.Object tree,
java.lang.Object root)
Evaluates the given AribaExpr expression tree to extract a value from the given root object. |
static java.lang.Object |
getValue(java.lang.Object tree,
java.lang.Object root,
java.lang.Class resultType)
Evaluates the given AribaExpr expression tree to extract a value from the given root object. |
static java.lang.Object |
getValue(java.lang.String expression,
java.util.Map context,
java.lang.Object root)
Evaluates the given AribaExpr expression to extract a value from the given root object in a given context |
static java.lang.Object |
getValue(java.lang.String expression,
java.util.Map context,
java.lang.Object root,
java.lang.Class resultType)
Evaluates the given AribaExpr expression to extract a value from the given root object in a given context |
static java.lang.Object |
getValue(java.lang.String expression,
java.lang.Object root)
Convenience method that combines calls to parseExpression and
getValue . |
static java.lang.Object |
getValue(java.lang.String expression,
java.lang.Object root,
java.lang.Class resultType)
Convenience method that combines calls to parseExpression and
getValue . |
static boolean |
isConstant(java.lang.Object tree)
|
static boolean |
isConstant(java.lang.Object tree,
java.util.Map context)
|
static boolean |
isConstant(java.lang.String expression)
|
static boolean |
isConstant(java.lang.String expression,
java.util.Map context)
|
static boolean |
isSimpleNavigationChain(java.lang.Object tree)
|
static boolean |
isSimpleNavigationChain(java.lang.Object tree,
java.util.Map context)
|
static boolean |
isSimpleNavigationChain(java.lang.String expression)
|
static boolean |
isSimpleNavigationChain(java.lang.String expression,
java.util.Map context)
|
static boolean |
isSimpleProperty(java.lang.Object tree)
|
static boolean |
isSimpleProperty(java.lang.Object tree,
java.util.Map context)
|
static boolean |
isSimpleProperty(java.lang.String expression)
|
static boolean |
isSimpleProperty(java.lang.String expression,
java.util.Map context)
|
static java.lang.Object |
parseExpression(java.lang.String expression)
Parses the given AribaExpr expression and returns a tree representation of the expression that can be used by Expr static methods. |
static void |
setClassResolver(java.util.Map context,
ClassResolver classResolver)
|
static void |
setMemberAccess(java.util.Map context,
MemberAccess memberAccess)
|
static void |
setRoot(java.util.Map context,
java.lang.Object root)
|
static void |
setTypeConverter(java.util.Map context,
TypeConverter converter)
|
static void |
setValue(java.lang.Object tree,
java.util.Map context,
java.lang.Object root,
java.lang.Object value)
Evaluates the given AribaExpr expression tree to insert a value into the object graph rooted at the given root object. |
static void |
setValue(java.lang.Object tree,
java.lang.Object root,
java.lang.Object value)
Evaluates the given AribaExpr expression tree to insert a value into the object graph rooted at the given root object. |
static void |
setValue(java.lang.String expression,
java.util.Map context,
java.lang.Object root,
java.lang.Object value)
Evaluates the given AribaExpr expression to insert a value into the object graph rooted at the given root object given the context. |
static void |
setValue(java.lang.String expression,
java.lang.Object root,
java.lang.Object value)
Convenience method that combines calls to parseExpression and
setValue . |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static java.lang.Object parseExpression(java.lang.String expression) throws ExpressionSyntaxException
Expr
static methods.
expression
- the AribaExpr expression to be parsed
ExpressionSyntaxException
- if the expression is malformed
ExpressionSyntaxException
- if there is a pathological environmental problempublic static java.util.Map createDefaultContext(java.lang.Object root)
root
- the root of the object graph
root
and context
set appropriatelypublic static java.util.Map createDefaultContext(java.lang.Object root, SymbolTable symbolTable)
root
- the root of the object graph
root
and context
set appropriatelypublic static java.util.Map createDefaultContext(java.lang.Object root, ClassResolver classResolver)
root
- the root of the object graph
root
and context
set appropriatelypublic static java.util.Map createDefaultContext(java.lang.Object root, ClassResolver classResolver, TypeConverter converter)
root
- the root of the object graph
root
and context
set appropriatelypublic static java.util.Map createDefaultContext(java.lang.Object root, ClassResolver classResolver, TypeConverter converter, MemberAccess memberAccess)
root
- the root of the object graph
root
and context
set appropriatelypublic static java.util.Map addDefaultContext(java.lang.Object root, java.util.Map context)
root
- the root of the object graphcontext
- the context to which AribaExpr context will be added.
root
and context
set appropriatelypublic static java.util.Map addDefaultContext(java.lang.Object root, ClassResolver classResolver, java.util.Map context)
root
- the root of the object graphcontext
- the context to which AribaExpr context will be added.
root
and context
set appropriatelypublic static java.util.Map addDefaultContext(java.lang.Object root, ClassResolver classResolver, TypeConverter converter, java.util.Map context)
root
- the root of the object graphcontext
- the context to which AribaExpr context will be added.
root
and context
set appropriatelypublic static java.util.Map addDefaultContext(java.lang.Object root, ClassResolver classResolver, TypeConverter converter, MemberAccess memberAccess, java.util.Map context)
root
- the root of the object graphcontext
- the context to which AribaExpr context will be added.
root
and context
set appropriatelypublic static void setClassResolver(java.util.Map context, ClassResolver classResolver)
public static ClassResolver getClassResolver(java.util.Map context)
public static void setTypeConverter(java.util.Map context, TypeConverter converter)
public static TypeConverter getTypeConverter(java.util.Map context)
public static void setMemberAccess(java.util.Map context, MemberAccess memberAccess)
public static MemberAccess getMemberAccess(java.util.Map context)
public static void setRoot(java.util.Map context, java.lang.Object root)
public static java.lang.Object getRoot(java.util.Map context)
public static Evaluation getLastEvaluation(java.util.Map context)
public static java.lang.Object getValue(java.lang.Object tree, java.util.Map context, java.lang.Object root) throws ExprException
addDefaultContext()
.
tree
- the AribaExpr expression tree to evaluate, as returned by parseExpression()context
- the naming context for the evaluationroot
- the root object for the AribaExpr expression
MethodFailedException
- if the expression called a method which failed
NoSuchPropertyException
- if the expression referred to a nonexistent property
InappropriateExpressionException
- if the expression can't be used in this context
ExprException
- if there is a pathological environmental problempublic static java.lang.Object getValue(java.lang.Object tree, java.util.Map context, java.lang.Object root, java.lang.Class resultType) throws ExprException
addDefaultContext()
.
tree
- the AribaExpr expression tree to evaluate, as returned by parseExpression()context
- the naming context for the evaluationroot
- the root object for the AribaExpr expressionresultType
- the converted type of the resultant object, using the context's type converter
MethodFailedException
- if the expression called a method which failed
NoSuchPropertyException
- if the expression referred to a nonexistent property
InappropriateExpressionException
- if the expression can't be used in this context
ExprException
- if there is a pathological environmental problempublic static java.lang.Object getValue(java.lang.String expression, java.util.Map context, java.lang.Object root) throws ExprException
expression
- the AribaExpr expression to be parsedcontext
- the naming context for the evaluationroot
- the root object for the AribaExpr expression
MethodFailedException
- if the expression called a method which failed
NoSuchPropertyException
- if the expression referred to a nonexistent property
InappropriateExpressionException
- if the expression can't be used in this context
ExprException
- if there is a pathological environmental problemparseExpression(String)
,
getValue(Object,Object)
public static java.lang.Object getValue(java.lang.String expression, java.util.Map context, java.lang.Object root, java.lang.Class resultType) throws ExprException
expression
- the AribaExpr expression to be parsedcontext
- the naming context for the evaluationroot
- the root object for the AribaExpr expressionresultType
- the converted type of the resultant object, using the context's type converter
MethodFailedException
- if the expression called a method which failed
NoSuchPropertyException
- if the expression referred to a nonexistent property
InappropriateExpressionException
- if the expression can't be used in this context
ExprException
- if there is a pathological environmental problemparseExpression(String)
,
getValue(Object,Object)
public static java.lang.Object getValue(java.lang.Object tree, java.lang.Object root) throws ExprException
tree
- the AribaExpr expression tree to evaluate, as returned by parseExpression()root
- the root object for the AribaExpr expression
MethodFailedException
- if the expression called a method which failed
NoSuchPropertyException
- if the expression referred to a nonexistent property
InappropriateExpressionException
- if the expression can't be used in this context
ExprException
- if there is a pathological environmental problempublic static java.lang.Object getValue(java.lang.Object tree, java.lang.Object root, java.lang.Class resultType) throws ExprException
tree
- the AribaExpr expression tree to evaluate, as returned by parseExpression()root
- the root object for the AribaExpr expressionresultType
- the converted type of the resultant object, using the context's type converter
MethodFailedException
- if the expression called a method which failed
NoSuchPropertyException
- if the expression referred to a nonexistent property
InappropriateExpressionException
- if the expression can't be used in this context
ExprException
- if there is a pathological environmental problempublic static java.lang.Object getValue(java.lang.String expression, java.lang.Object root) throws ExprException
parseExpression
and
getValue
.
expression
- the AribaExpr expression to be parsedroot
- the root object for the AribaExpr expression
ExpressionSyntaxException
- if the expression is malformed
MethodFailedException
- if the expression called a method which failed
NoSuchPropertyException
- if the expression referred to a nonexistent property
InappropriateExpressionException
- if the expression can't be used in this context
ExprException
- if there is a pathological environmental problemparseExpression(String)
,
getValue(Object,Object)
public static java.lang.Object getValue(java.lang.String expression, java.lang.Object root, java.lang.Class resultType) throws ExprException
parseExpression
and
getValue
.
expression
- the AribaExpr expression to be parsedroot
- the root object for the AribaExpr expressionresultType
- the converted type of the resultant object, using the context's type converter
ExpressionSyntaxException
- if the expression is malformed
MethodFailedException
- if the expression called a method which failed
NoSuchPropertyException
- if the expression referred to a nonexistent property
InappropriateExpressionException
- if the expression can't be used in this context
ExprException
- if there is a pathological environmental problemparseExpression(String)
,
getValue(Object,Object)
public static void setValue(java.lang.Object tree, java.util.Map context, java.lang.Object root, java.lang.Object value) throws ExprException
addDefaultContext()
.
tree
- the AribaExpr expression tree to evaluate, as returned by parseExpression()context
- the naming context for the evaluationroot
- the root object for the AribaExpr expressionvalue
- the value to insert into the object graph
MethodFailedException
- if the expression called a method which failed
NoSuchPropertyException
- if the expression referred to a nonexistent property
InappropriateExpressionException
- if the expression can't be used in this context
ExprException
- if there is a pathological environmental problempublic static void setValue(java.lang.String expression, java.util.Map context, java.lang.Object root, java.lang.Object value) throws ExprException
expression
- the AribaExpr expression to be parsedroot
- the root object for the AribaExpr expressioncontext
- the naming context for the evaluationvalue
- the value to insert into the object graph
MethodFailedException
- if the expression called a method which failed
NoSuchPropertyException
- if the expression referred to a nonexistent property
InappropriateExpressionException
- if the expression can't be used in this context
ExprException
- if there is a pathological environmental problempublic static void setValue(java.lang.Object tree, java.lang.Object root, java.lang.Object value) throws ExprException
tree
- the AribaExpr expression tree to evaluate, as returned by parseExpression()root
- the root object for the AribaExpr expressionvalue
- the value to insert into the object graph
MethodFailedException
- if the expression called a method which failed
NoSuchPropertyException
- if the expression referred to a nonexistent property
InappropriateExpressionException
- if the expression can't be used in this context
ExprException
- if there is a pathological environmental problempublic static void setValue(java.lang.String expression, java.lang.Object root, java.lang.Object value) throws ExprException
parseExpression
and
setValue
.
expression
- the AribaExpr expression to be parsedroot
- the root object for the AribaExpr expressionvalue
- the value to insert into the object graph
ExpressionSyntaxException
- if the expression is malformed
MethodFailedException
- if the expression called a method which failed
NoSuchPropertyException
- if the expression referred to a nonexistent property
InappropriateExpressionException
- if the expression can't be used in this context
ExprException
- if there is a pathological environmental problemparseExpression(String)
,
setValue(Object,Object,Object)
public static boolean isConstant(java.lang.Object tree, java.util.Map context) throws ExprException
ExprException
public static boolean isConstant(java.lang.String expression, java.util.Map context) throws ExprException
ExprException
public static boolean isConstant(java.lang.Object tree) throws ExprException
ExprException
public static boolean isConstant(java.lang.String expression) throws ExprException
ExprException
public static boolean isSimpleProperty(java.lang.Object tree, java.util.Map context) throws ExprException
ExprException
public static boolean isSimpleProperty(java.lang.String expression, java.util.Map context) throws ExprException
ExprException
public static boolean isSimpleProperty(java.lang.Object tree) throws ExprException
ExprException
public static boolean isSimpleProperty(java.lang.String expression) throws ExprException
ExprException
public static boolean isSimpleNavigationChain(java.lang.Object tree, java.util.Map context) throws ExprException
ExprException
public static boolean isSimpleNavigationChain(java.lang.String expression, java.util.Map context) throws ExprException
ExprException
public static boolean isSimpleNavigationChain(java.lang.Object tree) throws ExprException
ExprException
public static boolean isSimpleNavigationChain(java.lang.String expression) throws ExprException
ExprException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |