Example usage for org.springframework.beans MutablePropertyValues getPropertyValue

List of usage examples for org.springframework.beans MutablePropertyValues getPropertyValue

Introduction

In this page you can find the example usage for org.springframework.beans MutablePropertyValues getPropertyValue.

Prototype

@Override
    @Nullable
    public PropertyValue getPropertyValue(String propertyName) 

Source Link

Usage

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

/**
 * Asserts the given set of property values contains the expected property
 * value.//from   ww  w .  j a va  2 s.  c  o  m
 * 
 * @param propertyValues
 *          the given set of property values
 * @param expectedPropertyValue
 *          the expected property value
 */
public static void assertPropertyIsPresent(MutablePropertyValues propertyValues,
        PropertyValue expectedPropertyValue) {

    String propertyName = expectedPropertyValue.getName();
    PropertyValue actualPropertyValue = propertyValues.getPropertyValue(propertyName);

    Assert.assertNotNull("Property " + StringUtils.quote(propertyName) + " not found", actualPropertyValue);

    Object expectedValue = expectedPropertyValue.getValue();
    Object actualValue = actualPropertyValue.getValue();
    String message = "<Property " + StringUtils.quote(propertyName) + ">";

    assertEquals(message, expectedValue, actualValue);
}

From source file:com.mtgi.analytics.aop.config.v11.BtManagerBeanDefinitionParser.java

/** 
 * called by nested tags to push inner beans into the enclosing {@link BehaviorTrackingManagerImpl}.
 * @return <span>true if the inner bean was added to an enclosing {@link BehaviorTrackingManagerImpl}.  Otherwise, the bean definition
 * is not nested inside a &lt;bt:manager&gt; tag and therefore will have to be registered as a global bean in the application
 * context.</span>/*from  ww w  .j  a va2 s  .c o m*/
 */
protected static boolean registerNestedBean(BeanDefinitionHolder nested, String parentProperty,
        ParserContext parserContext) {
    //add parsed inner bean element to containing manager definition; e.g. persister or SessionContext impls.
    CompositeComponentDefinition parent = parserContext.getContainingComponent();
    if (parent instanceof ManagerComponentDefinition) {
        //we are nested; add to enclosing bean def.
        ManagerComponentDefinition mcd = (ManagerComponentDefinition) parent;
        BeanDefinition managerDef = parserContext.getContainingBeanDefinition();

        MutablePropertyValues props = managerDef.getPropertyValues();
        PropertyValue current = props.getPropertyValue(parentProperty);
        boolean innerBean = true;

        if (current != null) {
            //if the original value is a reference, replace it with an alias to the nested bean definition.
            //this means the nested bean takes the place of the default definition
            //in other places where it might be referenced, as well as during mbean export
            Object value = current.getValue();
            DefaultListableBeanFactory factory = mcd.getTemplateFactory();
            if (value instanceof RuntimeBeanReference) {
                String ref = ((RuntimeBeanReference) value).getBeanName();

                if (factory.getBeanDefinition(ref) == nested.getBeanDefinition()) {
                    //the nested definition is the same as the default definition
                    //by reference, so we don't need to make it an inner bean definition.
                    innerBean = false;
                }
            }
        }
        if (innerBean)
            props.addPropertyValue(parentProperty, nested);
        mcd.addNestedProperty(parentProperty);
        return true;
    }
    //bean is not nested inside bt:manager
    return false;
}

From source file:org.bytesoft.bytetcc.supports.dubbo.validator.ProtocolConfigValidator.java

public void validate() throws BeansException {
    MutablePropertyValues mpv = this.beanDefinition.getPropertyValues();
    PropertyValue pv = mpv.getPropertyValue("port");
    Object value = pv == null ? null : pv.getValue();
    if (pv == null || value == null) {
        throw new FatalBeanException(
                "The value of the attribute 'port' (<dubbo:protocol port='...' />) must be explicitly specified.");
    } else if ("-1".equals(value)) {
        throw new FatalBeanException(
                "The value of the attribute 'port' (<dubbo:protocol port='...' />) must be explicitly specified and not equal to -1.");
    }/*from w w  w.j  av  a  2  s  .c o  m*/
}

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

private void verifyConfig(MutablePropertyValues pCProps) {
    Map vals = (Map) pCProps.getPropertyValue("config").getValue();
    assertEquals(vals.size(), 3);//  ww w  . j ava  2  s  .  c om
    for (String k : new String[] { "host", "port", "autoStart" }) {
        assertTrue(vals.containsKey(new TypedStringValue(k, String.class)));
    }
}

From source file:org.bytesoft.bytetcc.supports.spring.TransactionConfigPostProcessor.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    String[] beanNameArray = beanFactory.getBeanDefinitionNames();
    for (int i = 0; i < beanNameArray.length; i++) {
        String beanName = beanNameArray[i];
        BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
        String beanClassName = beanDef.getBeanClassName();

        if (org.springframework.transaction.interceptor.TransactionProxyFactoryBean.class.getName()
                .equals(beanClassName)) {
            throw new FatalBeanException(String.format(
                    "Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).",
                    beanName));//from ww w.  j av  a  2s. c om
        }

        if (org.springframework.transaction.interceptor.TransactionInterceptor.class.getName()
                .equals(beanClassName)) {
            boolean errorExists = true;

            MutablePropertyValues mpv = beanDef.getPropertyValues();
            PropertyValue pv = mpv.getPropertyValue("transactionAttributeSource");
            Object value = pv == null ? null : pv.getValue();
            if (value != null && RuntimeBeanReference.class.isInstance(value)) {
                RuntimeBeanReference reference = (RuntimeBeanReference) value;
                BeanDefinition refBeanDef = beanFactory.getBeanDefinition(reference.getBeanName());
                String refBeanClassName = refBeanDef.getBeanClassName();
                errorExists = AnnotationTransactionAttributeSource.class.getName()
                        .equals(refBeanClassName) == false;
            }

            if (errorExists) {
                throw new FatalBeanException(String.format(
                        "Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).",
                        beanName));
            }

        }
    }
}

