Search in sources :

Example 1 with BeanFactoryAccessor

use of org.springframework.context.expression.BeanFactoryAccessor in project core by craftercms.

the class SpELStringTemplateCompiler method init.

@PostConstruct
public void init() {
    if (evalContext == null) {
        evalContext = new StandardEvaluationContext();
    }
    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));
                }
            }
        }
    }
}
Also used : StandardTypeConverter(org.springframework.expression.spel.support.StandardTypeConverter) BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator) ConversionService(org.springframework.core.convert.ConversionService) BeanFactoryAccessor(org.springframework.context.expression.BeanFactoryAccessor) PostConstruct(javax.annotation.PostConstruct)

Example 2 with BeanFactoryAccessor

use of org.springframework.context.expression.BeanFactoryAccessor in project spring-cloud-gcp by spring-cloud.

the class DatastorePersistentEntityImpl method setApplicationContext.

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.context.addPropertyAccessor(new BeanFactoryAccessor());
    this.context.setBeanResolver(new BeanFactoryResolver(applicationContext));
    this.context.setRootObject(applicationContext);
}
Also used : BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) BeanFactoryAccessor(org.springframework.context.expression.BeanFactoryAccessor)

Example 3 with BeanFactoryAccessor

use of org.springframework.context.expression.BeanFactoryAccessor in project spring-cloud-gcp by spring-cloud.

the class DatastoreRepositoryFactory method delegateContextProvider.

private QueryMethodEvaluationContextProvider delegateContextProvider(QueryMethodEvaluationContextProvider evaluationContextProvider) {
    return new QueryMethodEvaluationContextProvider() {

        @Override
        public <T extends Parameters<?, ?>> EvaluationContext getEvaluationContext(T parameters, Object[] parameterValues) {
            StandardEvaluationContext evaluationContext = (StandardEvaluationContext) evaluationContextProvider.getEvaluationContext(parameters, parameterValues);
            evaluationContext.setRootObject(DatastoreRepositoryFactory.this.applicationContext);
            evaluationContext.addPropertyAccessor(new BeanFactoryAccessor());
            evaluationContext.setBeanResolver(new BeanFactoryResolver(DatastoreRepositoryFactory.this.applicationContext));
            return evaluationContext;
        }
    };
}
Also used : BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) Parameters(org.springframework.data.repository.query.Parameters) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) QueryMethodEvaluationContextProvider(org.springframework.data.repository.query.QueryMethodEvaluationContextProvider) BeanFactoryAccessor(org.springframework.context.expression.BeanFactoryAccessor)

Example 4 with BeanFactoryAccessor

use of org.springframework.context.expression.BeanFactoryAccessor in project spring-data-mongodb by spring-projects.

the class BasicMongoPersistentEntity method setApplicationContext.

/*
	 * (non-Javadoc)
	 * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
	 */
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    context.addPropertyAccessor(new BeanFactoryAccessor());
    context.setBeanResolver(new BeanFactoryResolver(applicationContext));
    context.setRootObject(applicationContext);
}
Also used : BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) BeanFactoryAccessor(org.springframework.context.expression.BeanFactoryAccessor)

Example 5 with BeanFactoryAccessor

use of org.springframework.context.expression.BeanFactoryAccessor in project spring-cloud-gcp by spring-cloud.

the class SpannerRepositoryFactory method delegateContextProvider.

private QueryMethodEvaluationContextProvider delegateContextProvider(QueryMethodEvaluationContextProvider evaluationContextProvider) {
    return new QueryMethodEvaluationContextProvider() {

        @Override
        public <T extends Parameters<?, ?>> EvaluationContext getEvaluationContext(T parameters, Object[] parameterValues) {
            StandardEvaluationContext evaluationContext = (StandardEvaluationContext) evaluationContextProvider.getEvaluationContext(parameters, parameterValues);
            evaluationContext.setRootObject(SpannerRepositoryFactory.this.applicationContext);
            evaluationContext.addPropertyAccessor(new BeanFactoryAccessor());
            evaluationContext.setBeanResolver(new BeanFactoryResolver(SpannerRepositoryFactory.this.applicationContext));
            return evaluationContext;
        }
    };
}
Also used : BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) Parameters(org.springframework.data.repository.query.Parameters) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) QueryMethodEvaluationContextProvider(org.springframework.data.repository.query.QueryMethodEvaluationContextProvider) BeanFactoryAccessor(org.springframework.context.expression.BeanFactoryAccessor)

Aggregations

BeanFactoryAccessor (org.springframework.context.expression.BeanFactoryAccessor)6 BeanFactoryResolver (org.springframework.context.expression.BeanFactoryResolver)6 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)3 Parameters (org.springframework.data.repository.query.Parameters)2 QueryMethodEvaluationContextProvider (org.springframework.data.repository.query.QueryMethodEvaluationContextProvider)2 PostConstruct (javax.annotation.PostConstruct)1 ConversionService (org.springframework.core.convert.ConversionService)1 StandardTypeConverter (org.springframework.expression.spel.support.StandardTypeConverter)1 StandardTypeLocator (org.springframework.expression.spel.support.StandardTypeLocator)1