本文整理匯總了Java中org.springframework.expression.spel.standard.SpelExpressionParser類的典型用法代碼示例。如果您正苦於以下問題:Java SpelExpressionParser類的具體用法?Java SpelExpressionParser怎麽用?Java SpelExpressionParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SpelExpressionParser類屬於org.springframework.expression.spel.standard包,在下文中一共展示了SpelExpressionParser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUserInfos
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的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: getSpringExpressionParser
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的package包/類
/**
* Gets spring expression parser.
*
* @return the spring expression parser
*/
protected SpringELExpressionParser getSpringExpressionParser() {
final SpelParserConfiguration configuration = new SpelParserConfiguration();
final SpelExpressionParser spelExpressionParser = new SpelExpressionParser(configuration);
final SpringELExpressionParser parser = new SpringELExpressionParser(spelExpressionParser,
this.flowBuilderServices.getConversionService());
parser.addPropertyAccessor(new ActionPropertyAccessor());
parser.addPropertyAccessor(new BeanFactoryPropertyAccessor());
parser.addPropertyAccessor(new FlowVariablePropertyAccessor());
parser.addPropertyAccessor(new MapAdaptablePropertyAccessor());
parser.addPropertyAccessor(new MessageSourcePropertyAccessor());
parser.addPropertyAccessor(new ScopeSearchingPropertyAccessor());
parser.addPropertyAccessor(new BeanExpressionContextAccessor());
parser.addPropertyAccessor(new MapAccessor());
parser.addPropertyAccessor(new MapAdaptablePropertyAccessor());
parser.addPropertyAccessor(new EnvironmentAccessor());
parser.addPropertyAccessor(new ReflectivePropertyAccessor());
return parser;
}
示例3: NativeEbeanQuery
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的package包/類
/**
* Creates a new {@link NativeEbeanQuery} encapsulating the query annotated on the given {@link EbeanQueryMethod}.
*
* @param method must not be {@literal null}.
* @param ebeanServer must not be {@literal null}.
* @param queryString must not be {@literal null} or empty.
* @param evaluationContextProvider
*/
public NativeEbeanQuery(EbeanQueryMethod method, EbeanServer ebeanServer, String queryString,
EvaluationContextProvider evaluationContextProvider, SpelExpressionParser parser) {
super(method, ebeanServer, queryString, evaluationContextProvider, parser);
Parameters<?, ?> parameters = method.getParameters();
boolean hasPagingOrSortingParameter = parameters.hasPageableParameter() || parameters.hasSortParameter();
boolean containsPageableOrSortInQueryExpression = queryString.contains("#pageable")
|| queryString.contains("#sort");
if (hasPagingOrSortingParameter && !containsPageableOrSortInQueryExpression) {
throw new InvalidEbeanQueryMethodException(
"Cannot use native queries with dynamic sorting and/or pagination in method " + method);
}
}
示例4: NativeEbeanUpdate
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的package包/類
/**
* Creates a new {@link NativeEbeanUpdate} encapsulating the query annotated on the given {@link EbeanQueryMethod}.
*
* @param method must not be {@literal null}.
* @param ebeanServer must not be {@literal null}.
* @param queryString must not be {@literal null} or empty.
* @param evaluationContextProvider
*/
public NativeEbeanUpdate(EbeanQueryMethod method, EbeanServer ebeanServer, String queryString,
EvaluationContextProvider evaluationContextProvider, SpelExpressionParser parser) {
super(method, ebeanServer, queryString, evaluationContextProvider, parser);
Parameters<?, ?> parameters = method.getParameters();
boolean hasPagingOrSortingParameter = parameters.hasPageableParameter() || parameters.hasSortParameter();
boolean containsPageableOrSortInQueryExpression = queryString.contains("#pageable")
|| queryString.contains("#sort");
if (hasPagingOrSortingParameter && !containsPageableOrSortInQueryExpression) {
throw new InvalidEbeanQueryMethodException(
"Cannot use native queries with dynamic sorting and/or pagination in method " + method);
}
}
示例5: ProducerConfigurationMessageHandler
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的package包/類
ProducerConfigurationMessageHandler(KafkaTemplate<byte[], byte[]> kafkaTemplate, String topic,
ExtendedProducerProperties<KafkaProducerProperties> producerProperties,
ProducerFactory<byte[], byte[]> producerFactory) {
super(kafkaTemplate);
setTopicExpression(new LiteralExpression(topic));
setMessageKeyExpression(producerProperties.getExtension().getMessageKeyExpression());
setBeanFactory(KafkaMessageChannelBinder.this.getBeanFactory());
if (producerProperties.isPartitioned()) {
SpelExpressionParser parser = new SpelExpressionParser();
setPartitionIdExpression(parser.parseExpression("headers." + BinderHeaders.PARTITION_HEADER));
}
if (producerProperties.getExtension().isSync()) {
setSync(true);
}
this.producerFactory = producerFactory;
}
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-kafka,代碼行數:17,代碼來源:KafkaMessageChannelBinder.java
示例6: mapOfMap_SPR7244
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的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);
}
示例7: testLiterals
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的package包/類
@Test
public void testLiterals() throws Exception {
ExpressionParser parser = new SpelExpressionParser();
String helloWorld = (String) parser.parseExpression("'Hello World'").getValue(); // evals to "Hello World"
assertEquals("Hello World",helloWorld);
double avogadrosNumber = (Double) parser.parseExpression("6.0221415E+23").getValue();
assertEquals(6.0221415E+23, avogadrosNumber, 0);
int maxValue = (Integer) parser.parseExpression("0x7FFFFFFF").getValue(); // evals to 2147483647
assertEquals(Integer.MAX_VALUE,maxValue);
boolean trueValue = (Boolean) parser.parseExpression("true").getValue();
assertTrue(trueValue);
Object nullValue = parser.parseExpression("null").getValue();
assertNull(nullValue);
}
示例8: indexerMapAccessor_12045
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的package包/類
@Test
public void indexerMapAccessor_12045() throws Exception {
SpelParserConfiguration spc = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE,this.getClass().getClassLoader());
SpelExpressionParser sep = new SpelExpressionParser(spc);
expression=sep.parseExpression("headers[command]");
MyMessage root = new MyMessage();
assertEquals("wibble",expression.getValue(root));
// This next call was failing because the isCompilable check in Indexer did not check on the key being compilable
// (and also generateCode in the Indexer was missing the optimization that it didn't need necessarily need to call
// generateCode for that accessor)
assertEquals("wibble",expression.getValue(root));
assertCanCompile(expression);
// What about a map key that is an expression - ensure the getKey() is evaluated in the right scope
expression=sep.parseExpression("headers[getKey()]");
assertEquals("wobble",expression.getValue(root));
assertEquals("wobble",expression.getValue(root));
expression=sep.parseExpression("list[getKey2()]");
assertEquals("wobble",expression.getValue(root));
assertEquals("wobble",expression.getValue(root));
expression = sep.parseExpression("ia[getKey2()]");
assertEquals(3,expression.getValue(root));
assertEquals(3,expression.getValue(root));
}
示例9: testSpecialVariables
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的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());
}
示例10: indexIntoGenericPropertyContainingMapObject
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的package包/類
@Test
public void indexIntoGenericPropertyContainingMapObject() {
Map<String, Map<String, String>> property = new HashMap<String, Map<String, String>>();
Map<String, String> map = new HashMap<String, String>();
map.put("foo", "bar");
property.put("property", map);
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
context.addPropertyAccessor(new MapAccessor());
context.setRootObject(property);
Expression expression = parser.parseExpression("property");
assertEquals("java.util.HashMap<?, ?>", expression.getValueTypeDescriptor(context).toString());
assertEquals(map, expression.getValue(context));
assertEquals(map, expression.getValue(context, Map.class));
expression = parser.parseExpression("property['foo']");
assertEquals("bar", expression.getValue(context));
}
示例11: testScenario_AddingYourOwnPropertyResolvers_1
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的package包/類
/**
* Scenario: add a property resolver that will get called in the resolver chain, this one only supports reading.
*/
@Test
public void testScenario_AddingYourOwnPropertyResolvers_1() throws Exception {
// Create a parser
SpelExpressionParser parser = new SpelExpressionParser();
// Use the standard evaluation context
StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.addPropertyAccessor(new FruitColourAccessor());
Expression expr = parser.parseRaw("orange");
Object value = expr.getValue(ctx);
assertEquals(Color.orange, value);
try {
expr.setValue(ctx, Color.blue);
fail("Should not be allowed to set oranges to be blue !");
} catch (SpelEvaluationException ee) {
assertEquals(ee.getMessageCode(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
}
}
示例12: testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的package包/類
/**
* Scenario: using your own java methods and calling them from the expression
*/
@Test
public void testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem() throws SecurityException, NoSuchMethodException {
try {
// Create a parser
SpelExpressionParser parser = new SpelExpressionParser();
// Use the standard evaluation context
StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.registerFunction("repeat",ExpressionLanguageScenarioTests.class.getDeclaredMethod("repeat",String.class));
Expression expr = parser.parseRaw("#repeat('hello')");
Object value = expr.getValue(ctx);
assertEquals("hellohello", value);
} catch (EvaluationException ee) {
ee.printStackTrace();
fail("Unexpected Exception: " + ee.getMessage());
} catch (ParseException pe) {
pe.printStackTrace();
fail("Unexpected Exception: " + pe.getMessage());
}
}
示例13: indexIntoGenericPropertyContainingGrowingList
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的package包/類
@Test
public void indexIntoGenericPropertyContainingGrowingList() {
List<String> property = new ArrayList<String>();
this.property = property;
SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
SpelExpressionParser parser = new SpelExpressionParser(configuration);
Expression expression = parser.parseExpression("property");
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
assertEquals(property, expression.getValue(this));
expression = parser.parseExpression("property[0]");
try {
assertEquals("bar", expression.getValue(this));
} catch (EvaluationException e) {
assertTrue(e.getMessage().startsWith("EL1053E"));
}
}
示例14: indexIntoGenericPropertyContainingGrowingList2
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的package包/類
@Test
public void indexIntoGenericPropertyContainingGrowingList2() {
List<String> property2 = new ArrayList<String>();
this.property2 = property2;
SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
SpelExpressionParser parser = new SpelExpressionParser(configuration);
Expression expression = parser.parseExpression("property2");
assertEquals("java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
assertEquals(property2, expression.getValue(this));
expression = parser.parseExpression("property2[0]");
try {
assertEquals("bar", expression.getValue(this));
} catch (EvaluationException e) {
assertTrue(e.getMessage().startsWith("EL1053E"));
}
}
示例15: testSpel
import org.springframework.expression.spel.standard.SpelExpressionParser; //導入依賴的package包/類
@Test
public void testSpel(){
//使用SPEL進行key的解析
ExpressionParser parser = new SpelExpressionParser();
//SPEL上下文
StandardEvaluationContext context = new StandardEvaluationContext();
//把方法參數放入SPEL上下文中
List<Model> list = MyBatisUtil.parseBase("username,=,leiyong","password,=,asssd","loginName,=,ray");
context.setVariable("objs", list);
System.out.println(parser.parseExpression("#objs[0].column").getValue(context,String.class));
System.out.println(parser.parseExpression("#objs?.![column]").getValue(context,String.class));
System.out.println(parser.parseExpression("#objs?.![column+operate]").getValue(context,String.class));
context.setVariable("obj", list.get(0));
// System.out.println(parser.parseExpression("#orgPk+#userName").getValue(context,String.class));
System.out.println(parser.parseExpression("#obj?.column+#obj?.operate").getValue(context,String.class));
System.out.println(parser.parseExpression("#obj?.column+{':'}+#obj?.operate").getValue(context,String.class));
System.out.println(parser.parseExpression("#obj?.operate").getValue(context,String.class));
System.out.println(parser.parseExpression("#obj?.value").getValue(context,String.class));
System.out.println(parser.parseExpression("#obj?.value").getValue(context,String.class));
System.out.println(parser.parseExpression("'test'").getValue(context,String.class));
System.out.println(parser.parseExpression("#objs?.!['1']").getValue(context,String.class));
}