• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JexlExpression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.commons.jexl3.JexlExpression的典型用法代码示例。如果您正苦于以下问题:Java JexlExpression类的具体用法?Java JexlExpression怎么用?Java JexlExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JexlExpression类属于org.apache.commons.jexl3包,在下文中一共展示了JexlExpression类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
    }
}
 
开发者ID:apache,项目名称:commons-scxml,代码行数:27,代码来源:JexlEvaluator.java


示例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);
    }
}
 
开发者ID:apache,项目名称:commons-scxml,代码行数:22,代码来源:JexlEvaluator.java


示例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;
}
 
开发者ID:apache,项目名称:syncope,代码行数:20,代码来源:JexlUtils.java


示例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;
}
 
开发者ID:wmaop,项目名称:wm-aop,代码行数:12,代码来源:JexlIDataMatcher.java


示例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;
}
 
开发者ID:wmaop,项目名称:wm-aop,代码行数:10,代码来源:JexlIDataMatcher.java


示例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);
}
 
开发者ID:wmaop,项目名称:wm-jbehave,代码行数:9,代码来源:PipelineVariableStep.java


示例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);
}
 
开发者ID:debrief,项目名称:limpet,代码行数:39,代码来源:ReflectivePropertySource.java


示例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;
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:8,代码来源:JexlRowFactory.java


示例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;
    }
}
 
开发者ID:apache,项目名称:commons-jexl,代码行数:13,代码来源:Debugger.java


示例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;
}
 
开发者ID:apache,项目名称:commons-jexl,代码行数:13,代码来源:ScriptVisitor.java


示例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));
}
 
开发者ID:apache,项目名称:commons-jexl,代码行数:30,代码来源:ArrayTest.java


示例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;
}
 
开发者ID:wmaop,项目名称:wm-aop,代码行数:7,代码来源:JexlServiceNameMatcher.java


示例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);
}
 
开发者ID:wmaop,项目名称:wm-aop,代码行数:7,代码来源:JexlIDataMatcher.java


示例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));
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:5,代码来源:JexlSelector.java


示例15: getSourceText

import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
public String getSourceText() {
  return expression.map(JexlExpression::getSourceText).orElse("");
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:4,代码来源:JexlSelector.java


示例16: example

import org.apache.commons.jexl3.JexlExpression; //导入依赖的package包/类
/**
 * An example for method access.
 */
public static void example(final 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();

    /**
     * The Java equivalents of foo and number for comparison and checking
     */
    Foo foo = new Foo();
    Integer number = new Integer(10);

    jc.set("foo", foo);
    jc.set("number", number);

    /*
     *  access a method w/o args
     */
    JexlExpression e = jexl.createExpression("foo.getFoo()");
    Object o = e.evaluate(jc);
    out.print("value returned by the method getFoo() is : ", o, foo.getFoo());

    /*
     *  access a method w/ args
     */
    e = jexl.createExpression("foo.convert(1)");
    o = e.evaluate(jc);
    out.print("value of " + e.getParsedText() + " is : ", o, foo.convert(1));

    e = jexl.createExpression("foo.convert(1+7)");
    o = e.evaluate(jc);
    out.print("value of " + e.getParsedText() + " is : ", o, foo.convert(1+7));

    e = jexl.createExpression("foo.convert(1+number)");
    o = e.evaluate(jc);
    out.print("value of " + e.getParsedText() + " is : ", o, foo.convert(1+number.intValue()));

    /*
     * access a property
     */
    e = jexl.createExpression("foo.bar");
    o = e.evaluate(jc);
    out.print("value returned for the property 'bar' is : ", o, foo.get("bar"));

}
 
开发者ID:apache,项目名称:commons-jexl,代码行数:54,代码来源:MethodPropertyTest.java



注:本文中的org.apache.commons.jexl3.JexlExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DataTreeModification类代码示例发布时间:2022-05-22
下一篇:
Java CompileStatic类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap