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


Java Expression.getValue方法代碼示例

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


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

示例1: execute

import org.springframework.expression.Expression; //導入方法依賴的package包/類
@Override
public Result execute(Object target) {
    try {
        EvaluationContext ctx = create(target);
        Expression exp = parser.parseExpression(expression);
        Boolean value = (Boolean) exp.getValue(ctx);
        if (value) {
            return ok();
        } else {
            return nok("Expression " + expression + " returned false");
        }
    } catch (Exception e) {
        // TODO - Log me
        return nok("Exception : " + e.getMessage());
    }
}
 
開發者ID:gilles-stragier,項目名稱:quickmon,代碼行數:17,代碼來源:SpelAssertion.java

示例2: getKeyFilter

import org.springframework.expression.Expression; //導入方法依賴的package包/類
/**
 * Creates the key filter lambda which is responsible to decide how the rate limit will be performed. The key
 * is the unique identifier like an IP address or a username.
 * 
 * @param url is used to generated a unique cache key
 * @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
 * @param expressionParser is used to evaluate the expression if the filter key type is EXPRESSION.
 * @param beanFactory used to get full access to all java beans in the SpEl
 * @return should not been null. If no filter key type is matching a plain 1 is returned so that all requests uses the same key.
 */
public KeyFilter getKeyFilter(String url, RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
	
	switch(rateLimit.getFilterKeyType()) {
	case IP:
		return (request) -> url + "-" + request.getRemoteAddr();
	case EXPRESSION:
		String expression = rateLimit.getExpression();
		if(StringUtils.isEmpty(expression)) {
			throw new MissingKeyFilterExpressionException();
		}
		StandardEvaluationContext context = new StandardEvaluationContext();
		context.setBeanResolver(new BeanFactoryResolver(beanFactory));
		return  (request) -> {
			//TODO performance problem - how can the request object reused in the expression without setting it as a rootObject
			Expression expr = expressionParser.parseExpression(rateLimit.getExpression()); 
			final String value = expr.getValue(context, request, String.class);
			return url + "-" + value;
		};
	
	}
	return (request) -> url + "-" + "1";
}
 
開發者ID:MarcGiffing,項目名稱:bucket4j-spring-boot-starter,代碼行數:33,代碼來源:Bucket4JBaseConfiguration.java

示例3: getEligbleOfferings

import org.springframework.expression.Expression; //導入方法依賴的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;
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:23,代碼來源:OfferingsMatcher.java

示例4: isExpressionMatching

