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

Java JexlContext类代码示例

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

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



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

示例1: evaluate

import org.apache.commons.jexl3.JexlContext; //导入依赖的package包/类
@Override
public boolean evaluate(final VariableSource variableSource) {
  if (expression.isPresent()) {
    Set<String> vars = variableSource.getVariableSet();
    JexlContext jc = new MapContext();

    // load the values, if present, into the context
    vars.forEach(variable -> variableSource.get(variable).ifPresent(value -> jc.set(variable, value)));

    Object o = expression.get().evaluate(jc);

    return (o instanceof Boolean) ? (Boolean) o : false;
  }
  else {
    return true;
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:18,代码来源:JexlSelector.java


示例2: beforePropagation

import org.apache.commons.jexl3.JexlContext; //导入依赖的package包/类
@Override
public List<PlainAttrValue> beforePropagation(
        final Item item,
        final Entity entity,
        final List<PlainAttrValue> values) {

    if (StringUtils.isNotBlank(propagationJEXL) && values != null) {
        values.forEach(value -> {
            JexlContext jexlContext = new MapContext();
            if (entity != null) {
                JexlUtils.addFieldsToContext(entity, jexlContext);
                if (entity instanceof Any) {
                    JexlUtils.addPlainAttrsToContext(((Any<?>) entity).getPlainAttrs(), jexlContext);
                    JexlUtils.addDerAttrsToContext(((Any<?>) entity), jexlContext);
                }
            }
            jexlContext.set("value", value.getValueAsString());

            value.setStringValue(JexlUtils.evaluate(propagationJEXL, jexlContext));
        });

        return values;
    }

    return values;
}
 
开发者ID:apache,项目名称:syncope,代码行数:27,代码来源:JEXLItemTransformerImpl.java


示例3: evaluateNAME

import org.apache.commons.jexl3.JexlContext; //导入依赖的package包/类
/**
 * Build __NAME__ for propagation.
 * First look if there is a defined connObjectLink for the given resource (and in
 * this case evaluate as JEXL); otherwise, take given connObjectKey.
 *
 * @param any given any object
 * @param provision external resource
 * @param connObjectKey connector object key
 * @return the value to be propagated as __NAME__
 */
public static Name evaluateNAME(final Any<?> any, final Provision provision, final String connObjectKey) {
    if (StringUtils.isBlank(connObjectKey)) {
        // LOG error but avoid to throw exception: leave it to the external resource
        LOG.error("Missing ConnObjectKey for '{}': ", provision.getResource());
    }

    // Evaluate connObjectKey expression
    String connObjectLink = provision == null || provision.getMapping() == null
            ? null
            : provision.getMapping().getConnObjectLink();
    String evalConnObjectLink = null;
    if (StringUtils.isNotBlank(connObjectLink)) {
        JexlContext jexlContext = new MapContext();
        JexlUtils.addFieldsToContext(any, jexlContext);
        JexlUtils.addPlainAttrsToContext(any.getPlainAttrs(), jexlContext);
        JexlUtils.addDerAttrsToContext(any, jexlContext);
        evalConnObjectLink = JexlUtils.evaluate(connObjectLink, jexlContext);
    }

    return getName(evalConnObjectLink, connObjectKey);
}
 
开发者ID:apache,项目名称:syncope,代码行数:32,代码来源:MappingUtils.java


示例4: evaluate

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


示例5: 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


示例6: eval

import org.apache.commons.jexl3.JexlContext; //导入依赖的package包/类
@Override
public Object eval(final String script, final ScriptContext context) throws ScriptException {
    // This is mandated by JSR-223 (see SCR.5.5.2   Methods)
    if (script == null || context == null) {
        throw new NullPointerException("script and context must be non-null");
    }
    // This is mandated by JSR-223 (end of section SCR.4.3.4.1.2 - JexlScript Execution)
    context.setAttribute(CONTEXT_KEY, context, ScriptContext.ENGINE_SCOPE);
    try {
        JexlScript jexlScript = jexlEngine.createScript(script);
        JexlContext ctxt = new JexlContextWrapper(context);
        return jexlScript.execute(ctxt);
    } catch (Exception e) {
        throw new ScriptException(e.toString());
    }
}
 
开发者ID:apache,项目名称:commons-jexl,代码行数:17,代码来源:JexlScriptEngine.java


示例7: getProperty

import org.apache.commons.jexl3.JexlContext; //导入依赖的package包/类
@Override
public Object getProperty(JexlContext context, Object bean, String expr) {
    if (context == null) {
        context = EMPTY_CONTEXT;
    }
    // synthetize expr using register
    String src = trimSource(expr);
    src = "#0" + (src.charAt(0) == '[' ? "" : ".") + src;
    try {
        final Scope scope = new Scope(null, "#0");
        final ASTJexlScript script = parse(null, PROPERTY_FEATURES, src, scope);
        final JexlNode node = script.jjtGetChild(0);
        final Scope.Frame frame = script.createFrame(bean);
        final Interpreter interpreter = createInterpreter(context, frame);
        return node.jjtAccept(interpreter, null);
    } catch (JexlException xjexl) {
        if (silent) {
            logger.warn(xjexl.getMessage(), xjexl.getCause());
            return null;
        }
        throw xjexl.clean();
    }
}
 
开发者ID:apache,项目名称:commons-jexl,代码行数:24,代码来源:Engine.java


示例8: setProperty

import org.apache.commons.jexl3.JexlContext; //导入依赖的package包/类
@Override
public void setProperty(JexlContext context, Object bean, String expr, Object value) {
    if (context == null) {
        context = EMPTY_CONTEXT;
    }
    // synthetize expr using register
    String src = trimSource(expr);
    src = "#0" + (src.charAt(0) == '[' ? "" : ".") + src + "=" + "#1";
    try {
        final Scope scope = new Scope(null, "#0", "#1");
        final ASTJexlScript script = parse(null, PROPERTY_FEATURES, src, scope);
        final JexlNode node = script.jjtGetChild(0);
        final Scope.Frame frame = script.createFrame(bean, value);
        final Interpreter interpreter = createInterpreter(context, frame);
        node.jjtAccept(interpreter, null);
    } catch (JexlException xjexl) {
        if (silent) {
            logger.warn(xjexl.getMessage(), xjexl.getCause());
            return;
        }
        throw xjexl.clean();
    }
}
 
开发者ID:apache,项目名称:commons-jexl,代码行数:24,代码来源:Engine.java


示例9: 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


示例10: 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


示例11: 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


示例12: match

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


示例13: 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


示例14: getValues

import org.apache.commons.jexl3.JexlContext; //导入依赖的package包/类
private Map<DerSchema, String> getValues(final Any<?> any, final Set<DerSchema> schemas) {
    Map<DerSchema, String> result = new HashMap<>(schemas.size());

    for (DerSchema schema : schemas) {
        JexlContext jexlContext = new MapContext();
        JexlUtils.addPlainAttrsToContext(any.getPlainAttrs(), jexlContext);
        JexlUtils.addFieldsToContext(any, jexlContext);

        result.put(schema, JexlUtils.evaluate(schema.getExpression(), jexlContext));
    }

    return result;
}
 
开发者ID:apache,项目名称:syncope,代码行数:14,代码来源:DerAttrHandlerImpl.java


示例15: beforePull

import org.apache.commons.jexl3.JexlContext; //导入依赖的package包/类
@Override
public List<Object> beforePull(
        final Item item,
        final EntityTO entityTO,
        final List<Object> values) {

    if (StringUtils.isNotBlank(pullJEXL) && values != null) {
        List<Object> newValues = new ArrayList<>(values.size());
        values.forEach(value -> {
            JexlContext jexlContext = new MapContext();
            jexlContext.set("value", value);
            if (entityTO instanceof AnyTO) {
                JexlUtils.addFieldsToContext((AnyTO) entityTO, jexlContext);
                JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getPlainAttrs(), jexlContext);
                JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getDerAttrs(), jexlContext);
                JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getVirAttrs(), jexlContext);
            } else if (entityTO instanceof RealmTO) {
                JexlUtils.addFieldsToContext((RealmTO) entityTO, jexlContext);
                newValues.add(JexlUtils.evaluate(pullJEXL, jexlContext));
            }

            newValues.add(JexlUtils.evaluate(pullJEXL, jexlContext));
        });

        return newValues;
    }

    return JEXLItemTransformer.super.beforePull(item, entityTO, values);
}
 
