本文整理汇总了Java中org.springframework.expression.spel.support.StandardEvaluationContext.setRootObject方法的典型用法代码示例。如果您正苦于以下问题:Java StandardEvaluationContext.setRootObject方法的具体用法?Java StandardEvaluationContext.setRootObject怎么用?Java StandardEvaluationContext.setRootObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.expression.spel.support.StandardEvaluationContext
的用法示例。
在下文中一共展示了StandardEvaluationContext.setRootObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: testRootObject
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Test
public void testRootObject() throws Exception {
GregorianCalendar c = new GregorianCalendar();
c.set(1856, 7, 9);
// The constructor arguments are name, birthday, and nationaltiy.
Inventor tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian");
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("name");
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(tesla);
String name = (String) exp.getValue(context);
assertEquals("Nikola Tesla",name);
}
示例4: testDictionaryAccess
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Test
public void testDictionaryAccess() throws Exception {
StandardEvaluationContext societyContext = new StandardEvaluationContext();
societyContext.setRootObject(new IEEE());
// Officer's Dictionary
Inventor pupin = parser.parseExpression("officers['president']").getValue(societyContext, Inventor.class);
assertNotNull(pupin);
// evaluates to "Idvor"
String city = parser.parseExpression("officers['president'].PlaceOfBirth.city").getValue(societyContext, String.class);
assertNotNull(city);
// setting values
Inventor i = parser.parseExpression("officers['advisors'][0]").getValue(societyContext,Inventor.class);
assertEquals("Nikola Tesla",i.getName());
parser.parseExpression("officers['advisors'][0].PlaceOfBirth.Country").setValue(societyContext, "Croatia");
Inventor i2 = parser.parseExpression("reverse[0]['advisors'][0]").getValue(societyContext,Inventor.class);
assertEquals("Nikola Tesla",i2.getName());
}
示例5: testTernary
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Test
public void testTernary() throws Exception {
String falseString = parser.parseExpression("false ? 'trueExp' : 'falseExp'").getValue(String.class);
assertEquals("falseExp",falseString);
StandardEvaluationContext societyContext = new StandardEvaluationContext();
societyContext.setRootObject(new IEEE());
parser.parseExpression("Name").setValue(societyContext, "IEEE");
societyContext.setVariable("queryName", "Nikola Tesla");
String expression = "isMember(#queryName)? #queryName + ' is a member of the ' "
+ "+ Name + ' Society' : #queryName + ' is not a member of the ' + Name + ' Society'";
String queryResultString = parser.parseExpression(expression).getValue(societyContext, String.class);
assertEquals("Nikola Tesla is a member of the IEEE Society",queryResultString);
// queryResultString = "Nikola Tesla is a member of the IEEE Society"
}
示例6: indexIntoGenericPropertyContainingMapObject
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的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));
}
示例7: testScenario01_Roles
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Test
public void testScenario01_Roles() throws Exception {
try {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext ctx = new StandardEvaluationContext();
Expression expr = parser.parseRaw("hasAnyRole('MANAGER','TELLER')");
ctx.setRootObject(new Person("Ben"));
Boolean value = expr.getValue(ctx,Boolean.class);
assertFalse(value);
ctx.setRootObject(new Manager("Luke"));
value = expr.getValue(ctx,Boolean.class);
assertTrue(value);
} catch (EvaluationException ee) {
ee.printStackTrace();
fail("Unexpected SpelException: " + ee.getMessage());
}
}
示例8: testScenario03_Arithmetic
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Test
public void testScenario03_Arithmetic() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext ctx = new StandardEvaluationContext();
// Might be better with a as a variable although it would work as a property too...
// Variable references using a '#'
Expression expr = parser.parseRaw("(hasRole('SUPERVISOR') or (#a < 1.042)) and hasIpAddress('10.10.0.0/16')");
Boolean value = null;
ctx.setVariable("a",1.0d); // referenced as #a in the expression
ctx.setRootObject(new Supervisor("Ben")); // so non-qualified references 'hasRole()' 'hasIpAddress()' are invoked against it
value = expr.getValue(ctx,Boolean.class);
assertTrue(value);
ctx.setRootObject(new Manager("Luke"));
ctx.setVariable("a",1.043d);
value = expr.getValue(ctx,Boolean.class);
assertFalse(value);
}
示例9: testScenario04_ControllingWhichMethodsRun
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Test
public void testScenario04_ControllingWhichMethodsRun() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.setRootObject(new Supervisor("Ben")); // so non-qualified references 'hasRole()' 'hasIpAddress()' are invoked against it);
ctx.addMethodResolver(new MyMethodResolver()); // NEEDS TO OVERRIDE THE REFLECTION ONE - SHOW REORDERING MECHANISM
// Might be better with a as a variable although it would work as a property too...
// Variable references using a '#'
// SpelExpression expr = parser.parseExpression("(hasRole('SUPERVISOR') or (#a < 1.042)) and hasIpAddress('10.10.0.0/16')");
Expression expr = parser.parseRaw("(hasRole(3) or (#a < 1.042)) and hasIpAddress('10.10.0.0/16')");
Boolean value = null;
ctx.setVariable("a",1.0d); // referenced as #a in the expression
value = expr.getValue(ctx,Boolean.class);
assertTrue(value);
// ctx.setRootObject(new Manager("Luke"));
// ctx.setVariable("a",1.043d);
// value = (Boolean)expr.getValue(ctx,Boolean.class);
// assertFalse(value);
}
示例10: getEvaluationContext
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
private EvaluationContext getEvaluationContext(CmsWorkOrderBase woBase) {
StandardEvaluationContext context = new StandardEvaluationContext();
if (woBase instanceof CmsWorkOrder) {
CmsRfcCISimple rfcSimple = cmsUtil.custRfcCI2RfcCISimple(((CmsWorkOrder)woBase).getRfcCi());
context.setRootObject(rfcSimple);
} else if (woBase instanceof CmsActionOrder) {
CmsCISimple ciSimple = cmsUtil.custCI2CISimple(((CmsActionOrder)woBase).getCi(), CmsConstants.ATTR_VALUE_TYPE_DF, true);
context.setRootObject(ciSimple);
}
return context;
}
示例11: getEvaluationContext
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
private EvaluationContext getEvaluationContext(Object rootObject, Object[] arguments) {
StandardEvaluationContext standardEvaluationContext = new StandardEvaluationContext();
standardEvaluationContext.setBeanResolver(beanFactoryResolver);
// add the parameter values as variables
int index = 0;
for (String name : argumentTypeMap.keySet()) {
standardEvaluationContext.setVariable(name, arguments[index++]);
}
standardEvaluationContext.setRootObject(rootObject);
return standardEvaluationContext;
}
示例12: setupRootContextObject
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
/**
* Create the root context object, an Inventor instance. Non-qualified property
* and method references will be resolved against this context object.
* @param testContext the evaluation context in which to set the root object
*/
private static void setupRootContextObject(StandardEvaluationContext testContext) {
GregorianCalendar c = new GregorianCalendar();
c.set(1856, 7, 9);
Inventor tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian");
tesla.setPlaceOfBirth(new PlaceOfBirth("SmilJan"));
tesla.setInventions(new String[] { "Telephone repeater", "Rotating magnetic field principle",
"Polyphase alternating-current system", "Induction motor", "Alternating-current power transmission",
"Tesla coil transformer", "Wireless communication", "Radio", "Fluorescent lights" });
testContext.setRootObject(tesla);
}
示例13: testEqualityCheck
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Test
public void testEqualityCheck() throws Exception {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(tesla);
Expression exp = parser.parseExpression("name == 'Nikola Tesla'");
boolean isEqual = exp.getValue(context, Boolean.class); // evaluates to true
assertTrue(isEqual);
}
示例14: testPropertyNavigation
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Test
public void testPropertyNavigation() throws Exception {
ExpressionParser parser = new SpelExpressionParser();
// Inventions Array
StandardEvaluationContext teslaContext = TestScenarioCreator.getTestEvaluationContext();
// teslaContext.setRootObject(tesla);
// evaluates to "Induction motor"
String invention = parser.parseExpression("inventions[3]").getValue(teslaContext, String.class);
assertEquals("Induction motor",invention);
// Members List
StandardEvaluationContext societyContext = new StandardEvaluationContext();
IEEE ieee = new IEEE();
ieee.Members[0]= tesla;
societyContext.setRootObject(ieee);
// evaluates to "Nikola Tesla"
String name = parser.parseExpression("Members[0].Name").getValue(societyContext, String.class);
assertEquals("Nikola Tesla",name);
// List and Array navigation
// evaluates to "Wireless communication"
invention = parser.parseExpression("Members[0].Inventions[6]").getValue(societyContext, String.class);
assertEquals("Wireless communication",invention);
}
示例15: testMethodInvocation2
import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Test
public void testMethodInvocation2() throws Exception {
// string literal, evaluates to "bc"
String c = parser.parseExpression("'abc'.substring(1, 3)").getValue(String.class);
assertEquals("bc",c);
StandardEvaluationContext societyContext = new StandardEvaluationContext();
societyContext.setRootObject(new IEEE());
// evaluates to true
boolean isMember = parser.parseExpression("isMember('Mihajlo Pupin')").getValue(societyContext, Boolean.class);
assertTrue(isMember);
}