Example usage for org.springframework.expression.spel.support StandardEvaluationContext getTypeConverter

List of usage examples for org.springframework.expression.spel.support StandardEvaluationContext getTypeConverter

Introduction

In this page you can find the example usage for org.springframework.expression.spel.support StandardEvaluationContext getTypeConverter.

Prototype

@Override
    public TypeConverter getTypeConverter() 

Source Link

Usage

From source file:org.craftercms.core.util.template.impl.spel.SpELStringTemplateCompiler.java

@PostConstruct
public void init() {
    if (evalContext == null) {
        evalContext = new StandardEvaluationContext();
    }//from   ww w .j  a v  a2s .  c  o m

    if (evalContext instanceof StandardEvaluationContext) {
        StandardEvaluationContext standardEvalContext = (StandardEvaluationContext) evalContext;
        // PropertyAccessor used when the model is a BeanFactory.
        standardEvalContext.addPropertyAccessor(new BeanFactoryAccessor());
        if (beanFactory != null) {
            if (standardEvalContext.getBeanResolver() == null) {
                standardEvalContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
            }
            if (standardEvalContext.getTypeLocator() == null) {
                standardEvalContext.setTypeLocator(new StandardTypeLocator(beanFactory.getBeanClassLoader()));
            }
            if (standardEvalContext.getTypeConverter() == null) {
                ConversionService conversionService = beanFactory.getConversionService();
                if (conversionService != null) {
                    standardEvalContext.setTypeConverter(new StandardTypeConverter(conversionService));
                }
            }
        }
    }
}

From source file:org.springframework.integration.handler.support.MessagingMethodInvokerHelper.java

private void prepareEvaluationContext() throws Exception {
    StandardEvaluationContext context = getEvaluationContext(false);
    Class<?> targetType = AopUtils.getTargetClass(this.targetObject);
    if (this.method != null) {
        context.registerMethodFilter(targetType, new FixedMethodFilter(this.method));
        if (this.expectedType != null) {
            Assert.state(//from  w w  w . ja  va  2s . c  o  m
                    context.getTypeConverter().canConvert(TypeDescriptor.valueOf((this.method).getReturnType()),
                            this.expectedType),
                    "Cannot convert to expected type (" + this.expectedType + ") from " + this.method);
        }
    } else {
        AnnotatedMethodFilter filter = new AnnotatedMethodFilter(this.annotationType, this.methodName,
                this.requiresReply);
        Assert.state(canReturnExpectedType(filter, targetType, context.getTypeConverter()),
                "Cannot convert to expected type (" + this.expectedType + ") from " + this.method);
        context.registerMethodFilter(targetType, filter);
    }
    context.setVariable("target", this.targetObject);
    context.registerFunction("requiredHeader",
            ParametersWrapper.class.getDeclaredMethod("getHeader", Map.class, String.class));
}

From source file:org.springframework.integration.util.MessagingMethodInvokerHelper.java

private void prepareEvaluationContext(StandardEvaluationContext context, Object method,
        Class<? extends Annotation> annotationType) {
    Class<?> targetType = AopUtils.getTargetClass(this.targetObject);
    if (method instanceof Method) {
        context.registerMethodFilter(targetType, new FixedMethodFilter((Method) method));
        if (expectedType != null) {
            Assert.state(//  ww  w  .  j ava2s . c  o  m
                    context.getTypeConverter().canConvert(
                            TypeDescriptor.valueOf(((Method) method).getReturnType()),
                            TypeDescriptor.valueOf(expectedType)),
                    "Cannot convert to expected type (" + expectedType + ") from " + method);
        }
    } else if (method == null || method instanceof String) {
        AnnotatedMethodFilter filter = new AnnotatedMethodFilter(annotationType, (String) method,
                this.requiresReply);
        Assert.state(canReturnExpectedType(filter, targetType, context.getTypeConverter()),
                "Cannot convert to expected type (" + expectedType + ") from " + method);
        context.registerMethodFilter(targetType, filter);
    }
    context.setVariable("target", targetObject);
}