当前位置: 首页>>代码示例>>Java>>正文


Java EvaluationException类代码示例

本文整理汇总了Java中org.springframework.expression.EvaluationException的典型用法代码示例。如果您正苦于以下问题:Java EvaluationException类的具体用法?Java EvaluationException怎么用?Java EvaluationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EvaluationException类属于org.springframework.expression包,在下文中一共展示了EvaluationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getValueInternal

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
/**
 * Returns a boolean based on whether a value is in the range expressed. The first
 * operand is any value whilst the second is a list of two values - those two values
 * being the bounds allowed for the first operand (inclusive).
 * @param state the expression state
 * @return true if the left operand is in the range specified, false otherwise
 * @throws EvaluationException if there is a problem evaluating the expression
 */
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	Object left = getLeftOperand().getValueInternal(state).getValue();
	Object right = getRightOperand().getValueInternal(state).getValue();
	if (!(right instanceof List) || ((List<?>) right).size() != 2) {
		throw new SpelEvaluationException(getRightOperand().getStartPosition(),
				SpelMessage.BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST);
	}
	List<?> l = (List<?>) right;
	Object low = l.get(0);
	Object high = l.get(1);
	TypeComparator comparator = state.getTypeComparator();
	try {
		return BooleanTypedValue.forValue((comparator.compare(left, low) >= 0 &&
				comparator.compare(left, high) <= 0));
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getStartPosition());
		throw ex;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:OperatorBetween.java

