|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.gentics.api.lib.expressionparser.ExpressionEvaluator
public class ExpressionEvaluator
Class for expression evaluation. Implements the basic functionality to evaluate an expression. Also provides static methods for type conversions.
Nested Class Summary | |
---|---|
static class |
ExpressionEvaluator.TypeSafeComparator
Comparator class for doing typesafe comparisons and sorting. |
Field Summary | |
---|---|
protected Map |
baseObjects
base objects of the expression evaluator |
static int |
OBJECTTYPE_ANY
constant for any value type |
static int |
OBJECTTYPE_ASSIGNMENT
constant for the value type "assignment (result)" |
static int |
OBJECTTYPE_BINARY
constant for binary value type |
static int |
OBJECTTYPE_BOOLEAN
constant for the value type "boolean" |
static int |
OBJECTTYPE_COLLECTION
constant for the value type "collection" |
static int |
OBJECTTYPE_DATE
constant for the value type "date" |
static int |
OBJECTTYPE_NULL
constant for the value type "null" (object is expected to be null) |
static int |
OBJECTTYPE_NUMBER
constant for the value type "number" |
static int |
OBJECTTYPE_STRING
constant for the value type "string" |
static int |
OBJECTTYPE_UNKNOWN
constant for unknown value type |
static int |
OBJECTTYPE_WILDCARDSTRING
constant for the value type "string" |
protected PropertyResolver |
resolver
PropertyResolver |
Constructor Summary | |
---|---|
ExpressionEvaluator()
Create a new instance of the expression evaluator |
Method Summary | |
---|---|
boolean |
canResolve()
Check whether the resolvable is capable of resolving properties right now. |
void |
clearProperties()
Clear all resolvable properties |
static boolean |
containsAll(Collection leftCollection,
Collection rightCollection)
Check whether the left collection contains all objects from the right collection |
static boolean |
containsNone(Collection leftCollection,
Collection rightCollection)
Check whether the collections have no object in common |
static boolean |
containsOneOf(Collection leftCollection,
Collection rightCollection)
Check whether the left collection contains at least one object of the right collection |
Object |
get(String key)
Get the property named by key or null if the property does not exist or is not set. |
static Boolean |
getAsBoolean(Object object)
Get the given object as boolean. |
static Collection |
getAsCollection(Object object)
Get the given object as Collection. |
static Date |
getAsDate(Object object)
Get the given object as Date. |
static Number |
getAsNumber(ExpressionQueryRequest request,
Object object,
Class numberClass)
|
static Number |
getAsNumber(Object object)
Get the given object as number. |
static Number |
getAsNumber(Object object,
Class numberClass)
Get the given object as number of the given class. |
static String |
getAsString(Object object)
Get the given object as String. |
static Object |
getAsType(Object object,
int type)
Get the given object as object of specified type. |
protected static int |
getObjectType(Object object)
Analyze the given object and get the objecttype |
Object |
getProperty(String key)
Get the property named by key or null if the property does not exist or is not set. |
protected static String |
getTypeName(Object object)
Get the type of the object as string |
static String |
getValuetypeName(int valueType)
Get the name of the given value type |
protected static boolean |
incompatibleComparisonTypes(Object object1,
Object object2)
Helper method to throw an Exception "Incompatible types found in comparison..." |
static boolean |
isInteger(Number number)
Check whether the given number is an integer. |
static boolean |
isTypeSafeEqual(Object object1,
Object object2)
Check whether the objects are typesafe equal. |
static boolean |
isTypeSafeUnequal(Object object1,
Object object2)
Check whether the objects are typesafe unequal. |
boolean |
match(Expression expression)
Try to match the given expression (against the added resolvables) |
boolean |
match(Expression expression,
Resolvable matchedObject)
Try to match the given expression against the given object (and the added resolvables) |
boolean |
setProperty(String name,
Object value)
Set (modify) the property name to resolve to the given value |
void |
setRequestParameters(Map parameters)
Allows you to set parameters which will be passed to ExpressionQueryRequest |
void |
setResolver(PropertyResolver resolver)
Set a property resolver, which will be used to resolve paths in expressions |
static boolean |
typeSafeComparison(ExpressionQueryRequest request,
Object object1,
Object object2,
int type)
Perform a typesafe comparison between the given objects. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int OBJECTTYPE_ANY
public static final int OBJECTTYPE_NULL
public static final int OBJECTTYPE_BOOLEAN
public static final int OBJECTTYPE_NUMBER
public static final int OBJECTTYPE_DATE
public static final int OBJECTTYPE_STRING
public static final int OBJECTTYPE_WILDCARDSTRING
public static final int OBJECTTYPE_COLLECTION
public static final int OBJECTTYPE_ASSIGNMENT
public static final int OBJECTTYPE_UNKNOWN
public static final int OBJECTTYPE_BINARY
protected Map baseObjects
protected PropertyResolver resolver
Constructor Detail |
---|
public ExpressionEvaluator()
Method Detail |
---|
public void setResolver(PropertyResolver resolver)
resolver
- property resolverpublic static String getValuetypeName(int valueType)
valueType
- value type
public void setRequestParameters(Map parameters)
ExpressionQueryRequest
parameters
- public boolean match(Expression expression) throws ExpressionParserException
expression
- expression to match
ExpressionParserException
- when the expression cannot be matched (is not
boolean or contains errors)public boolean match(Expression expression, Resolvable matchedObject) throws ExpressionParserException
expression
- expression to matchmatchedObject
- object the expression is matched against
ExpressionParserException
- when the expression cannot be matched (is not
boolean or contains errors)public static Number getAsNumber(Object object, Class numberClass) throws EvaluationException
object
- object to interpret as numbernumberClass
- desired class, must be a subclass of Number
EvaluationException
- when the object cannot be interpreted as
number or the given numberClass is not derived from class Numberpublic static Number getAsNumber(ExpressionQueryRequest request, Object object, Class numberClass) throws EvaluationException
EvaluationException
public static Number getAsNumber(Object object) throws EvaluationException
Number
, its string representation is parsed as number.
object
- object to interpret as number
EvaluationException
- when the object cannot be interpreted as
numberpublic static Boolean getAsBoolean(Object object) throws EvaluationException
Boolean
, its string representation is parsed as boolean. "true",
"false", "1" or "0" can be interpreted as boolean.
object
- object to interpret as boolean
EvaluationException
- when the object cannot be interpreted as
booleanpublic static Date getAsDate(Object object) throws EvaluationException
Date
.
object
- object to interpret as Date
EvaluationException
- when the object cannot be interpreted as Datepublic static Collection getAsCollection(Object object) throws EvaluationException
Collection
, a new collection containing just the object is
returned.
object
- object to interpret as collection
EvaluationException
public static String getAsString(Object object) throws EvaluationException
Collection
.
object
- object to interpret as string
EvaluationException
- when the object cannot be interpreted as
stringpublic static Object getAsType(Object object, int type) throws EvaluationException
OBJECTTYPE_ANY
,
OBJECTTYPE_BOOLEAN
, OBJECTTYPE_COLLECTION
,
OBJECTTYPE_DATE
, OBJECTTYPE_NULL
,
OBJECTTYPE_NUMBER
, OBJECTTYPE_STRING
).
object
- object to interpret in the given typetype
- requested type for the object
EvaluationException
- when the object cannot be interpreted in the
given typepublic static boolean isInteger(Number number)
Long
,
Integer
, Short
, Byte
, BigInteger
number
- number to check
protected static String getTypeName(Object object)
object
- object to analyze
protected static boolean incompatibleComparisonTypes(Object object1, Object object2) throws EvaluationException
object1
- first object in comparisonobject2
- second object in comparison
EvaluationException
- since this is the purpose of this methodpublic static boolean typeSafeComparison(ExpressionQueryRequest request, Object object1, Object object2, int type) throws EvaluationException
Function.TYPE_SMALLER
,
Function.TYPE_SMALLEROREQUAL
,
Function.TYPE_GREATEROREQUAL
, Function.TYPE_GREATER
).
request
- object.object1
- lefthand-side objectobject2
- righthand-side objecttype
- type of the comparison
EvaluationException
- when the objects cannot be converted such
that the comparison can be donepublic static boolean isTypeSafeUnequal(Object object1, Object object2) throws EvaluationException
isTypeSafeEqual(Object, Object)
, when object1 is an instance
of NestedCollection
. In this case, the comparison is interpreted
as: "true when object1 contains at least one object that is unequal
object2"
object1
- lefthand-side objectobject2
- righthand-side object
EvaluationException
- when the objects cannot be comparedpublic static boolean isTypeSafeEqual(Object object1, Object object2) throws EvaluationException
object1
- lefthand-side objectobject2
- righthand-side object
EvaluationException
- when the objects cannot be comparedprotected static int getObjectType(Object object) throws EvaluationException
object
- object to analyze
EvaluationException
public static boolean containsOneOf(Collection leftCollection, Collection rightCollection) throws EvaluationException
leftCollection
- left collectionrightCollection
- right collection
EvaluationException
public static boolean containsNone(Collection leftCollection, Collection rightCollection) throws EvaluationException
leftCollection
- left collectionrightCollection
- right collection
EvaluationException
public static boolean containsAll(Collection leftCollection, Collection rightCollection)
leftCollection
- left collectionrightCollection
- right collection
public boolean setProperty(String name, Object value) throws InsufficientPrivilegesException
Changeable
setProperty
in interface Changeable
name
- name of the property to set/modifyvalue
- (new) value to set
InsufficientPrivilegesException
- when the property may not be
changedpublic Object getProperty(String key)
Resolvable
Resolvable.get(String)
.
getProperty
in interface Resolvable
key
- key of the property
public Object get(String key)
Resolvable
get
in interface Resolvable
key
- key of the property
public boolean canResolve()
Resolvable
Resolvable.getProperty(String)
or Resolvable.get(String)
will return null.
canResolve
in interface Resolvable
public void clearProperties()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |