本文整理汇总了Java中org.springframework.expression.spel.standard.SpelExpression类的典型用法代码示例。如果您正苦于以下问题:Java SpelExpression类的具体用法?Java SpelExpression怎么用?Java SpelExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpelExpression类属于org.springframework.expression.spel.standard包,在下文中一共展示了SpelExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: generateKey
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的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");
}
}
开发者ID:profullstack,项目名称:spring-seed,代码行数:21,代码来源:ExpirableCacheAspect.java
示例2: parseCheck
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
/**
* Parse the supplied expression and then create a string representation of the resultant AST, it should be the
* expected value.
*
* @param expression the expression to parse
* @param expectedStringFormOfAST the expected string form of the AST
*/
public void parseCheck(String expression, String expectedStringFormOfAST) {
try {
SpelExpression e = parser.parseRaw(expression);
if (e != null && !e.toStringAST().equals(expectedStringFormOfAST)) {
SpelUtilities.printAbstractSyntaxTree(System.err, e);
}
if (e == null) {
fail("Parsed exception was null");
}
assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST());
} catch (ParseException ee) {
ee.printStackTrace();
fail("Unexpected Exception: " + ee.getMessage());
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:ParsingTests.java
示例3: resolve
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Override
public SpelCriteria resolve(KeyValueQuery<?> query) {
if (query.getCriteria() == null) {
return null;
}
if (query.getCriteria() instanceof SpelExpression) {
return new SpelCriteria((SpelExpression) query.getCriteria());
}
if (query.getCriteria() instanceof String) {
return new SpelCriteria(parser.parseRaw((String) query.getCriteria()));
}
if (query.getCriteria() instanceof SpelCriteria) {
return (SpelCriteria) query.getCriteria();
}
throw new IllegalArgumentException("Cannot create SpelCriteria for " + query.getCriteria());
}
开发者ID:spring-projects,项目名称:spring-data-keyvalue,代码行数:22,代码来源:SpelCriteriaAccessor.java
示例4: createQueryForMethodWithArgs
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
private KeyValueQuery<SpelExpression> createQueryForMethodWithArgs(String methodName, Object... args)
throws NoSuchMethodException, SecurityException {
Class<?>[] argTypes = new Class<?>[args.length];
if (!ObjectUtils.isEmpty(args)) {
for (int i = 0; i < args.length; i++) {
argTypes[i] = args[i].getClass();
}
}
Method method = PersonRepository.class.getMethod(methodName, argTypes);
doReturn(Person.class).when(metadataMock).getReturnedDomainClass(method);
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(
new QueryMethod(method, metadataMock, new SpelAwareProxyProjectionFactory()).getParameters(), args));
KeyValueQuery<SpelExpression> q = creator.createQuery();
q.getCriteria().setEvaluationContext(new StandardEvaluationContext(args));
return q;
}
开发者ID:spring-projects,项目名称:spring-data-keyvalue,代码行数:24,代码来源:SpelQueryCreatorUnitTests.java
示例5: checkConstantList
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
private void checkConstantList(String expressionText, boolean expectedToBeConstant) {
SpelExpressionParser parser = new SpelExpressionParser();
SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
SpelNode node = expression.getAST();
assertTrue(node instanceof InlineList);
InlineList inlineList = (InlineList) node;
if (expectedToBeConstant) {
assertTrue(inlineList.isConstant());
}
else {
assertFalse(inlineList.isConstant());
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:ListTests.java
示例6: testConstructorInvocation06
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void testConstructorInvocation06() throws Exception {
// repeated evaluation to drive use of cached executor
SpelExpression expr = (SpelExpression) parser.parseExpression("new String('wibble')");
String newString = expr.getValue(String.class);
assertEquals("wibble", newString);
newString = expr.getValue(String.class);
assertEquals("wibble", newString);
// not writable
assertFalse(expr.isWritable(new StandardEvaluationContext()));
// ast
assertEquals("new String('wibble')", expr.toStringAST());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:EvaluationTests.java
示例7: testTypeReferencesAndQualifiedIdentifierCaching
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void testTypeReferencesAndQualifiedIdentifierCaching() throws Exception {
SpelExpression expr = (SpelExpression) parser.parseExpression("T(java.lang.String)");
assertFalse(expr.isWritable(new StandardEvaluationContext()));
assertEquals("T(java.lang.String)", expr.toStringAST());
assertEquals(String.class, expr.getValue(Class.class));
// use cached QualifiedIdentifier:
assertEquals("T(java.lang.String)", expr.toStringAST());
assertEquals(String.class, expr.getValue(Class.class));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:EvaluationTests.java
示例8: operatorVariants
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void operatorVariants() throws Exception {
SpelExpression expr = (SpelExpression)parser.parseExpression("#a < #b");
EvaluationContext ctx = new StandardEvaluationContext();
ctx.setVariable("a", (short)3);
ctx.setVariable("b", (short)6);
assertTrue(expr.getValue(ctx, Boolean.class));
ctx.setVariable("b", (byte)6);
assertTrue(expr.getValue(ctx, Boolean.class));
ctx.setVariable("a", (byte)9);
ctx.setVariable("b", (byte)6);
assertFalse(expr.getValue(ctx, Boolean.class));
ctx.setVariable("a", 10L);
ctx.setVariable("b", (short)30);
assertTrue(expr.getValue(ctx, Boolean.class));
ctx.setVariable("a", (byte)3);
ctx.setVariable("b", (short)30);
assertTrue(expr.getValue(ctx, Boolean.class));
ctx.setVariable("a", (byte)3);
ctx.setVariable("b", 30L);
assertTrue(expr.getValue(ctx, Boolean.class));
ctx.setVariable("a", (byte)3);
ctx.setVariable("b", 30f);
assertTrue(expr.getValue(ctx, Boolean.class));
ctx.setVariable("a", new BigInteger("10"));
ctx.setVariable("b", new BigInteger("20"));
assertTrue(expr.getValue(ctx, Boolean.class));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:EvaluationTests.java
示例9: testOperatorNames
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void testOperatorNames() throws Exception {
Operator node = getOperatorNode((SpelExpression)parser.parseExpression("1==3"));
assertEquals("==",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("1!=3"));
assertEquals("!=",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3/3"));
assertEquals("/",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3+3"));
assertEquals("+",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3-3"));
assertEquals("-",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3<4"));
assertEquals("<",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3<=4"));
assertEquals("<=",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3*4"));
assertEquals("*",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3%4"));
assertEquals("%",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3>=4"));
assertEquals(">=",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3 between 4"));
assertEquals("between",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3 ^ 4"));
assertEquals("^",node.getOperatorName());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:39,代码来源:OperatorTests.java
示例10: checkConstantMap
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
private void checkConstantMap(String expressionText, boolean expectedToBeConstant) {
SpelExpressionParser parser = new SpelExpressionParser();
SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
SpelNode node = expression.getAST();
assertTrue(node instanceof InlineMap);
InlineMap inlineMap = (InlineMap) node;
if (expectedToBeConstant) {
assertTrue(inlineMap.isConstant());
}
else {
assertFalse(inlineMap.isConstant());
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:MapTests.java
示例11: testUtilities
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void testUtilities() throws ParseException {
SpelExpression expr = (SpelExpression)parser.parseExpression("3+4+5+6+7-2");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
SpelUtilities.printAbstractSyntaxTree(ps, expr);
ps.flush();
String s = baos.toString();
// ===> Expression '3+4+5+6+7-2' - AST start
// OperatorMinus value:(((((3 + 4) + 5) + 6) + 7) - 2) #children:2
// OperatorPlus value:((((3 + 4) + 5) + 6) + 7) #children:2
// OperatorPlus value:(((3 + 4) + 5) + 6) #children:2
// OperatorPlus value:((3 + 4) + 5) #children:2
// OperatorPlus value:(3 + 4) #children:2
// CompoundExpression value:3
// IntLiteral value:3
// CompoundExpression value:4
// IntLiteral value:4
// CompoundExpression value:5
// IntLiteral value:5
// CompoundExpression value:6
// IntLiteral value:6
// CompoundExpression value:7
// IntLiteral value:7
// CompoundExpression value:2
// IntLiteral value:2
// ===> Expression '3+4+5+6+7-2' - AST end
assertTrue(s.contains("===> Expression '3+4+5+6+7-2' - AST start"));
assertTrue(s.contains(" OpPlus value:((((3 + 4) + 5) + 6) + 7) #children:2"));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:ReflectionHelperTests.java
示例12: projectionTypeDescriptors_1
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void projectionTypeDescriptors_1() throws Exception {
StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
SpelExpressionParser parser = new SpelExpressionParser();
String el1 = "ls.![#this.equals('abc')]";
SpelExpression exp = parser.parseRaw(el1);
List<?> value = (List<?>) exp.getValue(ctx);
// value is list containing [true,false]
assertEquals(Boolean.class, value.get(0).getClass());
TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
assertEquals(null, evaluated.getElementTypeDescriptor());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:SpelReproTests.java
示例13: projectionTypeDescriptors_2
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void projectionTypeDescriptors_2() throws Exception {
StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
SpelExpressionParser parser = new SpelExpressionParser();
String el1 = "as.![#this.equals('abc')]";
SpelExpression exp = parser.parseRaw(el1);
Object[] value = (Object[]) exp.getValue(ctx);
// value is array containing [true,false]
assertEquals(Boolean.class, value[0].getClass());
TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
assertEquals(Boolean.class, evaluated.getElementTypeDescriptor().getType());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:SpelReproTests.java
示例14: projectionTypeDescriptors_3
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void projectionTypeDescriptors_3() throws Exception {
StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
SpelExpressionParser parser = new SpelExpressionParser();
String el1 = "ms.![key.equals('abc')]";
SpelExpression exp = parser.parseRaw(el1);
List<?> value = (List<?>) exp.getValue(ctx);
// value is list containing [true,false]
assertEquals(Boolean.class, value.get(0).getClass());
TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
assertEquals(null, evaluated.getElementTypeDescriptor());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:SpelReproTests.java
示例15: greaterThanWithNulls_SPR7840
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void greaterThanWithNulls_SPR7840() throws Exception {
List<D> list = new ArrayList<D>();
list.add(new D("aaa"));
list.add(new D("bbb"));
list.add(new D(null));
list.add(new D("ccc"));
list.add(new D(null));
list.add(new D("zzz"));
StandardEvaluationContext ctx = new StandardEvaluationContext(list);
SpelExpressionParser parser = new SpelExpressionParser();
String el1 = "#root.?[a < 'hhh']";
SpelExpression exp = parser.parseRaw(el1);
Object value = exp.getValue(ctx);
assertEquals("[D(aaa), D(bbb), D(null), D(ccc), D(null)]", value.toString());
String el2 = "#root.?[a > 'hhh']";
SpelExpression exp2 = parser.parseRaw(el2);
Object value2 = exp2.getValue(ctx);
assertEquals("[D(zzz)]", value2.toString());
// trim out the nulls first
String el3 = "#root.?[a!=null].?[a < 'hhh']";
SpelExpression exp3 = parser.parseRaw(el3);
Object value3 = exp3.getValue(ctx);
assertEquals("[D(aaa), D(bbb), D(ccc)]", value3.toString());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:SpelReproTests.java
示例16: reservedWordProperties_9862
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void reservedWordProperties_9862() throws Exception {
StandardEvaluationContext ctx = new StandardEvaluationContext();
SpelExpressionParser parser = new SpelExpressionParser();
SpelExpression expression = parser.parseRaw("T(org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver).CONST");
Object value = expression.getValue(ctx);
assertEquals(value, Reserver.CONST);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:SpelReproTests.java
示例17: array
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void array() {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Expression expression = null;
Object result = null;
expression = parser.parseExpression("new java.lang.Long[0].class");
result = expression.getValue(context, "");
assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());
expression = parser.parseExpression("T(java.lang.Long[])");
result = expression.getValue(context, "");
assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());
expression = parser.parseExpression("T(java.lang.String[][][])");
result = expression.getValue(context, "");
assertEquals("Equal assertion failed: ", "class [[[Ljava.lang.String;", result.toString());
assertEquals("T(java.lang.String[][][])", ((SpelExpression) expression).toStringAST());
expression = parser.parseExpression("new int[0].class");
result = expression.getValue(context, "");
assertEquals("Equal assertion failed: ", "class [I", result.toString());
expression = parser.parseExpression("T(int[][])");
result = expression.getValue(context, "");
assertEquals("class [[I", result.toString());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:SpelReproTests.java
示例18: functionReferenceNonCompilableArguments_SPR12359
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void functionReferenceNonCompilableArguments_SPR12359() throws Exception {
StandardEvaluationContext context = new StandardEvaluationContext(new Object[] { "1" });
context.registerFunction("negate", SomeCompareMethod2.class.getDeclaredMethod(
"negate", Integer.TYPE));
context.setVariable("arg", "2");
int[] ints = new int[]{1,2,3};
context.setVariable("ints",ints);
expression = parser.parseExpression("#negate(#ints.?[#this<2][0])");
assertEquals("-1",expression.getValue(context, Integer.class).toString());
// Selection isn't compilable.
assertFalse(((SpelNodeImpl)((SpelExpression)expression).getAST()).isCompilable());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:SpelCompilationCoverageTests.java
示例19: failsWhenSettingContextForExpression_SPR12326
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
@Test
public void failsWhenSettingContextForExpression_SPR12326() {
SpelExpressionParser parser = new SpelExpressionParser(
new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, getClass().getClassLoader()));
Person3 person = new Person3("foo", 1);
SpelExpression expression = parser.parseRaw("#it?.age?.equals([0])");
StandardEvaluationContext context = new StandardEvaluationContext(new Object[] { 1 });
context.setVariable("it", person);
expression.setEvaluationContext(context);
assertTrue(expression.getValue(Boolean.class));
assertTrue(expression.getValue(Boolean.class));
assertCanCompile(expression);
assertTrue(expression.getValue(Boolean.class));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:SpelCompilationCoverageTests.java
示例20: listNodes
import org.springframework.expression.spel.standard.SpelExpression; //导入依赖的package包/类
public <T> Collection<T> listNodes(Collection<T> collection, UISearchQuery searchQuery) {
final String criteria = searchQuery.getCriterias();
final List<UISearchQuery.SearchOrder> orders = firstNonNull(searchQuery.getOrders(), Collections.emptyList());
//init sorting
Comparator<T> comparing = (t1, t2) -> 0;
for (UISearchQuery.SearchOrder order : orders) {
comparing = comparing.thenComparing((nodeInfo1, nodeInfo2) -> {
Object value1 = getValue(nodeInfo1, order.getField());
Object value2 = getValue(nodeInfo2, order.getField());
Comparable v1 = value1 instanceof Comparable ? (Comparable) value1 : null;
Comparable v2 = value2 instanceof Comparable ? (Comparable) value2 : null;
@SuppressWarnings("unchecked") int result = Comparables.compare(v1, v2);
return order.getOrder() == ASC ? result : -result;
});
}
final List<Criterion<T>> criterions = new ArrayList<>();
if (StringUtils.hasText(criteria)) {
criterions.add(fromPredicate(w -> {
try {
SpelExpression expr = parser.parseRaw(criteria);
return (Boolean) expr.getValue(w);
} catch (Exception e) {
log.error("error during parsing '" + criteria + "', '" + w + "'", e);
return false;
}
}));
}
criterions.add(topN(comparing, searchQuery.getPage() * searchQuery.getSize(), searchQuery.getSize()));
final Criterion<T> compositeCriteria =
criterions.stream().reduce(c -> c, (c1, c2) -> (s -> c2.apply(c1.apply(s))));
return compositeCriteria.apply(collection.stream()).collect(Collectors.toList());
}
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:38,代码来源:FilterApi.java
注:本文中的org.springframework.expression.spel.standard.SpelExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论