import org.springframework.expression.Expression; //導入方法依賴的package包/類
public boolean isExpressionMatching(CmsCI complianceCi, CmsWorkOrderBase wo) {
	
	CmsCIAttribute attr = complianceCi.getAttribute(ATTR_NAME_FILTER);
	if (attr == null) {
		return false;
	}
	String filter = attr.getDjValue();
	
	try {
		if (StringUtils.isNotBlank(filter)) {
			Expression expr = exprParser.parseExpression(filter);
			EvaluationContext context = getEvaluationContext(wo);
			//parse the filter expression and check if it matches this ci/rfc
			Boolean match = expr.getValue(context, Boolean.class);
			if (logger.isDebugEnabled()) {
				logger.debug("Expression " + filter + " provided by compliance ci " + complianceCi.getCiId() + " not matched for ci " + getCiName(wo));	
			}
			
			return match;
		}
	} catch (ParseException | EvaluationException e) {
		String error = "Error in evaluating expression " + filter +" provided by compliance ci " + complianceCi.getCiId() + ", target ci :" + getCiName(wo); 
		logger.error(error, e);
	}
	return false;
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:27,代碼來源:ExpressionEvaluator.java

示例5: getMartinis

import org.springframework.expression.Expression; //導入方法依賴的package包/類
protected Collection<Martini> getMartinis(Expression expression) {
	StandardEvaluationContext context = new StandardEvaluationContext();
	List<MethodResolver> methodResolvers = context.getMethodResolvers();
	ArrayList<MethodResolver> modifiedList = Lists.newArrayList(methodResolvers);
	modifiedList.add(new TagResolver(categories));
	context.setMethodResolvers(modifiedList);

	ImmutableList<Martini> martinis = getMartinis();
	List<Martini> matches = Lists.newArrayListWithCapacity(martinis.size());
	for (Martini martini : martinis) {
		Boolean match = expression.getValue(context, martini, Boolean.class);
		if (match) {
			matches.add(martini);
		}
	}
	return matches;
}
 
開發者ID:qas-guru,項目名稱:martini-core,代碼行數:18,代碼來源:DefaultMixologist.java

示例6: elvis

import org.springframework.expression.Expression; //導入方法依賴的package包/類
@Test
public void elvis() throws Exception {
	Expression expression = parser.parseExpression("'a'?:'b'");
	String resultI = expression.getValue(String.class);
	assertCanCompile(expression);
	String resultC = expression.getValue(String.class);
	assertEquals("a",resultI);
	assertEquals("a",resultC);

	expression = parser.parseExpression("null?:'a'");
	resultI = expression.getValue(String.class);
	assertCanCompile(expression);
	resultC = expression.getValue(String.class);
	assertEquals("a",resultI);
	assertEquals("a",resultC);

	String s = "abc";
	expression = parser.parseExpression("#root?:'b'");
	assertCantCompile(expression);
	resultI = expression.getValue(s,String.class);
	assertEquals("abc",resultI);
	assertCanCompile(expression);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:SpelCompilationCoverageTests.java

示例7: SPR10452

import org.springframework.expression.Expression; //導入方法依賴的package包/類
@Test
public void SPR10452() throws Exception {
	SpelParserConfiguration configuration = new SpelParserConfiguration(false, false);
	ExpressionParser parser = new SpelExpressionParser(configuration);

	StandardEvaluationContext context = new StandardEvaluationContext();
	Expression spel = parser.parseExpression("#enumType.values()");

	context.setVariable("enumType", ABC.class);
	Object result = spel.getValue(context);
	assertNotNull(result);
	assertTrue(result.getClass().isArray());
	assertEquals(ABC.A, Array.get(result, 0));
	assertEquals(ABC.B, Array.get(result, 1));
	assertEquals(ABC.C, Array.get(result, 2));

	context.setVariable("enumType", XYZ.class);
	result = spel.getValue(context);
	assertNotNull(result);
	assertTrue(result.getClass().isArray());
	assertEquals(XYZ.X, Array.get(result, 0));
	assertEquals(XYZ.Y, Array.get(result, 1));
	assertEquals(XYZ.Z, Array.get(result, 2));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:SpelReproTests.java

示例8: format

import org.springframework.expression.Expression; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> T format(Object formatBean, String expressionString) {
	// 解析表達式
	Expression expression = createExpression(expressionString);
	// 構造上下文
	EvaluationContext context = createContext(formatBean);
	// 解析
	return (T) expression.getValue(context);
}
 
開發者ID:zh-cn-trio,項目名稱:trioAop,代碼行數:11,代碼來源:SpelFromat.java

示例9: encrypt

import org.springframework.expression.Expression; //導入方法依賴的package包/類
public String encrypt(String unencryptedValue) {
    
    if (unencryptedValue==null) {
        return null;
    }
    
    final ExpressionParser expressionParser = new SpelExpressionParser();
    final Expression encryptExpression = expressionParser.parseExpression(encryptorImpl);

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

示例10: resolvePrincipal

import org.springframework.expression.Expression; //導入方法依賴的package包/類
String resolvePrincipal(Session session) {
    String principalName = session.getAttribute(PRINCIPAL_NAME_INDEX_NAME);
    if (principalName != null) {
        return principalName;
    }
    
    Object auth = session.getAttribute(SPRING_SECURITY_CONTEXT);
    if (auth == null) {
        return null;
    }
    
    Expression expression = SPEL_PARSER.parseExpression("authentication?.name");
    return expression.getValue(auth, String.class);
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:15,代碼來源:RedissonSessionRepository.java

示例11: isConditionValid

import org.springframework.expression.Expression; //導入方法依賴的package包/類
private static boolean isConditionValid(Expression expression, StandardEvaluationContext context) {
    boolean result;
    if (expression == null || StringUtils.isEmpty(expression.getExpressionString())) {
        result = true;
    } else {
        try {
            result = expression.getValue(context, Boolean.class);
        } catch (Exception e) {
            result = false;
            log.error("Exception while getting value ", e);
        }
    }
    return result;
}
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:15,代碼來源:PermissionCheckService.java

示例12: executeCondition

import org.springframework.expression.Expression; //導入方法依賴的package包/類
/**
 * Creates the lambda for the execute condition which will be evaluated on each request.
 * 
 * @param rateLimit the {@link RateLimit} configuration which holds the execute condition string
 * @param expressionParser is used to evaluate the execution expression
 * @param beanFactory used to get full access to all java beans in the SpEl
 * @return the lamdba condition which will be evaluated lazy - null if there is no condition available.
 */
public Condition executeCondition(RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setBeanResolver(new BeanFactoryResolver(beanFactory));
	
	if(rateLimit.getExecuteCondition() != null) {
		return (request) -> {
			Expression expr = expressionParser.parseExpression(rateLimit.getExecuteCondition()); 
			Boolean value = expr.getValue(context, request, Boolean.class);
			return value;
		};
	}
	return null;
}
 
開發者ID:MarcGiffing,項目名稱:bucket4j-spring-boot-starter,代碼行數:22,代碼來源:Bucket4JBaseConfiguration.java

示例13: getValue

import org.springframework.expression.Expression; //導入方法依賴的package包/類
@Override
public String getValue() throws EvaluationException {
	StringBuilder sb = new StringBuilder();
	for (Expression expression : this.expressions) {
		String value = expression.getValue(String.class);
		if (value != null) {
			sb.append(value);
		}
	}
	return sb.toString();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:CompositeStringExpression.java

示例14: parseSpelExpression

import org.springframework.expression.Expression; //導入方法依賴的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

示例15: encryptUsingPlatformBean

import org.springframework.expression.Expression; //導入方法依賴的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


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