示例2: getValueInternal

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	TypedValue o = state.lookupVariable(this.name);
	if (o == null) {
		throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_NOT_DEFINED, this.name);
	}

	// Two possibilities: a lambda function or a Java static method registered as a function
	if (!(o.getValue() instanceof Method)) {
		throw new SpelEvaluationException(SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, o.getClass());
	}
	try {
		return executeFunctionJLRMethod(state, (Method) o.getValue());
	}
	catch (SpelEvaluationException se) {
		se.setPosition(getStartPosition());
		throw se;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:FunctionReference.java

示例3: convertTypedValue

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
/**
 * Determines if there is a type converter available in the specified context and
 * attempts to use it to convert the supplied value to the specified type. Throws an
 * exception if conversion is not possible.
 * @param context the evaluation context that may define a type converter
 * @param typedValue the value to convert and a type descriptor describing it
 * @param targetType the type to attempt conversion to
 * @return the converted value
 * @throws EvaluationException if there is a problem during conversion or conversion
 * of the value to the specified type is not supported
 */
@SuppressWarnings("unchecked")
public static <T> T convertTypedValue(EvaluationContext context, TypedValue typedValue, Class<T> targetType) {
	Object value = typedValue.getValue();
	if (targetType == null) {
		return (T) value;
	}
	if (context != null) {
		return (T) context.getTypeConverter().convertValue(
				value, typedValue.getTypeDescriptor(), TypeDescriptor.valueOf(targetType));
	}
	if (ClassUtils.isAssignableValue(targetType, value)) {
		return (T) value;
	}
	throw new EvaluationException("Cannot convert value '" + value + "' to type '" + targetType.getName() + "'");
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:ExpressionUtils.java

示例4: getValueInternal

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
/**
 * Check the first operand matches the regex specified as the second operand.
 * @param state the expression state
 * @return true if the first operand matches the regex specified as the second
 *         operand, otherwise false
 * @throws EvaluationException if there is a problem evaluating the expression (e.g.
 *         the regex is invalid)
 */
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	SpelNodeImpl leftOp = getLeftOperand();
	SpelNodeImpl rightOp = getRightOperand();
	Object left = leftOp.getValue(state, String.class);
	Object right = getRightOperand().getValueInternal(state).getValue();
	try {
		if (!(left instanceof String)) {
			throw new SpelEvaluationException(leftOp.getStartPosition(),
					SpelMessage.INVALID_FIRST_OPERAND_FOR_MATCHES_OPERATOR, left);
		}
		if (!(right instanceof String)) {
			throw new SpelEvaluationException(rightOp.getStartPosition(),
					SpelMessage.INVALID_SECOND_OPERAND_FOR_MATCHES_OPERATOR, right);
		}
		Pattern pattern = Pattern.compile((String) right);
		Matcher matcher = pattern.matcher((String) left);
		return BooleanTypedValue.forValue(matcher.matches());
	}
	catch (PatternSyntaxException pse) {
		throw new SpelEvaluationException(rightOp.getStartPosition(), pse, SpelMessage.INVALID_PATTERN, right);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:OperatorMatches.java

示例5: isExpressionMatching

import org.springframework.expression.EvaluationException; //导入依赖的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

示例6: findType

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
/**
 * Find a (possibly unqualified) type reference - first using the type name as-is,
 * then trying any registered prefixes if the type name cannot be found.
 * @param typeName the type to locate
 * @return the class object for the type
 * @throws EvaluationException if the type cannot be found
 */
@Override
public Class<?> findType(String typeName) throws EvaluationException {
	String nameToLookup = typeName;
	try {
		return ClassUtils.forName(nameToLookup, this.classLoader);
	}
	catch (ClassNotFoundException ey) {
		// try any registered prefixes before giving up
	}
	for (String prefix : this.knownPackagePrefixes) {
		try {
			nameToLookup = prefix + "." + typeName;
			return ClassUtils.forName(nameToLookup, this.classLoader);
		}
		catch (ClassNotFoundException ex) {
			// might be a different prefix
		}
	}
	throw new SpelEvaluationException(SpelMessage.TYPE_NOT_FOUND, typeName);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:StandardTypeLocator.java

示例7: test_evaluate_evaluation_exception

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
@Test(expected = EvaluationException.class)
public void test_evaluate_evaluation_exception() {
    Mockito.when(expressionParser.parseExpression(Mockito.anyString()))
            .thenReturn(expression);
    Mockito.when(expression
            .getValue(Mockito.any(StandardEvaluationContext.class)))
            .thenThrow(new EvaluationException("bar"));

    ukubukaExpressionEvaluator.evaluate(new FileContents(),
            new FileRecord(), "fooBar");
}
 
开发者ID:ukubuka,项目名称:ukubuka-core,代码行数:12,代码来源:UkubukaExpressionEvaluatorTest.java

示例8: getValueInternal

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
/**
 * Implements getValue() - delegating to the code for building an array or a simple type.
 */
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	if (this.isArrayConstructor) {
		return createArray(state);
	}
	else {
		return createNewInstance(state);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:ConstructorReference.java

示例9: getValueInternal

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
/**
 * Evaluate the condition and if true evaluate the first alternative, otherwise
 * evaluate the second alternative.
 * @param state the expression state
 * @throws EvaluationException if the condition does not evaluate correctly to a
 *         boolean or there is a problem executing the chosen alternative
 */
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	Boolean value = this.children[0].getValue(state, Boolean.class);
	if (value == null) {
		throw new SpelEvaluationException(getChild(0).getStartPosition(),
				SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean");
	}
	if (value.booleanValue()) {
		return this.children[1].getValueInternal(state);
	}
	else {
		return this.children[2].getValueInternal(state);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:Ternary.java

示例10: getValueInternal

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
@Override
public TypedValue getValueInternal(ExpressionState expressionState) throws EvaluationException {
	if (this.constant != null) {
		return this.constant;
	}
	else {
		List<Object> returnValue = new ArrayList<Object>();
		int childcount = getChildCount();
		for (int c = 0; c < childcount; c++) {
			returnValue.add(getChild(c).getValue(expressionState));
		}
		return new TypedValue(returnValue);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:InlineList.java

示例11: getValueInternal

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	Object leftOperand = getLeftOperand().getValueInternal(state).getValue();
	Object rightOperand = getRightOperand().getValueInternal(state).getValue();

	if (leftOperand instanceof Number && rightOperand instanceof Number) {
		Number leftNumber = (Number) leftOperand;
		Number rightNumber = (Number) rightOperand;

		if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) {
			BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
			BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
			int scale = Math.max(leftBigDecimal.scale(), rightBigDecimal.scale());
			return new TypedValue(leftBigDecimal.divide(rightBigDecimal, scale, RoundingMode.HALF_EVEN));
		}

		if (leftNumber instanceof Double || rightNumber instanceof Double) {
			return new TypedValue(leftNumber.doubleValue() / rightNumber.doubleValue());
		}
		if (leftNumber instanceof Float || rightNumber instanceof Float) {
			return new TypedValue(leftNumber.floatValue() / rightNumber.floatValue());
		}
		if (leftNumber instanceof Long || rightNumber instanceof Long) {
			return new TypedValue(leftNumber.longValue() / rightNumber.longValue());
		}

		// TODO what about non-int result of the division?
		return new TypedValue(leftNumber.intValue() / rightNumber.intValue());
	}

	return state.operate(Operation.DIVIDE, leftOperand, rightOperand);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:OpDivide.java

示例12: getValueInternal

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	if (getBooleanValue(state, getLeftOperand()) == false) {
		// no need to evaluate right operand
		return BooleanTypedValue.FALSE;
	}
	return BooleanTypedValue.forValue(getBooleanValue(state, getRightOperand()));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:OpAnd.java

示例13: getValueInternal

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	if (getBooleanValue(state, getLeftOperand())) {
		// no need to evaluate right operand
		return BooleanTypedValue.TRUE;
	}
	return BooleanTypedValue.forValue(getBooleanValue(state, getRightOperand()));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:OpOr.java

示例14: getValueInternal

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	try {
		Boolean value = this.children[0].getValue(state, Boolean.class);
		if (value == null) {
			throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean");
		}
		return BooleanTypedValue.forValue(!value);
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getChild(0).getStartPosition());
		throw ex;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:OperatorNot.java

示例15: getValueRef

import org.springframework.expression.EvaluationException; //导入依赖的package包/类
@Override
protected ValueRef getValueRef(ExpressionState state) throws EvaluationException {
	Object[] arguments = getArguments(state);
	if (state.getActiveContextObject().getValue() == null) {
		throwIfNotNullSafe(getArgumentTypes(arguments));
		return ValueRef.NullValueRef.instance;
	}
	return new MethodValueRef(state, arguments);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:MethodReference.java


注:本文中的org.springframework.expression.EvaluationException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。