All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nepxion.discovery.common.expression.DiscoveryExpressionResolver Maven / Gradle / Ivy

There is a newer version: 6.22.0
Show newest version
package com.nepxion.discovery.common.expression;

/**
 * 

Title: Nepxion Discovery

*

Description: Nepxion Discovery

*

Copyright: Copyright (c) 2017-2050

*

Company: Nepxion

* @author Haojun Ren * @version 1.0 */ import java.util.HashMap; import java.util.Map; import org.springframework.expression.ExpressionParser; import org.springframework.expression.TypeComparator; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; public class DiscoveryExpressionResolver { private static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser(); public static boolean eval(String expression, String key, Map map, TypeComparator typeComparator) { StandardEvaluationContext context = new StandardEvaluationContext(); context.setTypeComparator(typeComparator); if (map != null) { context.setVariable(key, map); } else { context.setVariable(key, new HashMap()); } return eval(expression, context); } public static boolean eval(String expression, StandardEvaluationContext context) { try { Boolean result = EXPRESSION_PARSER.parseExpression(expression).getValue(context, Boolean.class); return result != null ? result.booleanValue() : false; } catch (Exception e) { return false; } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy