Example usage for org.springframework.beans.factory.config RuntimeBeanNameReference RuntimeBeanNameReference

List of usage examples for org.springframework.beans.factory.config RuntimeBeanNameReference RuntimeBeanNameReference

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config RuntimeBeanNameReference RuntimeBeanNameReference.

Prototype

public RuntimeBeanNameReference(String beanName) 

Source Link

Document

Create a new RuntimeBeanNameReference to the given bean name.

Usage

From source file:com.tacitknowledge.flip.spring.config.FeatureServiceHandlerParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder factoryBuilder = BeanDefinitionBuilder
            .rootBeanDefinition(FeatureServiceDirectFactory.class);
    RootBeanDefinition factoryBean = (RootBeanDefinition) factoryBuilder.getBeanDefinition();
    parserContext.getRegistry().registerBeanDefinition(FlipSpringAspect.FEATURE_SERVICE_FACTORY_BEAN_NAME,
            factoryBean);//w w  w .  jav a  2  s.c  o m

    MutablePropertyValues factoryPropertyValues = new MutablePropertyValues();
    factoryBean.setPropertyValues(factoryPropertyValues);

    String environmentBean = element.getAttribute("environment");
    if (environmentBean != null && !environmentBean.isEmpty()) {
        factoryPropertyValues.addPropertyValue("environment", new RuntimeBeanNameReference(environmentBean));
    }

    Element contextProvidersElement = DomUtils.getChildElementByTagName(element, "context-providers");
    if (contextProvidersElement != null) {
        List contextProvidersList = parserContext.getDelegate().parseListElement(contextProvidersElement,
                factoryBean);
        if (contextProvidersList != null && !contextProvidersList.isEmpty()) {
            factoryPropertyValues.addPropertyValue("contextProviders", contextProvidersList);
        }
    }

    Element propertyReadersElement = DomUtils.getChildElementByTagName(element, "property-readers");
    if (propertyReadersElement != null && propertyReadersElement.hasChildNodes()) {
        List propertyReadersList = parserContext.getDelegate().parseListElement(propertyReadersElement,
                factoryBean);
        if (propertyReadersList != null && !propertyReadersList.isEmpty()) {
            factoryPropertyValues.addPropertyValue("propertyReaders", propertyReadersList);
        }
    }

    Element propertiesElement = DomUtils.getChildElementByTagName(element, "properties");
    if (propertiesElement != null && propertiesElement.hasChildNodes()) {
        Properties properties = parserContext.getDelegate().parsePropsElement(propertiesElement);
        if (properties != null && !properties.isEmpty()) {
            factoryPropertyValues.addPropertyValue("properties", properties);
        }
    }

    BeanDefinitionBuilder featureServiceBuilder = BeanDefinitionBuilder.genericBeanDefinition();
    BeanDefinition featureServiceRawBean = featureServiceBuilder.getRawBeanDefinition();
    featureServiceRawBean.setFactoryBeanName(FlipSpringAspect.FEATURE_SERVICE_FACTORY_BEAN_NAME);
    featureServiceRawBean.setFactoryMethodName("createFeatureService");
    parserContext.getRegistry().registerBeanDefinition(FlipSpringAspect.FEATURE_SERVICE_BEAN_NAME,
            featureServiceBuilder.getBeanDefinition());

    return null;
}

From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenterTest.java

@Test
public void existingBeanReference() {
    BeanReference br = new RuntimeBeanNameReference(this.beanName);
    this.propertyValues.addPropertyValue(this.key, br);
    Map<String, String> m = new HashMap<String, String>();
    m.put("additional-key", "additional-value");
    this.propertyValues.addPropertyValue("sourceMap", m);

    this.propertyAugmenter.augment(this.beanFactory, this.beanClass, this.key, this.additionalProperties);

    assertTrue(this.propertyValues.contains(this.key));
    assertContainsKey("additional-key");
}

From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenterTest.java

@Test
public void existingPropertiesFactoryBeanLocation() {
    BeanReference br = new RuntimeBeanNameReference(this.beanName);
    this.propertyValues.addPropertyValue(this.key, br);
    when(this.beanDefinition.getBeanClassName()).thenReturn(PropertiesFactoryBean.class.getCanonicalName());
    this.propertyValues.addPropertyValue("location", "alpha.properties");

    this.propertyAugmenter.augment(this.beanFactory, this.beanClass, this.key, this.additionalProperties);

    assertTrue(this.propertyValues.contains(this.key));
    assertContainsKey("alpha");
}

From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenterTest.java

@Test
public void existingPropertiesFactoryBeanLocationTypedStringValue() {
    BeanReference br = new RuntimeBeanNameReference(this.beanName);
    this.propertyValues.addPropertyValue(this.key, br);
    when(this.beanDefinition.getBeanClassName()).thenReturn(PropertiesFactoryBean.class.getCanonicalName());
    this.propertyValues.addPropertyValue("location", new TypedStringValue("alpha.properties"));

    this.propertyAugmenter.augment(this.beanFactory, this.beanClass, this.key, this.additionalProperties);

    assertTrue(this.propertyValues.contains(this.key));
    assertContainsKey("alpha");
}

