當前位置: 首頁>>代碼示例>>Java>>正文


Java SpelExpressionParser.parseExpression方法代碼示例

本文整理匯總了Java中org.springframework.expression.spel.standard.SpelExpressionParser.parseExpression方法的典型用法代碼示例。如果您正苦於以下問題:Java SpelExpressionParser.parseExpression方法的具體用法?Java SpelExpressionParser.parseExpression怎麽用?Java SpelExpressionParser.parseExpression使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.expression.spel.standard.SpelExpressionParser的用法示例。


在下文中一共展示了SpelExpressionParser.parseExpression方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testParsingSimpleTemplateExpression04

import org.springframework.expression.spel.standard.SpelExpressionParser; //導入方法依賴的package包/類
@Test
public void testParsingSimpleTemplateExpression04() throws Exception {
	SpelExpressionParser parser = new SpelExpressionParser();
	Expression expr = parser.parseExpression("${'hello'} world", DEFAULT_TEMPLATE_PARSER_CONTEXT);
	Object o = expr.getValue();
	assertEquals("hello world", o.toString());

	expr = parser.parseExpression("", DEFAULT_TEMPLATE_PARSER_CONTEXT);
	o = expr.getValue();
	assertEquals("", o.toString());

	expr = parser.parseExpression("abc", DEFAULT_TEMPLATE_PARSER_CONTEXT);
	o = expr.getValue();
	assertEquals("abc", o.toString());

	expr = parser.parseExpression("abc", DEFAULT_TEMPLATE_PARSER_CONTEXT);
	o = expr.getValue((Object)null);
	assertEquals("abc", o.toString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:TemplateExpressionParsingTests.java

示例2: 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));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:IndexingTests.java

示例3: checkTemplateParsingError

import org.springframework.expression.spel.standard.SpelExpressionParser; //導入方法依賴的package包/類
private void checkTemplateParsingError(String expression, ParserContext context, String expectedMessage) throws Exception {
	SpelExpressionParser parser = new SpelExpressionParser();
	try {
		parser.parseExpression(expression, context);
		fail("Should have failed with message: " + expectedMessage);
	}
	catch (Exception ex) {
		String message = ex.getMessage();
		if (ex instanceof ExpressionException) {
			message = ((ExpressionException) ex).getSimpleMessage();
		}
		if (!message.equals(expectedMessage)) {
			ex.printStackTrace();
		}
		assertThat(expectedMessage, equalTo(message));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:SpelReproTests.java

示例4: 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));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:SpelCompilationCoverageTests.java

示例5: 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"));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:IndexingTests.java

示例6: limitCollectionGrowing

