List of usage examples for org.springframework.beans.factory.config BeanExpressionContext BeanExpressionContext
public BeanExpressionContext(ConfigurableBeanFactory beanFactory, @Nullable Scope scope)
From source file:com.github.ljtfreitas.restify.http.spring.contract.metadata.SpelDynamicParameterExpressionResolver.java
public SpelDynamicParameterExpressionResolver(ConfigurableBeanFactory beanFactory) { this.beanFactory = beanFactory; this.resolver = beanFactory.getBeanExpressionResolver(); this.context = new BeanExpressionContext(beanFactory, null); }
From source file:lodsve.core.condition.OnExpressionCondition.java
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String expression = (String) metadata.getAnnotationAttributes(ConditionalOnExpression.class.getName()) .get("value"); String rawExpression = expression; if (!expression.startsWith("#{")) { // For convenience allow user to provide bare expression with no #{} wrapper expression = "#{" + expression + "}"; }/* w ww .j a va 2 s. c o m*/ // Explicitly allow environment placeholders inside the expression expression = context.getEnvironment().resolvePlaceholders(expression); ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); BeanExpressionResolver resolver = (beanFactory != null) ? beanFactory.getBeanExpressionResolver() : null; BeanExpressionContext expressionContext = (beanFactory != null) ? new BeanExpressionContext(beanFactory, null) : null; if (resolver == null) { resolver = new StandardBeanExpressionResolver(); } boolean result = (Boolean) resolver.evaluate(expression, expressionContext); StringBuilder message = new StringBuilder("SpEL expression"); if (metadata instanceof ClassMetadata) { message.append(" on " + ((ClassMetadata) metadata).getClassName()); } message.append(": " + rawExpression); return new ConditionOutcome(result, message.toString()); }
From source file:com.github.jmnarloch.spring.jaxrs.client.support.JaxRsClientProxyFactoryBean.java
/** * Retrieves the service url./*w ww . jav a 2 s .c om*/ * * @return the service url */ private String getServiceUrl() { try { if (!serviceUrl.isEmpty()) { ConfigurableBeanFactory beanFactory = getBeanFactory(); if (beanFactory != null) { return (String) beanFactory.getBeanExpressionResolver().evaluate(serviceUrl, new BeanExpressionContext(beanFactory, null)); } return serviceUrl; } return applicationContext.getBean(serviceUrlProvider).getServiceUrl(); } catch (BeansException e) { throw new IllegalStateException("The service url hasn't been specified and " + "no ServiceUrlProvider has been registered in application context.", e); } }
From source file:cf.spring.servicebroker.ServiceBrokerConfiguration.java
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (beanFactory instanceof ConfigurableBeanFactory) { final ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory; expressionResolver = new BeanExpressionResolver() { @Override/*from w w w . j a v a 2s . c o m*/ public Object evaluate(String expression, BeanExpressionContext beanExpressionContext) throws BeansException { final Object value = cbf.getBeanExpressionResolver().evaluate(expression, expressionContext); return value == null ? null : value.toString(); } }; expressionContext = new BeanExpressionContext(cbf, cbf.getRegisteredScope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)); } else { throw new BeanCreationException( getClass().getName() + " can only be used with a " + ConfigurableBeanFactory.class.getName()); } }
From source file:cf.spring.CfComponentConfiguration.java
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (beanFactory instanceof ConfigurableBeanFactory) { final ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory; expressionResolver = cbf.getBeanExpressionResolver(); expressionContext = new BeanExpressionContext(cbf, cbf.getRegisteredScope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)); } else {// w ww.ja v a2 s.c o m throw new BeanCreationException( getClass().getName() + " can only be used with a " + ConfigurableBeanFactory.class.getName()); } }
From source file:dstrelec.nats.annotation.NatsListenerAnnotationBeanPostProcessor.java
/** * Making a {@link BeanFactory} available is optional; if not set, * {@link NatsListenerConfigurer} beans won't get autodetected and an * {@link #setEndpointRegistry endpoint registry} has to be explicitly configured. * @param beanFactory the {@link BeanFactory} to be used. *///from www . ja va 2 s. com @Override public void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; if (beanFactory instanceof ConfigurableListableBeanFactory) { this.resolver = ((ConfigurableListableBeanFactory) beanFactory).getBeanExpressionResolver(); this.expressionContext = new BeanExpressionContext((ConfigurableListableBeanFactory) beanFactory, null); } }
From source file:morph.plugin.views.annotation.AnnotationMethodHandlerAdapter.java
public void setBeanFactory(BeanFactory beanFactory) { if (beanFactory instanceof ConfigurableBeanFactory) { this.beanFactory = (ConfigurableBeanFactory) beanFactory; this.expressionContext = new BeanExpressionContext(this.beanFactory, new RequestScope()); }//from w w w . j a v a 2 s . c o m }
From source file:org.kuali.rice.krad.datadictionary.DataDictionary.java
/** * Returns a property value for the bean with the given name from the dictionary. * * @param beanName id or name for the bean definition * @param propertyName name of the property to retrieve, must be a valid property configured on * the bean definition//from w w w . j av a2s .c o m * @return Object property value for property */ public Object getDictionaryBeanProperty(String beanName, String propertyName) { Object bean = ddBeans.getSingleton(beanName); if (bean != null) { return ObjectPropertyUtils.getPropertyValue(bean, propertyName); } BeanDefinition beanDefinition = ddBeans.getMergedBeanDefinition(beanName); if (beanDefinition == null) { throw new RuntimeException("Unable to get bean for bean name: " + beanName); } PropertyValues pvs = beanDefinition.getPropertyValues(); if (pvs.contains(propertyName)) { PropertyValue propertyValue = pvs.getPropertyValue(propertyName); Object value; if (propertyValue.isConverted()) { value = propertyValue.getConvertedValue(); } else if (propertyValue.getValue() instanceof String) { String unconvertedValue = (String) propertyValue.getValue(); Scope scope = ddBeans.getRegisteredScope(beanDefinition.getScope()); BeanExpressionContext beanExpressionContext = new BeanExpressionContext(ddBeans, scope); value = ddBeans.getBeanExpressionResolver().evaluate(unconvertedValue, beanExpressionContext); } else { value = propertyValue.getValue(); } return value; } return null; }
From source file:org.springframework.batch.core.jsr.configuration.support.BatchPropertyBeanPostProcessor.java
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (!(beanFactory instanceof ConfigurableListableBeanFactory)) { throw new IllegalArgumentException( "BatchPropertyBeanPostProcessor requires a ConfigurableListableBeanFactory"); }//from w w w .java2 s .c o m this.beanFactory = (ConfigurableListableBeanFactory) beanFactory; this.beanExpressionContext = new BeanExpressionContext(this.beanFactory, this.beanFactory.getBean(StepScope.class)); }
From source file:org.springframework.batch.core.jsr.launch.support.BatchPropertyBeanPostProcessor.java
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (!(beanFactory instanceof ConfigurableListableBeanFactory)) { throw new IllegalArgumentException( "BatchPropertyBeanPostProcessor requires a ConfigurableListableBeanFactory"); }/*from w w w. j a va2s .c o m*/ ConfigurableListableBeanFactory configurableListableBeanFactory = (ConfigurableListableBeanFactory) beanFactory; BeanExpressionContext beanExpressionContext = new BeanExpressionContext(configurableListableBeanFactory, configurableListableBeanFactory.getBean(StepScope.class)); this.jsrExpressionParser = new JsrExpressionParser(new StandardBeanExpressionResolver(), beanExpressionContext); }