From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenterTest.java

@Test(expected = IllegalArgumentException.class)
public void existingPropertiesFactoryBeanLocationIllegal() {
    BeanReference br = new RuntimeBeanNameReference(this.beanName);
    this.propertyValues.addPropertyValue(this.key, br);
    when(this.beanDefinition.getBeanClassName()).thenReturn(PropertiesFactoryBean.class.getCanonicalName());
    this.propertyValues.addPropertyValue("location", new Object());

    this.propertyAugmenter.augment(this.beanFactory, this.beanClass, this.key, this.additionalProperties);
}

From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenterTest.java

@Test
public void existingPropertiesFactoryBeanLocationsList() {
    BeanReference br = new RuntimeBeanNameReference(this.beanName);
    this.propertyValues.addPropertyValue(this.key, br);
    when(this.beanDefinition.getBeanClassName()).thenReturn(PropertiesFactoryBean.class.getCanonicalName());
    this.propertyValues.addPropertyValue("locations", Arrays.asList("alpha.properties", "bravo.properties"));

    this.propertyAugmenter.augment(this.beanFactory, this.beanClass, this.key, this.additionalProperties);

    assertTrue(this.propertyValues.contains(this.key));
    assertContainsKey("alpha");
    assertContainsKey("bravo");
}

From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenterTest.java

@Test(expected = IllegalArgumentException.class)
public void existingPropertiesFactoryBeanLocationsIllegal() {
    BeanReference br = new RuntimeBeanNameReference(this.beanName);
    this.propertyValues.addPropertyValue(this.key, br);
    when(this.beanDefinition.getBeanClassName()).thenReturn(PropertiesFactoryBean.class.getCanonicalName());
    this.propertyValues.addPropertyValue("locations", Sets.asSet("alpha.properties", "bravo.properties"));

    this.propertyAugmenter.augment(this.beanFactory, this.beanClass, this.key, this.additionalProperties);
}

From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenterTest.java

@Test(expected = IllegalArgumentException.class)
public void existingPropertiesFactoryBeanNoLocationOrProperties() {
    BeanReference br = new RuntimeBeanNameReference(this.beanName);
    this.propertyValues.addPropertyValue(this.key, br);
    when(this.beanDefinition.getBeanClassName()).thenReturn(PropertiesFactoryBean.class.getCanonicalName());

    this.propertyAugmenter.augment(this.beanFactory, this.beanClass, this.key, this.additionalProperties);
}

From source file:eap.config.ConfigBeanDefinitionParser.java

/**
 * Create a {@link RootBeanDefinition} for the advisor described in the supplied. Does <strong>not</strong>
 * parse any associated '{@code pointcut}' or '{@code pointcut-ref}' attributes.
 *//*from ww w.j a  va 2 s.  c o m*/
private AbstractBeanDefinition createAdvisorBeanDefinition(Element advisorElement,
        ParserContext parserContext) {
    RootBeanDefinition advisorDefinition = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class);
    advisorDefinition.setSource(parserContext.extractSource(advisorElement));

    String adviceRef = advisorElement.getAttribute(ADVICE_REF);
    if (!StringUtils.hasText(adviceRef)) {
        parserContext.getReaderContext().error("'advice-ref' attribute contains empty value.", advisorElement,
                this.parseState.snapshot());
    } else {
        advisorDefinition.getPropertyValues().add(ADVICE_BEAN_NAME, new RuntimeBeanNameReference(adviceRef));
    }

    if (advisorElement.hasAttribute(ORDER_PROPERTY)) {
        advisorDefinition.getPropertyValues().add(ORDER_PROPERTY, advisorElement.getAttribute(ORDER_PROPERTY));
    }

    return advisorDefinition;
}

From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenterTest.java

@Test
public void existingPropertiesFactoryBeanPropertiesBeanDefinitionHolder() {
    BeanReference br = new RuntimeBeanNameReference(this.beanName);
    this.propertyValues.addPropertyValue(this.key, br);
    when(this.beanDefinition.getBeanClassName()).thenReturn(PropertiesFactoryBean.class.getCanonicalName(),
            Map.class.getCanonicalName());
    BeanDefinitionHolder bdh = new BeanDefinitionHolder(this.beanDefinition, "");
    this.propertyValues.addPropertyValue("properties", bdh);
    Map<String, String> m = new HashMap<String, String>();
    m.put("additional-key", "additional-value");
    this.propertyValues.addPropertyValue("sourceMap", m);

    this.propertyAugmenter.augment(this.beanFactory, this.beanClass, this.key, this.additionalProperties);

    assertTrue(this.propertyValues.contains(this.key));
    assertContainsKey("additional-key");
}