|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectExpressionAbstract
DefaultExpression
FunctionExpressionImpl
EnvFunction
public class EnvFunction
Provides a lookup table of named variables allowing externally defined values to be access within a SLD document.
Example: in the application, prior to rendering...
EnvFunction.setValue("foo", 42);
Then, in the SLD document we can refer to this variable using
the "env" function
...
<FeatureTypeStyle>
<Rule>
<Filter>
<PropertyIsEqualTo>
<PropertyName>FooValue</PropertyName>
<Function name="env">
<literal>foo</literal>
</Function>
</PropertyIsEqualTo>
</Filter>
...
The function provides a lookup table that is local to the active thread
so that a given variable can hold different values in different threads.
There is also a global lookup table, accessible from all threads.
When the function is given a variable to look up it first searches the
thread's local table and then, if the variable was not found, the global
table. All lookups are case-insensitive.
Setting a fallback value is not supported in accordance with SLD 1.1 specification. However, you can provide a default value when calling the function as in these examples:
<!-- Here, if variable foo is not set the function returns null -->
<Function name="env">
<Literal>foo</Literal>
</Function>
<!-- Here, a second argument is provided. If foo is not set the -->
<!-- function will return 0. -->
<Function name="env">
<Literal>foo</Literal>
<Literal>0</Literal>
</Function>
The same approach can be used programmatically...
// set argument to set a default return value of 0
FilterFactory ff = ...
ff.function("env", ff.literal("foo"), ff.literal(0));
Field Summary | |
---|---|
static FunctionName |
NAME
|
Fields inherited from class FunctionExpressionImpl |
---|
fallback, functionName, name, params |
Fields inherited from class DefaultExpression |
---|
expressionType, permissiveConstruction |
Fields inherited from interface ExpressionType |
---|
ATTRIBUTE, ATTRIBUTE_DOUBLE, ATTRIBUTE_GEOMETRY, ATTRIBUTE_INTEGER, ATTRIBUTE_STRING, ATTRIBUTE_UNDECLARED, FUNCTION, LITERAL_DOUBLE, LITERAL_GEOMETRY, LITERAL_INTEGER, LITERAL_LONG, LITERAL_STRING, LITERAL_UNDECLARED, MATH_ADD, MATH_DIVIDE, MATH_MULTIPLY, MATH_SUBTRACT |
Fields inherited from interface Expression |
---|
NIL |
Constructor Summary | |
---|---|
EnvFunction()
Create a new instance of this function. |
Method Summary | |
---|---|
static void |
clearGlobalValues()
Clear all values from the global (accessible from any thread) lookup table. |
static void |
clearLocalValues()
Clear all values from the local (to this thread) lookup table. |
Object |
evaluate(Object feature)
This method checks if the object is an instance of Feature and
if so, calls through to #evaluate(Feature) . |
int |
getArgCount()
Gets the number of arguments that are set. |
void |
setFallbackValue(Literal fallback)
This method is overriden to ignore the fallback value and log a warning message. |
static void |
setGlobalValue(String name,
Object value)
Add a named value to the global (accessible from any thread) lookup table. |
static void |
setGlobalValues(Map<String,Object> values)
Set the table of global lookup values that is accessible from any thread, replacing the previously set table. |
static void |
setLocalValue(String name,
Object value)
Add a named value to the local (to this thread) lookup table. |
static void |
setLocalValues(Map<String,Object> values)
Set the local (to this thread) table of lookup values, deleting any previously set table. |
void |
setParameters(List params)
Sets the function parameters. |
Methods inherited from class FunctionExpressionImpl |
---|
accept, equals, functionName, getArgs, getExpression, getFallbackValue, getFunctionName, getImplementationHints, getName, getParameters, getType, setArgs, setName, toString |
Methods inherited from class DefaultExpression |
---|
accept, evaluate, getValue, isAttributeExpression, isExpression, isFunctionExpression, isGeometryExpression, isLiteralExpression, isMathExpression, isMathExpression |
Methods inherited from class ExpressionAbstract |
---|
eval, eval, evaluate |
Methods inherited from class Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface Expression |
---|
accept, evaluate, getValue |
Methods inherited from interface Expression |
---|
evaluate |
Field Detail |
---|
public static FunctionName NAME
Constructor Detail |
---|
public EnvFunction()
Method Detail |
---|
public static void setLocalValues(Map<String,Object> values)
Map
is copied.
values
- the lookup table; if null
the existing lookup
table will be cleared.public static void clearLocalValues()
public static void setGlobalValues(Map<String,Object> values)
Map
is copied.
values
- the lookup table; if null
the existing lookup
table will be cleared.public static void clearGlobalValues()
public static void setLocalValue(String name, Object value)
name
- the namevalue
- the valuepublic static void setGlobalValue(String name, Object value)
name
- the namevalue
- the valuepublic int getArgCount()
getArgCount
in interface FunctionExpression
getArgCount
in class FunctionExpressionImpl
public Object evaluate(Object feature)
Feature
and
if so, calls through to #evaluate(Feature)
. This is done
to maintain backwards compatability with previous version of Expression api
which depended on Feature. If the object is not an instance of feature
the super implementation is called.
The variable name to search for is provided as the single argument to
this function. The active thread's local lookup table is searched first.
If the name is not found there the global table is searched.
evaluate
in interface Expression
evaluate
in class DefaultExpression
null
if the variable was not foundpublic void setParameters(List params)
setParameters
in interface FunctionExpression
setParameters
in class FunctionExpressionImpl
public void setFallbackValue(Literal fallback)
setFallbackValue
in class FunctionExpressionImpl
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |