Example usage for org.springframework.beans.factory.config BeanDefinition getPropertyValues

List of usage examples for org.springframework.beans.factory.config BeanDefinition getPropertyValues

Introduction

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

Prototype

MutablePropertyValues getPropertyValues();

Source Link

Document

Return the property values to be applied to a new instance of the bean.

Usage

From source file:org.jolokia.jvmagent.spring.config.SpringConfigTest.java

@Test
public void simpleServer() throws ParserConfigurationException, IOException, SAXException {

    reader.loadBeanDefinitions(new ClassPathResource("/simple-server.xml"));

    BeanDefinition bd = beanFactory.getBeanDefinition("jolokiaServer");
    assertEquals(bd.getBeanClassName(), SpringJolokiaAgent.class.getName());
    MutablePropertyValues props = bd.getPropertyValues();
    assertEquals(props.size(), 2);/*  w  w  w  .  j  a v  a2s . c  om*/
    assertEquals(props.getPropertyValue("lookupConfig").getValue(), false);
    BeanDefinition cBd = (BeanDefinition) props.getPropertyValue("config").getValue();
    ;
    assertEquals(cBd.getBeanClassName(), SpringJolokiaConfigHolder.class.getName());
    MutablePropertyValues cProps = cBd.getPropertyValues();
    assertEquals(cProps.size(), 1);
    verifyConfig(cProps);
}

From source file:org.springmodules.cache.config.CacheProxyFactoryBeanParserTests.java

public void testParseCacheSetupStrategy() {
    Element proxyElement = proxyElementBuilder.toXml();

    RootBeanDefinition beanDefinition = new RootBeanDefinition(String.class);
    BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, "beanName");
    beanReferenceParser.parse(proxyElement, parserContext);
    beanReferenceParserControl.setReturnValue(holder);
    beanReferenceParserControl.replay();

    // method to test.
    parser.parseCacheSetupStrategy(proxyElement, parserContext, propertySource);

    BeanDefinition proxyDefinition = registry.getBeanDefinition(proxyElementBuilder.id);

    // verify property "target" is correct.
    PropertyValue target = proxyDefinition.getPropertyValues().getPropertyValue("target");
    assertEquals(holder, target.getValue());
    assertCacheProxyFactoryBeanDefinitionIsCorrect(proxyDefinition);

    beanReferenceParserControl.verify();
}

From source file:com.clican.pluto.dataprocess.spring.parser.JdbcExecProcessorParser.java

@SuppressWarnings("unchecked")

public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) {
    String jdbcTemplate = element.getAttribute("jdbcTemplate");
    beanDef.getPropertyValues().addPropertyValue("jdbcTemplate", new RuntimeBeanReference(jdbcTemplate));
    List jdbcExecBeanList = new ManagedList();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String localName = node.getLocalName();
            if ("exec".equals(localName)) {
                RootBeanDefinition bean = new RootBeanDefinition();
                bean.setAbstract(false);
                bean.setBeanClass(JdbcExecBean.class);
                bean.setLazyInit(false);
                bean.setAutowireMode(Autowire.BY_NAME.value());

                Element jdbcExecElement = (Element) node;
                String batch = jdbcExecElement.getAttribute("batch");
                String paramName = jdbcExecElement.getAttribute("paramName");
                String resultName = jdbcExecElement.getAttribute("resultName");
                String paramNameMap = jdbcExecElement.getAttribute("paramNameMap");
                String singleRow = jdbcExecElement.getAttribute("singleRow");
                String clazz = jdbcExecElement.getAttribute("clazz");
                String sql = jdbcExecElement.getTextContent();
                if (StringUtils.isNotEmpty(paramNameMap)) {
                    Map<String, String> map = new HashMap<String, String>();
                    for (String pnm : paramNameMap.split(";")) {
                        String contextName = pnm.split("=>")[0].trim();
                        String ibatisName = pnm.split("=>")[1].trim();
                        map.put(contextName, ibatisName);
                    }//from w  w  w  .j a v  a  2s.c o  m
                    bean.getPropertyValues().addPropertyValue("paramNameMap", map);
                }
                if (StringUtils.isNotEmpty(batch)) {
                    bean.getPropertyValues().addPropertyValue("batch", Boolean.parseBoolean(batch));
                }
                if (StringUtils.isNotEmpty(singleRow)) {
                    bean.getPropertyValues().addPropertyValue("singleRow", Boolean.parseBoolean(singleRow));
                }
                if (StringUtils.isNotEmpty(clazz)) {
                    try {
                        bean.getPropertyValues().addPropertyValue("clazz", Class.forName(clazz));
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
                bean.getPropertyValues().addPropertyValue("paramName", paramName);
                bean.getPropertyValues().addPropertyValue("resultName", resultName);
                bean.getPropertyValues().addPropertyValue("sql", sql);
                jdbcExecBeanList.add(bean);
            }
        }
    }
    beanDef.getPropertyValues().addPropertyValue("jdbcExecBeanList", jdbcExecBeanList);
}

From source file:org.jolokia.support.spring.config.SpringConfigTest.java

@Test
public void logHandlerRef() throws IOException, SAXException, ParserConfigurationException {
    Element element = getElement("/simple-log-ref.xml");
    LogBeanDefinitionParser parser = new LogBeanDefinitionParser();
    BeanDefinition bd = parser.parseInternal(element, null);
    assertEquals(bd.getBeanClassName(), SpringJolokiaLogHandlerHolder.class.getName());
    MutablePropertyValues props = bd.getPropertyValues();
    assertEquals(props.size(), 1);/*www.  j  a  v  a  2s  .co m*/
    assertTrue(props.getPropertyValue("logHandler").getValue() instanceof BeanReference);
    assertEquals(((BeanReference) props.getPropertyValue("logHandler").getValue()).getBeanName(), "logHandler");
}

From source file:org.jolokia.support.spring.config.SpringConfigTest.java

@Test
public void logHandlerType() throws IOException, SAXException, ParserConfigurationException {
    Element element = getElement("/simple-log-type.xml");
    LogBeanDefinitionParser parser = new LogBeanDefinitionParser();
    BeanDefinition bd = parser.parseInternal(element, null);
    assertEquals(bd.getBeanClassName(), SpringJolokiaLogHandlerHolder.class.getName());
    MutablePropertyValues props = bd.getPropertyValues();
    assertEquals(props.size(), 2);//  w w w  .  ja  v  a 2 s . c  o  m
    assertEquals(props.getPropertyValue("type").getValue(), "commons");
    assertEquals(props.getPropertyValue("category").getValue(), "bla");
}

From source file:jeeves.server.overrides.AddPropertyUpdater.java

@SuppressWarnings("unchecked")
@Override/*from   w  w w .j  a v a 2  s.  c o  m*/
protected void doUpdate(ConfigurableListableBeanFactory beanFactory, BeanDefinition bean, Object value) {
    Log.debug(Log.JEEVES, "Adding new value " + value + " to property: " + propertyName + " on " + beanName);
    PropertyValue propertyValue = bean.getPropertyValues().getPropertyValue(propertyName);
    if (propertyValue == null) {
        final String beanClassName = bean.getBeanClassName();
        try {
            final Class<?> aClass = Class.forName(beanClassName);
            final PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(aClass);
            for (PropertyDescriptor descriptor : propertyDescriptors) {
                if (propertyName.equals(descriptor.getName())) {
                    final Class<?> collectionType = descriptor.getWriteMethod().getParameterTypes()[0];
                    if (List.class.isAssignableFrom(collectionType)) {
                        propertyValue = new PropertyValue(propertyName, new ManagedList<Object>());
                    } else if (Set.class.isAssignableFrom(collectionType)) {
                        propertyValue = new PropertyValue(propertyName, new ManagedSet<Object>());
                    } else if (Map.class.isAssignableFrom(collectionType)) {
                        propertyValue = new PropertyValue(propertyName, new ManagedMap<Object, Object>());
                    } else if (Properties.class.isAssignableFrom(collectionType)) {
                        propertyValue = new PropertyValue(propertyName, new ManagedProperties());
                    } else if (Array.class.isAssignableFrom(collectionType)) {
                        throw new IllegalArgumentException("Array collections not currently supported");
                    } else if (Collection.class.isAssignableFrom(collectionType)) {
                        propertyValue = new PropertyValue(propertyName, new ManagedList<Object>());
                    } else {
                        throw new IllegalArgumentException(
                                collectionType + " is not a supported type for adding new values");
                    }
                    break;
                }
            }
            if (propertyValue == null) {
                throw new IllegalArgumentException("Unable to find the collection type for property: "
                        + propertyName + " on bean " + beanName);
            }
            bean.getPropertyValues().addPropertyValue(propertyValue);
        } catch (ClassNotFoundException e) {
            throw new AssertionError(e);
        }
    }

    Object originalValue = propertyValue.getValue();
    if (originalValue instanceof Collection) {
        Collection<Object> coll = (Collection<Object>) originalValue;
        coll.add(value);
    } else {
        throw new IllegalArgumentException(originalValue + " is not a collection as expected");
    }
}

