本文整理汇总了Java中org.apache.commons.jexl3.JexlExpression类的典型用法代码示例。如果您正苦于以下问题:Java JexlExpression类的具体用法?Java JexlExpression怎么用?Java JexlExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JexlExpression类属于org.apache.commons.jexl3包,在下文中一共展示了JexlExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: eval
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
/**
* Evaluate an expression.
*
* @param ctx variable context
* @param expr expression
* @return a result of the evaluation
* @throws SCXMLExpressionException For a malformed expression
* @see Evaluator#eval(Context, String)
*/
public Object eval(final Context ctx, final String expr)
throws SCXMLExpressionException {
if (expr == null) {
return null;
}
if (!(ctx instanceof JexlContext)) {
throw new SCXMLExpressionException(ERR_CTX_TYPE);
}
try {
final JexlContext effective = getEffectiveContext((JexlContext)ctx);
JexlExpression exp = getJexlEngine().createExpression(expr);
return exp.evaluate(effective);
} catch (Exception e) {
String exMessage = e.getMessage() != null ? e.getMessage() : e.getClass().getCanonicalName();
throw new SCXMLExpressionException("eval('" + expr + "'): " + exMessage, e);
}
}
示例2: evalCond
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
/**
* @see Evaluator#evalCond(Context, String)
*/
public Boolean evalCond(final Context ctx, final String expr)
throws SCXMLExpressionException {
if (expr == null) {
return null;
}
if (!(ctx instanceof JexlContext)) {
throw new SCXMLExpressionException(ERR_CTX_TYPE);
}
try {
final JexlContext effective = getEffectiveContext((JexlContext)ctx);
JexlExpression exp = getJexlEngine().createExpression(expr);
final Object result = exp.evaluate(effective);
return result == null ? Boolean.FALSE : (Boolean)result;
} catch (Exception e) {
String exMessage = e.getMessage() != null ? e.getMessage() : e.getClass().getCanonicalName();
throw new SCXMLExpressionException("evalCond('" + expr + "'): " + exMessage, e);
}
}
示例3: evaluate
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
public static String evaluate(final String expression, final JexlContext jexlContext) {
String result = StringUtils.EMPTY;
if (StringUtils.isNotBlank(expression) && jexlContext != null) {
try {
JexlExpression jexlExpression = getEngine().createExpression(expression);
Object evaluated = jexlExpression.evaluate(jexlContext);
if (evaluated != null) {
result = evaluated.toString();
}
} catch (Exception e) {
LOG.error("Error while evaluating JEXL expression: " + expression, e);
}
} else {
LOG.debug("Expression not provided or invalid context");
}
return result;
}
示例4: match
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
@Override
public MatchResult match(IData idata) {
JexlContext ctx = new IDataJexlContext(idata);
for (Entry<String, JexlExpression> expr : expressions.entrySet()) {
Object result = expr.getValue().evaluate(ctx);
verifyExpressionResult(expr.getKey(), result);
if ((Boolean) result)
return new MatchResult(true, expr.getKey());
}
return MatchResult.FALSE;
}
示例5: toMap
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
@Override
public Map<String, Object> toMap() {
Map<String, Object> am = new HashMap<>();
am.put("type", "JexlIDataMatcher");
for (Entry<String, JexlExpression> e : expressions.entrySet()) {
am.put(e.getKey(), e.getValue().toString());
}
return am;
}
示例6: execute
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
@Override
protected void execute(ExecutionContext executionContext) throws Exception {
IData idata = executionContext.getPipeline();
for (JexlExpression expression : expressions) {
expression.evaluate(new IDataJexlContext(idata));
}
executionContext.setPipeline(idata);
}
示例7: evaluateVisibility
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
private boolean evaluateVisibility(Object object,
PropertyDescriptor[] beanPropertyDescriptors, String visibleWhen)
{
Map<String, PropertyDescriptor> descriptorsMap =
new HashMap<String, PropertyDescriptor>();
for (PropertyDescriptor pd : beanPropertyDescriptors)
{
descriptorsMap.put(pd.getName(), pd);
}
JexlEngine jexl = new JexlBuilder().create();
JexlExpression expression = jexl.createExpression(visibleWhen);
JexlContext context = new MapContext();
Set<List<String>> vars = ((Script) expression).getVariables();
for (List<String> varList : vars)
{
for (String varName : varList)
{
PropertyDescriptor propertyDescriptor = descriptorsMap.get(varName);
if (propertyDescriptor != null)
{
try
{
Object value = propertyDescriptor.getReadMethod().invoke(object);
context.set(varName, value);
}
catch (Exception e)
{
Activator.logError(Status.ERROR,
"Could not retrieve value for property " + varName, e);
}
}
}
}
return (boolean) expression.evaluate(context);
}
示例8: MapBasedRow
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
public MapBasedRow(Map<String, String> data, Map<String, List<String>> joinedData, ErrorHandler errorHandler,
Map<String, JexlExpression> expressions) {
this.data = data;
this.joinedData = joinedData;
this.errorHandler = errorHandler;
this.expressions = expressions;
}
示例9: debug
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
/**
* Position the debugger on the root of an expression.
* @param jscript the expression
* @return true if the expression was a {@link Script} instance, false otherwise
*/
public boolean debug(JexlExpression jscript) {
if (jscript instanceof Script) {
return debug(((Script) jscript).script);
} else {
return false;
}
}
示例10: visitExpression
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
/**
* Visits all AST constituents of a JEXL expression.
* @param jscript the expression
* @param data some data context
* @return the visit result or null if jscript was not a Script implementation
*/
public Object visitExpression (JexlExpression jscript, Object data) {
if (jscript instanceof Script) {
return ((Script) jscript).getScript().jjtAccept(this, data);
}
return null;
}
示例11: example
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
/**
* An example for array access.
*/
static void example(Output out) throws Exception {
/**
* First step is to retrieve an instance of a JexlEngine;
* it might be already existing and shared or created anew.
*/
JexlEngine jexl = new JexlBuilder().create();
/*
* Second make a jexlContext and put stuff in it
*/
JexlContext jc = new MapContext();
List<Object> l = new ArrayList<Object>();
l.add("Hello from location 0");
Integer two = new Integer(2);
l.add(two);
jc.set("array", l);
JexlExpression e = jexl.createExpression("array[1]");
Object o = e.evaluate(jc);
out.print("Object @ location 1 = ", o, two);
e = jexl.createExpression("array[0].length()");
o = e.evaluate(jc);
out.print("The length of the string at location 0 is : ", o, Integer.valueOf(21));
}
示例12: createExpression
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
private JexlExpression createExpression(String name, String exprText) {
JexlExpression compiledExpr = JexlExpressionFactory.createExpression(exprText);
Object result = compiledExpr.evaluate(new MapContext());
verifyExpressionResult(name, result);
return compiledExpr;
}
示例13: createExpression
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
private void createExpression(String name, String exprText) {
JexlExpression compiledExpr = JexlExpressionFactory.createExpression(exprText);
Object result = compiledExpr.evaluate(new MapContext());
verifyExpressionResult(name, result);
expressions.put(name, compiledExpr);
}
示例14: JexlSelector
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
public JexlSelector(final String expression) {
this.expression = isNullOrEmpty(expression) ? Optional.<JexlExpression>empty()
: Optional.of(threadLocalJexl.get().createExpression(CALLER_INFO, expression));
}
示例15: getSourceText
import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
public String getSourceText() {
return expression.map(JexlExpression::getSourceText).orElse("");
}