本文整理汇总了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);
}
示例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));
}
示例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));
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例10: ELExpressionParser
import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
public ELExpressionParser() {
_factory = new ExpressionFactoryImpl();
_context = new SimpleContext();
}
示例11: getContext
import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
protected SimpleContext getContext() {
return _context;
}
示例12: createDefaultParsingElContext
import de.odysseus.el.util.SimpleContext; //导入依赖的package包/类
protected SimpleContext createDefaultParsingElContext() {
return new SimpleContext();
}
示例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;
}
示例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);
}
}