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


Java SimpleContext类代码示例

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


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

示例1: JuelFunction

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
public JuelFunction(String juelExpression, Class<T> resultClass, Map<String, Class<?>> arguments) {
            // Initialize the JUEL conext.
            this.expressionFactory = new de.odysseus.el.ExpressionFactoryImpl();
            this.initializeContext(this.context = new SimpleContext());

            // Index the arguments.
            Class<?>[] argumentTypeClasses = new Class[arguments.size()];
            int argIndex = 0;
            for (Map.Entry<String, Class<?>> argumentEntry : arguments.entrySet()) {
                final String argName = argumentEntry.getKey();
                final Class<?> argTypeClass = argumentEntry.getValue();
                final TreeValueExpression argExpression =
                        this.expressionFactory.createValueExpression(this.context, String.format("${%s}", argName), argTypeClass);
                Argument argument = new Argument(argIndex++, argTypeClass, argExpression);
                argumentTypeClasses[argument.index] = argument.typeClass;
                this.arguments.put(argName, argument);
            }

            // Create the JUEL method.
            this.expression = expressionFactory.createValueExpression(this.context, juelExpression, resultClass);
//            this.expression = expressionFactory.createMethodExpression(this.context, juelExpression, resultClass, argumentTypeClasses);
        }
 
开发者ID:daqcri,项目名称:rheem,代码行数:23,代码来源:JuelUtils.java

示例2: canFilterUsingPojo

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
/**
 * Not really testing our code. Added this to confirm expected behavior of our EL library.
 */
@Test
public void canFilterUsingPojo() {
    SimpleContext context = new SimpleContext();
     ExpressionFactory factory = ExpressionFactory.newInstance();
    ValueExpression expression = factory.createValueExpression(context, "#{msg.localPort == 123}", boolean.class);

    SimpleContext runtimeContext = new SimpleContext();

    final Message message = new Message();
    message.setLocalPort(123);

    factory.createValueExpression(runtimeContext, "${msg}", message.getClass()).setValue(runtimeContext, message);


    assertTrue((boolean) expression.getValue(runtimeContext));
}
 
开发者ID:wired-mind,项目名称:usher,代码行数:20,代码来源:JuelMatcherTests.java

示例3: testExpressionRecognizesChanges

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
@Test
public void testExpressionRecognizesChanges() {
    SimpleContext context = new SimpleContext();
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ValueExpression expression = factory.createValueExpression(context, "#{msg.localPort == 123}", boolean.class);

    SimpleContext runtimeContext = new SimpleContext();

    final Message message = new Message();
    factory.createValueExpression(runtimeContext, "${msg}", message.getClass()).setValue(runtimeContext, message);
    //create the expression first, then set the value on the pojo
    message.setLocalPort(123);




    assertTrue((boolean) expression.getValue(runtimeContext));
    message.setLocalPort(456);
    assertFalse((boolean) expression.getValue(runtimeContext));
}
 
开发者ID:wired-mind,项目名称:usher,代码行数:21,代码来源:JuelMatcherTests.java

示例4: isRevealed

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
protected boolean isRevealed(String relevance, Map<String, Object> answers) {
    if (StringUtils.isBlank(relevance)) {
        return true;
    }
    SimpleContext context = new SimpleContext();
    for (Entry<String, Object> answer : answers.entrySet()) {
        String code = answer.getKey();
        Object value = answer.getValue();
        if (value != null) {
            context.setVariable(code, elFactory.createValueExpression(value, value.getClass()));
        }
    }
    Boolean revealed = false;
    try {
        // Evaluate the condition
        revealed = (Boolean) elFactory.createValueExpression(context, relevance, Boolean.class).getValue(context);
    } catch (ELException e) {
        logger.warn("Errors found in evaluating the relevance condition", e);
    }
    return revealed;
}
 
开发者ID:antoniomaria,项目名称:gazpachoquest,代码行数:22,代码来源:AbstractResolver.java

示例5: initializeContext

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
private void initializeContext(SimpleContext ctx) {
    try {
        ctx.setFunction("math", "sqrt", Math.class.getMethod("sqrt", double.class));
        ctx.setFunction("rheem", "logGrowth", OptimizationUtils.class.getMethod(
                "logisticGrowth", double.class, double.class, double.class, double.class)
        );
    } catch (NoSuchMethodException e) {
        throw new RheemException("Could not initialize JUEL context.", e);
    }
}
 
