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


Java SpelEvaluationException类代码示例

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


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

示例1: findExecutorForConstructor

import org.springframework.expression.spel.SpelEvaluationException; //导入依赖的package包/类
/**
 * Go through the list of registered constructor resolvers and see if any can find a constructor that takes the
 * specified set of arguments.
 * @param typename the type trying to be constructed
 * @param argumentTypes the types of the arguments supplied that the constructor must take
 * @param state the current state of the expression
 * @return a reusable ConstructorExecutor that can be invoked to run the constructor or null
 * @throws SpelEvaluationException if there is a problem locating the constructor
 */
private ConstructorExecutor findExecutorForConstructor(String typename,
		List<TypeDescriptor> argumentTypes, ExpressionState state)
		throws SpelEvaluationException {

	EvaluationContext eContext = state.getEvaluationContext();
	List<ConstructorResolver> cResolvers = eContext.getConstructorResolvers();
	if (cResolvers != null) {
		for (ConstructorResolver ctorResolver : cResolvers) {
			try {
				ConstructorExecutor cEx = ctorResolver.resolve(state.getEvaluationContext(), typename,
						argumentTypes);
				if (cEx != null) {
					return cEx;
				}
			}
			catch (AccessException ex) {
				throw new SpelEvaluationException(getStartPosition(), ex,
						SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typename,
						FormatHelper.formatMethodForMessage("", argumentTypes));
			}
		}
	}
	throw new SpelEvaluationException(getStartPosition(), SpelMessage.CONSTRUCTOR_NOT_FOUND, typename, FormatHelper
			.formatMethodForMessage("", argumentTypes));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:ConstructorReference.java

示例2: getValueInternal

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

示例3: findAccessorForMethod

import org.springframework.expression.spel.SpelEvaluationException; //导入依赖的package包/类
private MethodExecutor findAccessorForMethod(String name, List<TypeDescriptor> argumentTypes,
		Object targetObject, EvaluationContext evaluationContext) throws SpelEvaluationException {

	List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers();
	if (methodResolvers != null) {
		for (MethodResolver methodResolver : methodResolvers) {
			try {
				MethodExecutor methodExecutor = methodResolver.resolve(
						evaluationContext, targetObject, name, argumentTypes);
				if (methodExecutor != null) {
					return methodExecutor;
				}
			}
			catch (AccessException ex) {
				throw new SpelEvaluationException(getStartPosition(), ex,
						SpelMessage.PROBLEM_LOCATING_METHOD, name, targetObject.getClass());
			}
		}
	}

	throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_NOT_FOUND,
			FormatHelper.formatMethodForMessage(name, argumentTypes),
			FormatHelper.formatClassNameForMessage(
					targetObject instanceof Class ? ((Class<?>) targetObject) : targetObject.getClass()));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:MethodReference.java

示例4: getValueInternal

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

示例5: getValueInternal

import org.springframework.expression.spel.SpelEvaluationException; //导入依赖的package包/类
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	BeanResolver beanResolver = state.getEvaluationContext().getBeanResolver();
	if (beanResolver==null) {
		throw new SpelEvaluationException(getStartPosition(),
				SpelMessage.NO_BEAN_RESOLVER_REGISTERED, this.beanname);
	}

	try {
		TypedValue bean = new TypedValue(beanResolver.resolve(
				state.getEvaluationContext(), this.beanname));
	   return bean;
	}
	catch (AccessException ae) {
		throw new SpelEvaluationException( getStartPosition(), ae, SpelMessage.EXCEPTION_DURING_BEAN_RESOLUTION,
			this.beanname, ae.getMessage());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:BeanReference.java

示例6: setValue

import org.springframework.expression.spel.SpelEvaluationException; //导入依赖的package包/类
@Override
public void setValue(Object newValue) {
	growCollectionIfNecessary();
	if (this.collection instanceof List) {
		List list = (List) this.collection;
		if (this.collectionEntryDescriptor.getElementTypeDescriptor() != null) {
			newValue = this.typeConverter.convertValue(newValue, TypeDescriptor.forObject(newValue),
					this.collectionEntryDescriptor.getElementTypeDescriptor());
		}
		list.set(this.index, newValue);
	}
	else {
		throw new SpelEvaluationException(getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE,
				this.collectionEntryDescriptor.toString());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:Indexer.java

示例7: growCollectionIfNecessary

import org.springframework.expression.spel.SpelEvaluationException; //导入依赖的package包/类
private void growCollectionIfNecessary() {
	if (this.index >= this.collection.size()) {
		if (!this.growCollection) {
			throw new SpelEvaluationException(getStartPosition(), SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS,
					this.collection.size(), this.index);
		}
		if(this.index >= this.maximumSize) {
			throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION);
		}
		if (this.collectionEntryDescriptor.getElementTypeDescriptor() == null) {
			throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION_UNKNOWN_ELEMENT_TYPE);
		}
		TypeDescriptor elementType = this.collectionEntryDescriptor.getElementTypeDescriptor();
		try {
			int newElements = this.index - this.collection.size();
			while (newElements >= 0) {
				(this.collection).add(elementType.getType().newInstance());
				newElements--;
			}
		}
		catch (Exception ex) {
			throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.UNABLE_TO_GROW_COLLECTION);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:Indexer.java

示例8: getValueInternal

import org.springframework.expression.spel.SpelEvaluationException; //导入依赖的package包/类
/**
 * Compare the left operand to see it is an instance of the type specified as the
 * right operand. The right operand must be a class.
 * @param state the expression state
 * @return true if the left operand is an instanceof of the right operand, otherwise
 *         false
 * @throws EvaluationException if there is a problem evaluating the expression
 */
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	TypedValue left = getLeftOperand().getValueInternal(state);
	TypedValue right = getRightOperand().getValueInternal(state);
	Object leftValue = left.getValue();
	Object rightValue = right.getValue();
	if (leftValue == null) {
		return BooleanTypedValue.FALSE;  // null is not an instanceof anything
	}
	if (rightValue == null || !(rightValue instanceof Class<?>)) {
		throw new SpelEvaluationException(getRightOperand().getStartPosition(),
				SpelMessage.INSTANCEOF_OPERATOR_NEEDS_CLASS_OPERAND,
				(rightValue == null ? "null" : rightValue.getClass().getName()));
	}
	Class<?> rightClass = (Class<?>) rightValue;
	return BooleanTypedValue.forValue(rightClass.isAssignableFrom(leftValue.getClass()));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:OperatorInstanceof.java

示例9: isWritableProperty

import org.springframework.expression.spel.SpelEvaluationException; //导入依赖的package包/类
public boolean isWritableProperty(String name, TypedValue contextObject, EvaluationContext eContext) throws SpelEvaluationException {
	List<PropertyAccessor> accessorsToTry = getPropertyAccessorsToTry(contextObject.getValue(), eContext.getPropertyAccessors());
	if (accessorsToTry != null) {
		for (PropertyAccessor accessor : accessorsToTry) {
			try {
				if (accessor.canWrite(eContext, contextObject.getValue(), name)) {
					return true;
				}
			}
			catch (AccessException ae) {
				// let others try
			}
		}
	}
	return false;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:PropertyOrFieldReference.java

示例10: getValueInternal

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

示例11: findType

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

示例12: findExecutorForConstructor

import org.springframework.expression.spel.SpelEvaluationException; //导入依赖的package包/类
/**
 * Go through the list of registered constructor resolvers and see if any can find a
 * constructor that takes the specified set of arguments.
 * @param typeName the type trying to be constructed
 * @param argumentTypes the types of the arguments supplied that the constructor must take
 * @param state the current state of the expression
 * @return a reusable ConstructorExecutor that can be invoked to run the constructor or null
 * @throws SpelEvaluationException if there is a problem locating the constructor
 */
private ConstructorExecutor findExecutorForConstructor(String typeName,
		List<TypeDescriptor> argumentTypes, ExpressionState state)
		throws SpelEvaluationException {

	EvaluationContext evalContext = state.getEvaluationContext();
	List<ConstructorResolver> ctorResolvers = evalContext.getConstructorResolvers();
	if (ctorResolvers != null) {
		for (ConstructorResolver ctorResolver : ctorResolvers) {
			try {
				ConstructorExecutor ce = ctorResolver.resolve(state.getEvaluationContext(), typeName, argumentTypes);
				if (ce != null) {
					return ce;
				}
			}
			catch (AccessException ex) {
				throw new SpelEvaluationException(getStartPosition(), ex,
						SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typeName,
						FormatHelper.formatMethodForMessage("", argumentTypes));
			}
		}
	}
	throw new SpelEvaluationException(getStartPosition(), SpelMessage.CONSTRUCTOR_NOT_FOUND, typeName,
			FormatHelper.formatMethodForMessage("", argumentTypes));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:ConstructorReference.java

示例13: getValueInternal

import org.springframework.expression.spel.SpelEvaluationException; //导入依赖的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<?> list = (List<?>) right;
	Object low = list.get(0);
	Object high = list.get(1);
	TypeComparator comp = state.getTypeComparator();
	try {
		return BooleanTypedValue.forValue(comp.compare(left, low) >= 0 && comp.compare(left, high) <= 0);
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getStartPosition());
		throw ex;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:OperatorBetween.java

示例14: getValueInternal

import org.springframework.expression.spel.SpelEvaluationException; //导入依赖的package包/类
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	TypedValue value = state.lookupVariable(this.name);
	if (value == 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 (!(value.getValue() instanceof Method)) {
		throw new SpelEvaluationException(
				SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, value.getClass());
	}

	try {
		return executeFunctionJLRMethod(state, (Method) value.getValue());
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getStartPosition());
		throw ex;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:FunctionReference.java

示例15: getValueInternal

import org.springframework.expression.spel.SpelEvaluationException; //导入依赖的package包/类
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	BeanResolver beanResolver = state.getEvaluationContext().getBeanResolver();
	if (beanResolver == null) {
		throw new SpelEvaluationException(
				getStartPosition(), SpelMessage.NO_BEAN_RESOLVER_REGISTERED, this.beanName);
	}

	try {
		return new TypedValue(beanResolver.resolve(state.getEvaluationContext(), this.beanName));
	}
	catch (AccessException ex) {
		throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_BEAN_RESOLUTION,
			this.beanName, ex.getMessage());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:BeanReference.java


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