From source file:org.jolokia.support.spring.config.SpringConfigTest.java

@Test
public void simpleServer() throws ParserConfigurationException, IOException, SAXException {

    reader.loadBeanDefinitions(new ClassPathResource("/simple-server.xml"));

    BeanDefinition bd = beanFactory.getBeanDefinition("jolokiaServer");
    assertEquals(bd.getBeanClassName(), SpringJolokiaAgent.class.getName());
    MutablePropertyValues props = bd.getPropertyValues();
    assertEquals(props.size(), 3);/*from   w w  w  .java 2 s  .c o m*/
    assertEquals(props.getPropertyValue("lookupConfig").getValue(), false);
    assertEquals(props.getPropertyValue("lookupServices").getValue(), false);
    BeanDefinition cBd = (BeanDefinition) props.getPropertyValue("config").getValue();
    ;
    assertEquals(cBd.getBeanClassName(), SpringJolokiaConfigHolder.class.getName());
    MutablePropertyValues cProps = cBd.getPropertyValues();
    assertEquals(cProps.size(), 1);
    verifyConfig(cProps);
}

From source file:alpha.portal.webapp.spring.ValidatorExtensionPostProcessor.java

/**
 * Adds the validation configuration files to the list already held in the
 * validator factory bean configuration.
 * /* w  ww.j a v a  2s.  c om*/
 * @param configurableListableBeanFactory
 *            the bean factory
 */
public void postProcessBeanFactory(final ConfigurableListableBeanFactory configurableListableBeanFactory) {
    if (configurableListableBeanFactory.containsBean(this.validatorFactoryBeanName)) {
        final BeanDefinition validatorFactoryBeanDefinition = configurableListableBeanFactory
                .getBeanDefinition(this.validatorFactoryBeanName);
        final MutablePropertyValues propertyValues = validatorFactoryBeanDefinition.getPropertyValues();
        final PropertyValue propertyValue = propertyValues.getPropertyValue("validationConfigLocations");

        // value is expected to be a list.
        final List existingValidationConfigLocations = (List) propertyValue.getValue();
        existingValidationConfigLocations.addAll(this.validationConfigLocations);
    }
}

From source file:org.drools.container.spring.namespace.KnowledgeAgentDefinitionParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {

    BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(KnowledgeAgentBeanFactory.class);

    String id = element.getAttribute("id");
    emptyAttributeCheck(element.getLocalName(), "id", id);
    factory.addPropertyValue("id", id);

    String kbase = element.getAttribute("kbase");
    if (StringUtils.hasText(kbase)) {
        factory.addPropertyReference("kbase", kbase);
    }//from  ww  w  .j  a  va 2  s . c om

    String newInstance = element.getAttribute("new-instance");
    if (StringUtils.hasText(newInstance)) {
        factory.addPropertyValue("newInstance", newInstance);
    }

    String useKbaseClassloader = element.getAttribute("use-kbase-classloader");
    if (!useKbaseClassloader.trim().equals("")) {
        factory.addPropertyValue("useKbaseClassloader", useKbaseClassloader);
    }

    ManagedList resources = KnowledgeBaseDefinitionParser.getResources(element, parserContext, factory);

    if (resources != null) {
        factory.addPropertyValue("resources", resources);
    }

    // inject the kagent into any stateless sessions
    for (String beanName : parserContext.getRegistry().getBeanDefinitionNames()) {
        BeanDefinition def = parserContext.getRegistry().getBeanDefinition(beanName);
        if (StatelessKnowledgeSessionBeanFactory.class.getName().equals(def.getBeanClassName())) {
            PropertyValue pvalue = def.getPropertyValues().getPropertyValue("kbase");
            RuntimeBeanReference tbf = (RuntimeBeanReference) pvalue.getValue();
            if (kbase.equals(tbf.getBeanName())) {
                def.getPropertyValues().addPropertyValue("knowledgeAgent", new RuntimeBeanReference(id));
            }
        }
    }

    return factory.getBeanDefinition();
}

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

@Test
public void testFeatureServiceFactoryPropertiesWithEnvironment() {
    setupContext("test-feature-service-context-with-env.xml");
    BeanDefinition beanDefinition = context.getBeanDefinition("featureServiceFactory");

    // Test ContextProviders setup
    PropertyValue environmentProperty = beanDefinition.getPropertyValues().getPropertyValue("environment");
    assertNotNull(environmentProperty);//from w w w. ja  v  a  2  s.  com

    assertTrue(environmentProperty.getValue() instanceof BeanReference);
    assertEquals("environmentBean", ((BeanReference) environmentProperty.getValue()).getBeanName());
}