本文整理汇总了Java中org.springframework.expression.EvaluationContext类的典型用法代码示例。如果您正苦于以下问题:Java EvaluationContext类的具体用法?Java EvaluationContext怎么用?Java EvaluationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EvaluationContext类属于org.springframework.expression包,在下文中一共展示了EvaluationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isWritableProperty
import org.springframework.expression.EvaluationContext; //导入依赖的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;
}
示例2: findExecutorForConstructor
import org.springframework.expression.EvaluationContext; //导入依赖的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));
}
示例3: getCachedExecutor
import org.springframework.expression.EvaluationContext; //导入依赖的package包/类
private MethodExecutor getCachedExecutor(EvaluationContext evaluationContext, Object value,
TypeDescriptor target, List<TypeDescriptor> argumentTypes) {
List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers();
if (methodResolvers == null || methodResolvers.size() != 1 ||
!(methodResolvers.get(0) instanceof ReflectiveMethodResolver)) {
// Not a default ReflectiveMethodResolver - don't know whether caching is valid
return null;
}
CachedMethodExecutor executorToCheck = this.cachedExecutor;
if (executorToCheck != null && executorToCheck.isSuitable(value, target, argumentTypes)) {
return executorToCheck.get();
}
this.cachedExecutor = null;
return null;
}
示例4: findAccessorForMethod
import org.springframework.expression.EvaluationContext; //导入依赖的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()));
}
示例5: execute
import org.springframework.expression.EvaluationContext; //导入依赖的package包/类
@Override
public TypedValue execute(EvaluationContext context, Object... arguments) throws AccessException {
try {
if (arguments != null) {
ReflectionHelper.convertArguments(context.getTypeConverter(), arguments, this.ctor, this.varargsPosition);
}
if (this.ctor.isVarArgs()) {
arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(this.ctor.getParameterTypes(), arguments);
}
ReflectionUtils.makeAccessible(this.ctor);
return new TypedValue(this.ctor.newInstance(arguments));
}
catch (Exception ex) {
throw new AccessException("Problem invoking constructor: " + this.ctor, ex);
}
}
示例6: canRead
import org.springframework.expression.EvaluationContext; //导入依赖的package包/类
@Override
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
if (target == null) {
return false;
}
Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass());
if (type.isArray()) {
return false;
}
if (this.member instanceof Method) {
Method method = (Method) this.member;
String getterName = "get" + StringUtils.capitalize(name);
if (getterName.equals(method.getName())) {
return true;
}
getterName = "is" + StringUtils.capitalize(name);
return getterName.equals(method.getName());
}
else {
Field field = (Field) this.member;
return field.getName().equals(name);
}
}
示例7: execute
import org.springframework.expression.EvaluationContext; //导入依赖的package包/类
@Override
public TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException {
try {
if (arguments != null) {
ReflectionHelper.convertArguments(context.getTypeConverter(), arguments, this.method, this.varargsPosition);
}
if (this.method.isVarArgs()) {
arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(this.method.getParameterTypes(), arguments);
}
ReflectionUtils.makeAccessible(this.method);
Object value = this.method.invoke(target, arguments);
return new TypedValue(value, new TypeDescriptor(new MethodParameter(this.method, -1)).narrow(value));
}
catch (Exception ex) {
throw new AccessException("Problem invoking method: " + this.method, ex);
}
}
示例8: generateKey
import org.springframework.expression.EvaluationContext; //导入依赖的package包/类
/**
* generate the key based on SPel expression.
*/
protected Object generateKey(String key, ProceedingJoinPoint pjp) throws ExpirableCacheException {
try {
Object target = pjp.getTarget();
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
Object[] allArgs = pjp.getArgs();
if (StringUtils.hasText(key)) {
CacheExpressionDataObject cacheExpressionDataObject = new CacheExpressionDataObject(method, allArgs, target, target.getClass());
EvaluationContext evaluationContext = new StandardEvaluationContext(cacheExpressionDataObject);
SpelExpression spelExpression = getExpression(key, method);
spelExpression.setEvaluationContext(evaluationContext);
return spelExpression.getValue();
}
return keyGenerator.generate(target, method, allArgs);
} catch (Throwable t) {
throw new ExpirableCacheException("### generate key failed");
}
}
示例9: convertTypedValue
import org.springframework.expression.EvaluationContext; //导入依赖的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() + "'");
}
示例10: isExpressionMatching
import org.springframework.expression.EvaluationContext; //导入依赖的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;
}
示例11: createContext
import org.springframework.expression.EvaluationContext; //导入依赖的package包/类
@Override
public EvaluationContext createContext(Object root) {
EvaluationContext evaluationContext = getContextMap().get(root);
if (evaluationContext == null) {
evaluationContext = super.createContext(root);
getContextMap().put(root, evaluationContext);
}
return evaluationContext;
}
示例12: format
import org.springframework.expression.EvaluationContext; //导入依赖的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);
}
示例13: create
import org.springframework.expression.EvaluationContext; //导入依赖的package包/类
public EvaluationContext create(Object target) {
StandardEvaluationContext ctx = new StandardEvaluationContext(target);
stream(SpelExtensions.class.getMethods())
.filter(method -> method.getModifiers() == 9)
.forEach(method -> {
ctx.registerFunction(method.getName(), method);
});
return ctx;
}
示例14: decide
import org.springframework.expression.EvaluationContext; //导入依赖的package包/类
@Override
public Mono<Boolean> decide(Authentication authentication, ServerWebExchange object, Flux<ConfigAttribute> configAttributes) {
ConfigAttribute attribute = configAttributes.blockFirst();
EvaluationContext context = handler.createEvaluationContext(authentication, object);
Expression expression = handler.getExpressionParser().parseExpression(attribute.getAttribute());
return Mono.just(ExpressionUtils.evaluateAsBoolean(expression, context));
}
开发者ID:guilhebl,项目名称:item-shop-reactive-backend,代码行数:8,代码来源:ExpressionReactiveAccessDecisionManager.java
示例15: validate_spring_expression
import org.springframework.expression.EvaluationContext; //导入依赖的package包/类
@Ignore
@Test
public void validate_spring_expression ()
throws Exception {
// String url = "http://csaptools.yourcompany.com/admin/api/clusters";
String url = "http://testhost.yourcompany.com:8011/CsAgent/api/collection/application/CsAgent_8011/30/10";
ObjectNode restResponse = analyticsTemplate.getForObject( url, ObjectNode.class );
logger.info( "Url: {} response: {}", url, jacksonMapper.writerWithDefaultPrettyPrinter()
.writeValueAsString( restResponse ) );
ArrayList<Integer> publishvals = jacksonMapper.readValue(
restResponse.at( "/data/publishEvents" )
.traverse(),
new TypeReference<ArrayList<Integer>>() {
} );
int total = publishvals.stream().mapToInt( Integer::intValue ).sum();
logger.info( "Total: {} publishvals: {}", total, publishvals );
EvaluationContext context = new StandardEvaluationContext();
context.setVariable( "total", total );
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression( "#total.toString()" );
logger.info( "SPEL evalutation: {}", (String) exp.getValue( context ) );
exp = parser.parseExpression( "#total > 99" );
logger.info( "#total > 99 SPEL evalutation: {}", (Boolean) exp.getValue( context ) );
exp = parser.parseExpression( "#total > 3" );
logger.info( "#total > 3 SPEL evalutation: {}", (Boolean) exp.getValue( context ) );
}