From source file:org.bytesoft.bytetcc.supports.dubbo.validator.ServiceConfigValidator.java

public void validate() throws BeansException {
    MutablePropertyValues mpv = this.beanDefinition.getPropertyValues();
    PropertyValue retries = mpv.getPropertyValue("retries");
    PropertyValue loadbalance = mpv.getPropertyValue("loadbalance");
    PropertyValue cluster = mpv.getPropertyValue("cluster");
    PropertyValue filter = mpv.getPropertyValue("filter");
    PropertyValue group = mpv.getPropertyValue("group");

    if (retries == null || retries.getValue() == null || "0".equals(retries.getValue()) == false) {
        throw new FatalBeanException(
                String.format("The value of attr 'retries'(beanId= %s) should be '0'.", this.beanName));
    } else if (loadbalance == null || loadbalance.getValue() == null
            || "compensable".equals(loadbalance.getValue()) == false) {
        throw new FatalBeanException(String
                .format("The value of attr 'loadbalance'(beanId= %s) should be 'compensable'.", this.beanName));
    } else if (cluster == null || cluster.getValue() == null
            || "failfast".equals(cluster.getValue()) == false) {
        throw new FatalBeanException(String
                .format("The value of attribute 'cluster' (beanId= %s) must be 'failfast'.", this.beanName));
    } else if (filter == null || filter.getValue() == null
            || "compensable".equals(filter.getValue()) == false) {
        throw new FatalBeanException(String
                .format("The value of attr 'filter'(beanId= %s) should be 'compensable'.", this.beanName));
    } else if (group == null || group.getValue() == null
            || "org.bytesoft.bytetcc".equals(group.getValue()) == false) {
        throw new FatalBeanException(String.format(
                "The value of attr 'group'(beanId= %s) should be 'org.bytesoft.bytetcc'.", this.beanName));
    }/*  www  . j  a  v  a 2  s  .com*/
}

From source file:com.easyshop.datasource.MyBatisBeanFactoryPostProcessor.java

/**
 * @param beanFactory/*from  ww w  .j a  v a 2 s  .  co  m*/
 * @throws BeansException
 * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
 */
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    BeanDefinition bd = beanFactory.getBeanDefinition(sqlSessionFactoryBeanName);
    MutablePropertyValues propertyValues = bd.getPropertyValues();
    PropertyValue propertyValue = propertyValues.getPropertyValue("mapperLocations");
    Object value = propertyValue.getValue();

    ManagedList<TypedStringValue> locations = new ManagedList<TypedStringValue>();
    for (String location : mapperLocations) {
        locations.add(new TypedStringValue(location));
        log.info(" SQL Mapper  :{} " + location);
    }

    if (value == null) {
        PropertyValue newValue = new PropertyValue(propertyValue, locations);
        propertyValues.addPropertyValue(newValue);
    } else if (value instanceof String) {
        locations.add(new TypedStringValue((String) value));
        PropertyValue newValue = new PropertyValue(propertyValue, locations);
        propertyValues.addPropertyValue(newValue);
    } else if (value instanceof ManagedList) {
        ((ManagedList) value).addAll(locations);
    } else if (value instanceof TypedStringValue) {
        locations.add((TypedStringValue) value);
        PropertyValue newValue = new PropertyValue(propertyValue, locations);
        propertyValues.addPropertyValue(newValue);
    }
}

From source file:org.bytesoft.bytejta.supports.spring.TransactionEndpointPostProcessor.java

public void initializeCoordinator(ConfigurableListableBeanFactory beanFactory, BeanDefinition protocolDef,
        String compensableBeanId) throws BeansException {
    MutablePropertyValues mpv = protocolDef.getPropertyValues();
    PropertyValue pv = mpv.getPropertyValue("port");
    if (pv == null || pv.getValue() == null) {
        throw new FatalBeanException("Attribute 'port' of <dubbo:protocol ... /> is null.");
    }//from www  .j  a  v a2 s .co  m

    String host = CommonUtils.getInetAddress();
    String port = String.valueOf(pv.getValue());
    String identifier = String.format("%s:%s", host, port);

    BeanDefinition beanDef = beanFactory.getBeanDefinition(compensableBeanId);
    beanDef.getPropertyValues().addPropertyValue("identifier", identifier);
}

From source file:org.brekka.stillingar.spring.pc.PropertyDefChangeListener.java

/**
 * Update the property with the new value
 *//*from w w  w .  ja  va  2 s .co m*/
@Override
public void onChange(String newValue) {
    ConfigurableListableBeanFactory beanFactory = beanFactoryRef.get();
    if (beanFactory == null) {
        return;
    }
    BeanDefinition beanDef = beanFactory.getMergedBeanDefinition(beanName);
    MutablePropertyValues mutablePropertyValues = beanDef.getPropertyValues();
    PropertyValue propertyValue = mutablePropertyValues.getPropertyValue(propertyName);
    if (!ObjectUtils.nullSafeEquals(newValue, propertyValue.getValue())) {
        mutablePropertyValues.add(propertyValue.getName(), newValue);
    }
}

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);//from   w w w  . j  a va2 s .  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);
}