本文整理汇总了Java中org.springframework.expression.spel.standard.SpelExpression类的典型用法代码示例。如果您正苦于以下问题:Java SpelExpression类的具体用法?Java SpelExpression怎么用?Java SpelExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpelExpression类属于org.springframework.expression.spel.standard包,在下文中一共展示了SpelExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
}
示例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());
}
}
示例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());
}
示例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;
}
示例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());
}
}
示例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());
}
示例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));
}
示例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));
}
示例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());
}
示例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());
}
}
示例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"));
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}