本文整理汇总了Java中org.springframework.expression.spel.support.StandardEvaluationContext类的典型用法代码示例。如果您正苦于以下问题:Java StandardEvaluationContext类的具体用法?Java StandardEvaluationContext怎么用?Java StandardEvaluationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StandardEvaluationContext类属于org.springframework.expression.spel.support包,在下文中一共展示了StandardEvaluationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserInfos
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
@Override
public Map<String, String> getUserInfos(User user, HttpServletRequest request, final Map<String, String> userInfosInComputing) {
Map<String, String> userInfos = new HashMap<String, String>();
for(String name: sgcParam2spelExp.keySet()) {
String expression = sgcParam2spelExp.get(name);
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(expression);
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("user", user);
context.setVariable("request", request);
context.setVariable("userInfosInComputing", userInfosInComputing);
context.setVariable("dateUtils", dateUtils);
String value = (String) exp.getValue(context);
userInfos.put(name, value);
}
return userInfos;
}
示例2: getKeyFilter
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
/**
* Creates the key filter lambda which is responsible to decide how the rate limit will be performed. The key
* is the unique identifier like an IP address or a username.
*
* @param url is used to generated a unique cache key
* @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
* @param expressionParser is used to evaluate the expression if the filter key type is EXPRESSION.
* @param beanFactory used to get full access to all java beans in the SpEl
* @return should not been null. If no filter key type is matching a plain 1 is returned so that all requests uses the same key.
*/
public KeyFilter getKeyFilter(String url, RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
switch(rateLimit.getFilterKeyType()) {
case IP:
return (request) -> url + "-" + request.getRemoteAddr();
case EXPRESSION:
String expression = rateLimit.getExpression();
if(StringUtils.isEmpty(expression)) {
throw new MissingKeyFilterExpressionException();
}
StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new BeanFactoryResolver(beanFactory));
return (request) -> {
//TODO performance problem - how can the request object reused in the expression without setting it as a rootObject
Expression expr = expressionParser.parseExpression(rateLimit.getExpression());
final String value = expr.getValue(context, request, String.class);
return url + "-" + value;
};
}
return (request) -> url + "-" + "1";
}
示例3: skipCondition
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
/**
* Creates the lambda for the skip condition which will be evaluated on each request
*
* @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
* @param expressionParser is used to evaluate the skip expression
* @param beanFactory used to get full access to all java beans in the SpEl
* @return the lamdba condition which will be evaluated lazy - null if there is no condition available.
*/
public Condition skipCondition(RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new BeanFactoryResolver(beanFactory));
if(rateLimit.getSkipCondition() != null) {
return (request) -> {
Expression expr = expressionParser.parseExpression(rateLimit.getSkipCondition());
Boolean value = expr.getValue(context, request, Boolean.class);
return value;
};
}
return null;
}
示例4: test_evaluate_success
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
/******************************** Test(s) ********************************/
@Test
public void test_evaluate_success() {
Mockito.when(expressionParser.parseExpression(Mockito.anyString()))
.thenReturn(expression);
Mockito.when(expression
.getValue(Mockito.any(StandardEvaluationContext.class)))
.thenReturn(new Object());
ukubukaExpressionEvaluator.evaluate(new FileContents(),
new FileRecord(), "fooBar");
Mockito.verify(expressionParser, Mockito.times(1))
.parseExpression(Mockito.anyString());
Mockito.verify(expression, Mockito.times(1))
.getValue(Mockito.any(StandardEvaluationContext.class));
}
示例5: getEligibleOfferings
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
private List<CmsCI> getEligibleOfferings(CmsRfcCI rfcCi, List<CmsCI> serviceOfferings) {
if (serviceOfferings == null) return null;
List<CmsCI> eligibleOfferings = new ArrayList<>();
for (CmsCI offering : serviceOfferings) {
CmsCIAttribute criteriaAttribute = offering.getAttribute("criteria");
String criteria = criteriaAttribute.getDfValue();
if (isLikelyElasticExpression(criteria)) {
criteria = convert(criteria);
}
Expression expression = exprParser.parseExpression(criteria);
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(cmsUtil.custRfcCI2RfcCISimple(rfcCi));
boolean match = expression.getValue(context, Boolean.class);
if (match) {
eligibleOfferings.add(offering);
}
}
return eligibleOfferings;
}
示例6: getEligbleOfferings
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
List<CmsCI> getEligbleOfferings(CmsRfcCISimple cmsRfcCISimple, String offeringNS) {
List<CmsCI> offerings = new ArrayList<>();
List<CmsCI> list = cmsCmProcessor.getCiBy3(offeringNS, "cloud.Offering", null);
for (CmsCI ci: list){
CmsCIAttribute criteriaAttribute = ci.getAttribute("criteria");
String criteria = criteriaAttribute.getDfValue();
if (isLikelyElasticExpression(criteria)){
logger.warn("cloud.Offering CI ID:"+ci.getCiId()+" likely still has elastic search criteria. Evaluation may not be successful!");
logger.info("ES criteria:"+criteria);
criteria = convert(criteria);
logger.info("Converted SPEL criteria:"+criteria);
}
Expression expression = exprParser.parseExpression(criteria);
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(cmsRfcCISimple);
boolean match = (boolean) expression.getValue(context, Boolean.class);
if (match){
offerings.add(ci);
}
}
return offerings;
}
示例7: getMartinis
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
protected Collection<Martini> getMartinis(Expression expression) {
StandardEvaluationContext context = new StandardEvaluationContext();
List<MethodResolver> methodResolvers = context.getMethodResolvers();
ArrayList<MethodResolver> modifiedList = Lists.newArrayList(methodResolvers);
modifiedList.add(new TagResolver(categories));
context.setMethodResolvers(modifiedList);
ImmutableList<Martini> martinis = getMartinis();
List<Martini> matches = Lists.newArrayListWithCapacity(martinis.size());
for (Martini martini : martinis) {
Boolean match = expression.getValue(context, martini, Boolean.class);
if (match) {
matches.add(martini);
}
}
return matches;
}
示例8: generateKey
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
/**
* generate the key based on SPel expression.
*/
protected Object generateKey(String key, ProceedingJoinPoint pjp) throws ExpirableCacheException {
try {
Object target = pjp.getTarget();
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
Object[] allArgs = pjp.getArgs();
if (StringUtils.hasText(key)) {
CacheExpressionDataObject cacheExpressionDataObject = new CacheExpressionDataObject(method, allArgs, target, target.getClass());
EvaluationContext evaluationContext = new StandardEvaluationContext(cacheExpressionDataObject);
SpelExpression spelExpression = getExpression(key, method);
spelExpression.setEvaluationContext(evaluationContext);
return spelExpression.getValue();
}
return keyGenerator.generate(target, method, allArgs);
} catch (Throwable t) {
throw new ExpirableCacheException("### generate key failed");
}
}
示例9: execute
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
@Override
public ScriptResult execute(String id, Map<String, Object> args) {
long startTime = System.currentTimeMillis();
ScriptContext scriptContext = SCRIPT_CONTENT_CACHE.get(id);
if (scriptContext == null || scriptContext.getExpression() == null) {
return ScriptResult.failure(String.format("script(spel): %s not found!", id), null, System.currentTimeMillis() - startTime);
}
EvaluationContext context = new StandardEvaluationContext(args);
for (Map.Entry<String, Object> entry : args.entrySet()) {
context.setVariable(entry.getKey(), entry.getValue());
}
Object obj = scriptContext.getExpression().getValue(context);
return ScriptResult.success(obj, System.currentTimeMillis() - startTime);
}
示例10: calculateFieldComplexity
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
protected Observable<Double> calculateFieldComplexity(ExecutionContext executionContext, GraphQLObjectType parentType, List<Field> fields, Observable<Double> childScore) {
return childScore.flatMap(aDouble -> {
Observable<Double> result = Observable.just(aDouble + NODE_SCORE);
GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, fields.get(0));
if (fieldDef != null) {
GraphQLFieldDefinitionWrapper graphQLFieldDefinitionWrapper = getGraphQLFieldDefinitionWrapper(fieldDef);
if (graphQLFieldDefinitionWrapper != null) {
Expression expression = graphQLFieldDefinitionWrapper.getComplexitySpelExpression();
if (expression != null) {
Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldDef.getArguments(), fields.get(0).getArguments(), executionContext.getVariables());
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable(GraphQLConstants.EXECUTION_COMPLEXITY_CHILD_SCORE, aDouble);
if (argumentValues != null)
context.setVariables(argumentValues);
result = Observable.just(expression.getValue(context, Double.class));
}
}
}
return addComplexityCheckObservable(executionContext, result);
});
}
示例11: mapOfMap_SPR7244
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
@Test
public void mapOfMap_SPR7244() throws Exception {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("uri", "http:");
Map<String, String> nameMap = new LinkedHashMap<String, String>();
nameMap.put("givenName", "Arthur");
map.put("value", nameMap);
StandardEvaluationContext ctx = new StandardEvaluationContext(map);
ExpressionParser parser = new SpelExpressionParser();
String el1 = "#root['value'].get('givenName')";
Expression exp = parser.parseExpression(el1);
Object evaluated = exp.getValue(ctx);
assertEquals("Arthur", evaluated);
String el2 = "#root['value']['givenName']";
exp = parser.parseExpression(el2);
evaluated = exp.getValue(ctx);
assertEquals("Arthur", evaluated);
}
示例12: evaluate
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
private Object evaluate (Object aValue, Context aContext) {
StandardEvaluationContext context = createEvaluationContext(aContext);
if(aValue instanceof String) {
Expression expression = parser.parseExpression((String)aValue,new TemplateParserContext(PREFIX,SUFFIX));
try {
return(expression.getValue(context));
}
catch (SpelEvaluationException e) {
logger.debug(e.getMessage());
return aValue;
}
}
else if (aValue instanceof List) {
List<Object> evaluatedlist = new ArrayList<>();
List<Object> list = (List<Object>) aValue;
for(Object item : list) {
evaluatedlist.add(evaluate(item, aContext));
}
return evaluatedlist;
}
else if (aValue instanceof Map) {
return evaluateInternal((Map<String, Object>) aValue, aContext);
}
return aValue;
}
示例13: setValue
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
protected void setValue(String expression, Object value) {
try {
Expression e = parser.parseExpression(expression);
if (e == null) {
fail("Parser returned null for expression");
}
if (DEBUG) {
SpelUtilities.printAbstractSyntaxTree(System.out, e);
}
StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext();
assertTrue("Expression is not writeable but should be", e.isWritable(lContext));
e.setValue(lContext, value);
assertEquals("Retrieved value was not equal to set value", value, e.getValue(lContext,value.getClass()));
} catch (EvaluationException ee) {
ee.printStackTrace();
fail("Unexpected Exception: " + ee.getMessage());
} catch (ParseException pe) {
pe.printStackTrace();
fail("Unexpected Exception: " + pe.getMessage());
}
}
示例14: SPR10452
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
@Test
public void SPR10452() throws Exception {
SpelParserConfiguration configuration = new SpelParserConfiguration(false, false);
ExpressionParser parser = new SpelExpressionParser(configuration);
StandardEvaluationContext context = new StandardEvaluationContext();
Expression spel = parser.parseExpression("#enumType.values()");
context.setVariable("enumType", ABC.class);
Object result = spel.getValue(context);
assertNotNull(result);
assertTrue(result.getClass().isArray());
assertEquals(ABC.A, Array.get(result, 0));
assertEquals(ABC.B, Array.get(result, 1));
assertEquals(ABC.C, Array.get(result, 2));
context.setVariable("enumType", XYZ.class);
result = spel.getValue(context);
assertNotNull(result);
assertTrue(result.getClass().isArray());
assertEquals(XYZ.X, Array.get(result, 0));
assertEquals(XYZ.Y, Array.get(result, 1));
assertEquals(XYZ.Z, Array.get(result, 2));
}
示例15: testSpecialVariables
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testSpecialVariables() throws Exception {
// create an array of integers
List<Integer> primes = new ArrayList<Integer>();
primes.addAll(Arrays.asList(2,3,5,7,11,13,17));
// create parser and set variable 'primes' as the array of integers
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("primes",primes);
// all prime numbers > 10 from the list (using selection ?{...})
List<Integer> primesGreaterThanTen = (List<Integer>) parser.parseExpression("#primes.?[#this>10]").getValue(context);
assertEquals("[11, 13, 17]",primesGreaterThanTen.toString());
}