Package com.luciad.datamodel.expression
Class TLcdDataObjectExpressionLanguage
java.lang.Object
com.luciad.datamodel.expression.ALcdDataObjectExpressionLanguage
com.luciad.datamodel.expression.TLcdDataObjectExpressionLanguage
Default implementation of
ALcdDataObjectExpressionLanguage
. This language allows
the following kinds of expressions:
- Property names: a property name is evaluated to the value of that property. A chain
of property names can be set up using the dot operator. For example, consider a Person type
that has 3 properties: name, child (links to another Person object) and children (a list
property also of type Person). Given an object of such a type as root, the following
expressions are supported:
name
returns the value of the name property of the root object.child.name
returns the value of the name property of the root object's child. If the root object has no child,null
is returned.children.name
returns a list containing all the names (that are not null) of the root object's children
- Custom functions: the language supports the registration of custom
functions (see
getFunctions()
. These functions compute a value based on a number of arguments.
The arguments can be either other expressions or constants. Constants are placed between single quotes. For instance '2' or 'myString'. These constants evaluate to aString
.toUpper(child.name)
returns the name of the root object's child in upper case (as returned by the 'toUpper' function registered in the function context).favourite(children).name
returns the name of the root object's favourite child (as returned by the 'favourite' function), ornull
in case the function returnednull
.
- Index-based selection: in case an expression is evaluated into a List,
index-based selection can be applied to select the element at the given
position in the list. For instance,
children[3].name
returns the name of the root object's fourth child (the index of the first element in the list is 0) ornull
in case the root object does not have 4 children.
<Expression> =
[ <Expression> "." ] <PropertyName> |
<FunctionCall> |
<Expression> "[" <Number> "]" |
"'" <Literal> "'"
<FunctionCall> = <FunctionName> "(" [ <Expression> ( "," <Expression> )* ] ")"
- Since:
- 10.1
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Custom function that computes a value given a list of arguments. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCompiles the expression to an intermediate representation.static String
createExpression
(TLcdDataType aDataType, TLcdDataProperty... aDataProperties) Utility method to create the expression pointing to the value of a certain property.static TLcdDataProperty[]
getExpressionProperties
(TLcdDataType aDataType, String aExpression) This method will convert a straight property, likePropertyName1.PropertyName2...
, expression to anTLcdDataProperty
array.Returns the function context of this language.void
update
(String aExpression, ILcdDataObject aRoot, Object aValue) Updates the value in a data object identified by the passed expression.Methods inherited from class com.luciad.datamodel.expression.ALcdDataObjectExpressionLanguage
createContext, evaluate, evaluate
-
Constructor Details
-
TLcdDataObjectExpressionLanguage
public TLcdDataObjectExpressionLanguage()
-
-
Method Details
-
getFunctions
Returns the function context of this language. Functions that are added to this map can be used in expressions.- Returns:
- the function context of this language
-
compile
Description copied from class:ALcdDataObjectExpressionLanguage
Compiles the expression to an intermediate representation. This can be used to improve performance when the same expression needs to be evaluated in different contexts.- Specified by:
compile
in classALcdDataObjectExpressionLanguage
- Parameters:
aExpression
- the expression to compile- Returns:
- a compiled expression
-
update
Updates the value in a data object identified by the passed expression. Only straight property expressions, likePropertyName1.PropertyName2...
, are supported, seecreateExpression(com.luciad.datamodel.TLcdDataType, com.luciad.datamodel.TLcdDataProperty...)
. Expressions pointing to elements inside a list, likeListPropertyName[0]
, functions or complex expressions combining multiple properties can't be handled by this method.- Parameters:
aExpression
- the expression describing which property to update,aRoot
- the root data object.aValue
- the new value.
-
createExpression
Utility method to create the expression pointing to the value of a certain property. If more than one data property is passed it points to a property of the value, which must be aILcdDataObject
itself, of a property etc...- Parameters:
aDataType
- the root data typeaDataProperties
- one or more data properties, the first data property should be a property of an extension or supertype ofaDataType
, and the other data properties should be a property of an extension or super type of the type of the previous data property.- Returns:
- an expression representing a path from the passed dataType down to a (nested) property.
- Throws:
IllegalArgumentException
- if:aDataType
is nullaDataProperties
is null or empty- one of the data properties is not a property of the type of the previous data property.
-
getExpressionProperties
public static TLcdDataProperty[] getExpressionProperties(TLcdDataType aDataType, String aExpression) throws IllegalArgumentException This method will convert a straight property, likePropertyName1.PropertyName2...
, expression to anTLcdDataProperty
array. It is the reverse of the methodcreateExpression(com.luciad.datamodel.TLcdDataType, com.luciad.datamodel.TLcdDataProperty...)
.- Parameters:
aDataType
- the root data typeaExpression
- an expression representing a path from the passed dataType down to a (nested) property.- Returns:
- an array of data properties corresponding to the expression.
- Throws:
IllegalArgumentException
- when the expression is not valid for the given data type.- See Also:
-