开发者ID:daqcri,项目名称:rheem,代码行数:11,代码来源:JuelUtils.java

示例6: createContext

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
/**
 * Factory method to create the EL context
 */
protected ELContext createContext() {
    ELResolver resolver = new CompositeELResolver() {
        {
            add(new ArrayELResolver(false));
            add(new ListELResolver(false));
            add(new MapELResolver(false));
            add(new ResourceBundleELResolver());
            add(new BeanAndMethodELResolver());
        }
    };
    return new SimpleContext(resolver);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:JuelExpression.java

示例7: testJuel

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
@Test
public void testJuel() throws Exception {
    ExpressionFactory factory = new ExpressionFactoryImpl();
    ELContext context  = new SimpleContext();
    ValueExpression valueExpression = factory.createValueExpression(context, "${123 * 2}", Object.class);
    Object value = valueExpression.getValue(context);

    assertEquals("Result is a Long object", 246L, value);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:JuelTest.java

示例8: handleGetObject

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
@Override
protected Object handleGetObject(String key) {
	String expression = wrapped.getString(key);
	SimpleContext context = new SimpleContext();
	CompositeELResolver resolver = new CompositeELResolver();
	resolver.add(new IndirectResourceBundleELResolver(wrapped));
	resolver.add(new ResourceBundleELResolver());
	context.setELResolver(resolver);

	ValueExpression ve = factory.createValueExpression(context, expression, String.class);
	String value = (String) ve.getValue(context);
	return value;
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:14,代码来源:ELAwareResourceBundle.java

示例9: setVariable

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
protected void setVariable(ELContext context, String name, Object value, Class<?> type) {
    ValueExpression valueExpression = getExpressionFactory().createValueExpression(value, type);
    SimpleContext simpleContext = (SimpleContext) context;
    simpleContext.setVariable(name, valueExpression);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:6,代码来源:JuelExpression.java

示例10: ELExpressionParser

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
public ELExpressionParser() {
  _factory = new ExpressionFactoryImpl();
  _context = new SimpleContext();
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:5,代码来源:ELExpressionParser.java

示例11: getContext

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
protected SimpleContext getContext() {
  return _context;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:4,代码来源:ELExpressionParser.java

示例12: createDefaultParsingElContext

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
protected SimpleContext createDefaultParsingElContext() {
  return new SimpleContext();
}
 
开发者ID:camunda,项目名称:camunda-engine-dmn,代码行数:4,代码来源:JuelElProvider.java

示例13: createElContext

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
public ELContext createElContext(VariableContext variableContext) {
  SimpleContext elContext = new SimpleContext(resolver);
  elContext.putContext(VariableContext.class, variableContext);
  return elContext;
}
 
开发者ID:camunda,项目名称:camunda-engine-dmn,代码行数:6,代码来源:JuelElContextFactory.java

示例14: execute

import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    initClient();

    SimpleContext context = new SimpleContext();

    for(String variable : variables) {
        context.getELResolver().setValue(context, null, variable, project.getProperties().getProperty(variable));
    }

    try {
        Map<String, String> changes = new HashMap<String, String>();
        for(Property property : properties) {
            String propertyValue = project.getProperties().getProperty(property.getName());

            getLog().info(String.format("%s = %s", property.getName(), propertyValue));

            if(StringUtils.equalsIgnoreCase(propertyValue, "latest")) {
                String name = property.getJobExpr();

                Matcher matcher = EXPRESSION_PATTERN.matcher(name);

                if(matcher.find()) {
                    String content = matcher.group(1);

                    TreeValueExpression expr = (TreeValueExpression) expressionFactory.createValueExpression(context, String.format("${%s}", content), String.class);
                    name = (String) expr.getValue(context);
                }


                JobDetails jobDetails = client.getJobDetails(name);

                changes.put(property.getName() + "-modified", String.valueOf(jobDetails.getLastSuccessfulBuild().getNumber()));
            } else {
                changes.put(String.format("%s-modified", property.getName()), propertyValue);
            }
        }

        if(MapUtils.isNotEmpty(changes)) {
            getLog().info(String.format("Property changes: %s", changes));

            for(Map.Entry<String, String> entry : changes.entrySet()) {
                if(entry.getValue() == null) {
                    continue;
                }

                project.getProperties().setProperty(entry.getKey(), entry.getValue());
            }
        }
    } catch(Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
 
开发者ID:jenkinsmvn,项目名称:jenkinsmvn,代码行数:54,代码来源:PropertyMojo.java


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