List of usage examples for org.springframework.expression Expression getValue
@Nullable
<T> T getValue(EvaluationContext context, @Nullable Class<T> desiredResultType) throws EvaluationException;
From source file:org.opentides.util.CrudUtil.java
/** * This method evaluates the given expression from the object. * This method now uses Spring Expression Language (SpEL). * /*from ww w . ja v a 2 s.c om*/ * @param obj * @param expression * @return */ public static Boolean evaluateExpression(Object obj, String expression) { if (StringUtil.isEmpty(expression)) return false; try { ExpressionParser parser = new SpelExpressionParser(); Expression exp = parser.parseExpression(expression); return exp.getValue(obj, Boolean.class); } catch (Exception e) { _log.debug("Failed to evaluate expression [" + expression + "] for object [" + obj.getClass() + "]."); _log.debug(e.getMessage()); return false; } }
From source file:com.px100systems.util.SpringELCtx.java
/** * Iterator-based count using Spring EL/*w ww.ja v a2 s. c o m*/ * @param groupExpression what to group by elements by (optional) * @param iterator the iterator to iterate over * @return the count */ public static Map<String, Long> icount(String groupExpression, Iterator<?> iterator) { Expression grp = groupExpression == null ? null : new SpelExpressionParser().parseExpression(groupExpression); return icount(grp == null ? null : item -> grp.getValue(new SpringELCtx(item), String.class), iterator); }
From source file:com.github.sebhoss.contract.verifier.SpELContractContext.java
@Override public boolean isInViolationWith(final Clause clause) { final Expression expression = parser.parseExpression(clause.value()); return Boolean.FALSE.equals(expression.getValue(context, Boolean.class)); }
From source file:org.arrow.model.gateway.impl.ExclusiveGateway.java
@Override public List<EventMessage> fork(Execution execution, ExecutionService service) { ExpressionParser parser = new SpelExpressionParser(); for (Flow flow : getOutgoingFlows()) { // handle multiple outgoing flows ConditionExpression ce = ((SequenceFlow) flow).getConditionExpression(); if (ce == null) { continue; }/*from w w w .j av a 2s . co m*/ StandardEvaluationContext context = new StandardEvaluationContext(); context.setVariables(execution.getVariables()); Expression expr = parser.parseExpression(ce.getCondition()); Boolean result = expr.getValue(context, Boolean.class); if ((result != null) && (result)) { flow.enableRelation(execution); break; } } // mark gateway as finished execution.setState(State.SUCCESS); finish(execution, service); return Arrays.asList(); }
From source file:uk.co.christhomson.sibyl.cache.connectors.HashMapConnector.java
public Map<?, ?> query(String cacheName, String query) throws CacheException { Map<Object, Object> results = new HashMap<Object, Object>(); Map<?, ?> data = getCache(cacheName); ExpressionParser parser = new SpelExpressionParser(); for (Object key : data.keySet()) { Object value = data.get(key); EvaluationContext keyContext = new StandardEvaluationContext(key); Expression exp = parser.parseExpression(query); boolean result = exp.getValue(keyContext, Boolean.class); if (result) { results.put(key, value);/* ww w . j a va2 s . co m*/ } } return results; }
From source file:com.joyveb.dbpimpl.cass.prepare.mapping.BasicCassandraPersistentEntity.java
/** * Returns the table the entity shall be persisted to. * /*from w w w .j av a 2 s .c o m*/ * @return */ public String getTableName() { Expression expression = parser.parseExpression(table, ParserContext.TEMPLATE_EXPRESSION); return expression.getValue(context, String.class); }
From source file:org.springdata.ehcache.mapping.BasicEhcachePersistentEntity.java
public String getCacheName() { Expression expression = parser.parseExpression(cacheName, ParserContext.TEMPLATE_EXPRESSION); return expression.getValue(context, String.class); }
From source file:it.geosolutions.opensdi2.workflow.ForkAction.java
@Override public void executeAction(WorkflowContext ctx) throws WorkflowException { StandardEvaluationContext inputEvaluationContext = new StandardEvaluationContext(ctx); inputEvaluationContext.setPropertyAccessors(inputPropertyAccessors); if (branches != null) { for (String rule : branches.keySet()) { Expression conversionExpression = expressionParser.parseExpression(rule); boolean parseResult = conversionExpression.getValue(inputEvaluationContext, Boolean.class); if (parseResult) { branches.get(rule).execute(ctx); }/*from w ww . j a v a 2s . c o m*/ } } }
From source file:cz.jirutka.validator.spring.SpELAssertValidator.java
private boolean evaluate(Expression expression, EvaluationContext context) { Boolean result = expression.getValue(context, Boolean.class); return result == null ? false : result; }
From source file:org.arrow.model.gateway.impl.InclusiveGateway.java
/** * {@inheritDoc}/*w w w. j a v a 2s . c o m*/ */ @Override public List<EventMessage> fork(Execution execution, ExecutionService service) { ExpressionParser parser = new SpelExpressionParser(); for (Flow flow : getOutgoingFlows()) { // handle multiple outgoing flows ConditionExpression ce = ((SequenceFlow) flow).getConditionExpression(); notNull(ce, "no condition detected on flow " + flow.getId()); StandardEvaluationContext context = new StandardEvaluationContext(); context.setVariables(execution.getVariables()); Expression expression = parser.parseExpression(ce.getCondition()); Boolean result = expression.getValue(context, Boolean.class); if ((result != null) && result) { flow.enableRelation(execution); } } // mark gateway as finished execution.setState(State.SUCCESS); finish(execution, service); return Arrays.asList(); }