当前位置: 首页>>代码示例>>Java>>正文


Java JexlContext.set方法代码示例

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


在下文中一共展示了JexlContext.set方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRawValue

import org.apache.commons.jexl3.JexlContext; //导入方法依赖的package包/类
@Override
public String getRawValue(String key) {
  if (data.containsKey(key)) {
    return data.get(key);
  } else if (expressions.containsKey(key)) {
    try {
      JexlContext jexlContext = new MapContext();
      jexlContext.set("v", data);
      Object result = expressions.get(key).evaluate(jexlContext);
      if (result != null) {
        return result.toString();
      } else {
        return null;
      }
    } catch (Throwable throwable) {
      LOG.info("Error during mapping", throwable);
      errorHandler.valueGenerateFailed(
        key,
        String.format("Could not execute expression '%s' for row with values: '%s.", expressions.get(key), data)
      );
      return null;
    }
  } else {
    return null;
  }
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:27,代码来源:JexlRowFactory.java

示例2: testCantSeeMe

import org.apache.commons.jexl3.JexlContext; //导入方法依赖的package包/类
@Test
public void testCantSeeMe() throws Exception {
    JexlContext jc = new MapContext();
    String expr = "foo.doIt()";
    JexlScript script;
    Object result = null;

    JexlSandbox sandbox = new JexlSandbox(false);
    sandbox.white(Foo.class.getName());
    JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();

    jc.set("foo", new CantSeeMe());
    script = sjexl.createScript(expr);
    try {
        result = script.execute(jc);
        Assert.fail("should have failed, doIt()");
    } catch (JexlException xany) {
        //
    }
    jc.set("foo", new Foo("42"));
        result = script.execute(jc);
    Assert.assertEquals(42, ((Integer) result).intValue());
}
 
开发者ID:apache,项目名称:commons-jexl,代码行数:24,代码来源:SandboxTest.java

示例3: match

import org.apache.commons.jexl3.JexlContext; //导入方法依赖的package包/类
@Override
public MatchResult match(FlowPosition flowPosition) {
	final JexlContext ctx = new MapContext();
	ctx.set("serviceName", flowPosition.toString());
	Object result = expression.evaluate(ctx);
	verifyExpressionResult(sid, result);
	if ((Boolean) result) {
		return new MatchResult(true, sid);
	}
	return MatchResult.FALSE;
}
 
开发者ID:wmaop,项目名称:wm-aop,代码行数:12,代码来源:JexlServiceNameMatcher.java

示例4: match

import org.apache.commons.jexl3.JexlContext; //导入方法依赖的package包/类
public MatchResult match(FlowPosition flowPosition) {
	final JexlContext ctx = new MapContext();
	ctx.set("serviceName", flowPosition.toString());
	Object result = expression.evaluate(ctx);
	verifyExpressionResult(sid, result);
	if ((Boolean) result) {
		return new MatchResult(true, sid);
	}
	return MatchResult.FALSE;
}
 
开发者ID:wmaop,项目名称:wm-aop,代码行数:11,代码来源:JexlFlowPositionMatcher.java

示例5: evaluateVisibility

import org.apache.commons.jexl3.JexlContext; //导入方法依赖的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

示例6: addAttrTOsToContext

import org.apache.commons.jexl3.JexlContext; //导入方法依赖的package包/类
public static void addAttrTOsToContext(final Collection<AttrTO> attrs, final JexlContext jexlContext) {
    for (AttrTO attr : attrs) {
        if (attr.getSchema() != null) {
            String expressionValue = attr.getValues().isEmpty()
                    ? StringUtils.EMPTY
                    : attr.getValues().get(0);

            LOG.debug("Add attribute {} with value {}", attr.getSchema(), expressionValue);

            jexlContext.set(attr.getSchema(), expressionValue);
        }
    }
}
 
开发者ID:apache,项目名称:syncope,代码行数:14,代码来源:JexlUtils.java

示例7: example

import org.apache.commons.jexl3.JexlContext; //导入方法依赖的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

示例8: example

import org.apache.commons.jexl3.JexlContext; //导入方法依赖的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.JexlContext.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。