开发者ID:apache,项目名称:syncope,代码行数:30,代码来源:JEXLItemTransformerImpl.java


示例16: 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


示例17: addPlainAttrsToContext

import org.apache.commons.jexl3.JexlContext; //导入依赖的package包/类
public static void addPlainAttrsToContext(
        final Collection<? extends PlainAttr<?>> attrs, final JexlContext jexlContext) {

    attrs.stream().filter(attr -> attr.getSchema() != null).forEachOrdered((attr) -> {
        List<String> attrValues = attr.getValuesAsStrings();
        String expressionValue = attrValues.isEmpty()
                ? StringUtils.EMPTY
                : attrValues.get(0);

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

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


示例18: addDerAttrsToContext

import org.apache.commons.jexl3.JexlContext; //导入依赖的package包/类
public static void addDerAttrsToContext(final Any<?> any, final JexlContext jexlContext) {
    Map<DerSchema, String> derAttrs =
            ApplicationContextProvider.getBeanFactory().getBean(DerAttrHandler.class).getValues(any);

    derAttrs.entrySet().forEach(entry -> {
        jexlContext.set(entry.getKey().getKey(), entry.getValue());
    });
}
 
开发者ID:apache,项目名称:syncope,代码行数:9,代码来源:JexlUtils.java


示例19: evaluateMandatoryCondition

import org.apache.commons.jexl3.JexlContext; //导入依赖的package包/类
public static boolean evaluateMandatoryCondition(final String mandatoryCondition, final Any<?> any) {
    JexlContext jexlContext = new MapContext();
    addPlainAttrsToContext(any.getPlainAttrs(), jexlContext);
    addDerAttrsToContext(any, jexlContext);

    return Boolean.parseBoolean(evaluate(mandatoryCondition, jexlContext));
}
 
开发者ID:apache,项目名称:syncope,代码行数:8,代码来源:JexlUtils.java


示例20: execute

import org.apache.commons.jexl3.JexlContext; //导入依赖的package包/类
@Override
public Object execute(JexlContext context, Object... args) {
    Scope.Frame callFrame = null;
    if (frame != null) {
        callFrame = frame.assign(args);
    }
    Interpreter interpreter = jexl.createInterpreter(context, callFrame);
    JexlNode block = script.jjtGetChild(script.jjtGetNumChildren() - 1);
    return interpreter.interpret(block);
}
 
开发者ID:apache,项目名称:commons-jexl,代码行数:11,代码来源:Closure.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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