import org.springframework.expression.spel.standard.SpelExpressionParser; //導入方法依賴的package包/類
@Test
public void limitCollectionGrowing() throws Exception {
	TestClass instance = new TestClass();
	StandardEvaluationContext ctx = new StandardEvaluationContext(instance);
	SpelExpressionParser parser = new SpelExpressionParser( new SpelParserConfiguration(true, true, 3));
	Expression expression = parser.parseExpression("foo[2]");
	expression.setValue(ctx, "2");
	assertThat(instance.getFoo().size(), equalTo(3));
	expression = parser.parseExpression("foo[3]");
	try {
		expression.setValue(ctx, "3");
	} catch(SpelEvaluationException see) {
		assertEquals(SpelMessage.UNABLE_TO_GROW_COLLECTION, see.getMessageCode());
		assertThat(instance.getFoo().size(), equalTo(3));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:EvaluationTests.java

示例7: SPR11348

import org.springframework.expression.spel.standard.SpelExpressionParser; //導入方法依賴的package包/類
@Test
public void SPR11348() {
	Collection<String> coll = new LinkedHashSet<String>();
	coll.add("one");
	coll.add("two");
	coll = Collections.unmodifiableCollection(coll);

	SpelExpressionParser parser = new SpelExpressionParser();
	Expression expr = parser.parseExpression("new java.util.ArrayList(#root)");
	Object value = expr.getValue(coll);
	assertTrue(value instanceof ArrayList);
	@SuppressWarnings("rawtypes")
	ArrayList list = (ArrayList) value;
	assertEquals("one", list.get(0));
	assertEquals("two", list.get(1));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:SpelReproTests.java

示例8: testMethodThrowingException_SPR6941

import org.springframework.expression.spel.standard.SpelExpressionParser; //導入方法依賴的package包/類
/**
 * Check on first usage (when the cachedExecutor in MethodReference is null) that the exception is not wrapped.
 */
@Test
public void testMethodThrowingException_SPR6941() {
	// Test method on inventor: throwException()
	// On 1 it will throw an IllegalArgumentException
	// On 2 it will throw a RuntimeException
	// On 3 it will exit normally
	// In each case it increments the Inventor field 'counter' when invoked

	SpelExpressionParser parser = new SpelExpressionParser();
	Expression expr = parser.parseExpression("throwException(#bar)");

	eContext.setVariable("bar", 2);
	try {
		expr.getValue(eContext);
		fail();
	}
	catch (Exception ex) {
		if (ex instanceof SpelEvaluationException) {
			fail("Should not be a SpelEvaluationException: " + ex);
		}
		// normal
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:MethodInvocationTests.java

示例9: getMartinis

import org.springframework.expression.spel.standard.SpelExpressionParser; //導入方法依賴的package包/類
@Override
public Collection<Martini> getMartinis(@Nullable String spelFilter) {
	String trimmed = null == spelFilter ? "" : spelFilter.trim();

	Collection<Martini> martinis = null;
	if (!trimmed.isEmpty()) {
		SpelExpressionParser parser = new SpelExpressionParser();
		Expression expression = parser.parseExpression(spelFilter);
		martinis = getMartinis(expression);
	}
	return null == martinis ? getMartinis() : martinis;
}
 
開發者ID:qas-guru,項目名稱:martini-core,代碼行數:13,代碼來源:DefaultMixologist.java

示例10: encryptUsingPlatformBean

import org.springframework.expression.spel.standard.SpelExpressionParser; //導入方法依賴的package包/類
@Override
public String encryptUsingPlatformBean(String cleartext) {
    SpelExpressionParser expressionParser = new SpelExpressionParser();
    String encryptExpressionString = ApplicationProperties.get("encryptExpression");
    Expression encryptExpression = expressionParser.parseExpression(encryptExpressionString);

    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setVariable("stringToEncrypt", cleartext);
    return encryptExpression.getValue(context, String.class);
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:11,代碼來源:ResourceServiceImpl.java

示例11: parseSpelExpression

import org.springframework.expression.spel.standard.SpelExpressionParser; //導入方法依賴的package包/類
public static void parseSpelExpression(String property) {

        SpelExpressionParser parser = new SpelExpressionParser();

        //Static value not that useful .. but safe
        Expression exp1 = parser.parseExpression("'safe expression'");
        String constantValue = exp1.getValue(String.class);
        System.out.println("exp1="+constantValue);

        StandardEvaluationContext testContext = new StandardEvaluationContext(TEST_PERSON);
        //Unsafe if the input is control by the user..
        Expression exp2 = parser.parseExpression(property+" == 'Benoit'");
        String dynamicValue = exp2.getValue(testContext, String.class);
        System.out.println("exp2=" + dynamicValue);
    }
 
開發者ID:blackarbiter,項目名稱:Android_Code_Arbiter,代碼行數:16,代碼來源:SpelSample.java

示例12: renderQueryIfExpressionOrReturnQuery

import org.springframework.expression.spel.standard.SpelExpressionParser; //導入方法依賴的package包/類
/**
 * @param query,   the query expression potentially containing a SpEL expression. Must not be {@literal null}.}
 * @param metadata the {@link EntityMetadata} for the given entity. Must not be {@literal null}.
 * @param parser   Must not be {@literal null}.
 * @return
 */
private static String renderQueryIfExpressionOrReturnQuery(String query, EntityMetadata<?> metadata,
                                                           SpelExpressionParser parser) {

  Assert.notNull(query, "query must not be null!");
  Assert.notNull(metadata, "metadata must not be null!");
  Assert.notNull(parser, "parser must not be null!");

  if (!containsExpression(query)) {
    return query;
  }

  StandardEvaluationContext evalContext = new StandardEvaluationContext();
  evalContext.setVariable(ENTITY_NAME, metadata.getJavaType().getName());

  query = potentiallyQuoteExpressionsParameter(query);

  Expression expr = parser.parseExpression(query, ParserContext.TEMPLATE_EXPRESSION);

  String result = expr.getValue(evalContext, String.class);

  if (result == null) {
    return query;
  }

  return potentiallyUnquoteParameterExpressions(result);
}
 
開發者ID:hexagonframework,項目名稱:spring-data-ebean,代碼行數:33,代碼來源:ExpressionBasedStringQuery.java

示例13: SPR12522

import org.springframework.expression.spel.standard.SpelExpressionParser; //導入方法依賴的package包/類
@Test
@SuppressWarnings("rawtypes")
public void SPR12522() {
	SpelExpressionParser parser = new SpelExpressionParser();
	Expression expression = parser.parseExpression("T(java.util.Arrays).asList('')");
	Object value = expression.getValue();
	assertTrue(value instanceof List);
	assertTrue(((List) value).isEmpty());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:10,代碼來源:SpelReproTests.java

示例14: mapAccessorCompilable

import org.springframework.expression.spel.standard.SpelExpressionParser; //導入方法依賴的package包/類
@Test
public void mapAccessorCompilable() {
	Map<String, Object> testMap = getSimpleTestMap();
	StandardEvaluationContext sec = new StandardEvaluationContext();		
	sec.addPropertyAccessor(new MapAccessor());
	SpelExpressionParser sep = new SpelExpressionParser();
	
	// basic
	Expression ex = sep.parseExpression("foo");
	assertEquals("bar",ex.getValue(sec,testMap));
	assertTrue(SpelCompiler.compile(ex));		
	assertEquals("bar",ex.getValue(sec,testMap));

	// compound expression
	ex = sep.parseExpression("foo.toUpperCase()");
	assertEquals("BAR",ex.getValue(sec,testMap));
	assertTrue(SpelCompiler.compile(ex));		
	assertEquals("BAR",ex.getValue(sec,testMap));
	
	// nested map
	Map<String,Map<String,Object>> nestedMap = getNestedTestMap();
	ex = sep.parseExpression("aaa.foo.toUpperCase()");
	assertEquals("BAR",ex.getValue(sec,nestedMap));
	assertTrue(SpelCompiler.compile(ex));		
	assertEquals("BAR",ex.getValue(sec,nestedMap));
	
	// avoiding inserting checkcast because first part of expression returns a Map
	ex = sep.parseExpression("getMap().foo");
	MapGetter mapGetter = new MapGetter();
	assertEquals("bar",ex.getValue(sec,mapGetter));
	assertTrue(SpelCompiler.compile(ex));		
	assertEquals("bar",ex.getValue(sec,mapGetter));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:34,代碼來源:MapAccessorTests.java

示例15: resolveMapKeyValueTypes

import org.springframework.expression.spel.standard.SpelExpressionParser; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void resolveMapKeyValueTypes() {
	mapNotGeneric = new HashMap();
	mapNotGeneric.put("baseAmount", 3.11);
	mapNotGeneric.put("bonusAmount", 7.17);
	SpelExpressionParser parser = new SpelExpressionParser();
	Expression expression = parser.parseExpression("mapNotGeneric");
	assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.HashMap<?, ?>", expression.getValueTypeDescriptor(this).toString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:11,代碼來源:IndexingTests.java


注:本文中的org.springframework.expression.spel.standard.SpelExpressionParser.parseExpression方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。