Example usage for org.springframework.beans MutablePropertyValues MutablePropertyValues

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

Introduction

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

Prototype

public MutablePropertyValues() 

Source Link

Document

Creates a new empty MutablePropertyValues object.

Usage

From source file:de.interseroh.report.controller.ParameterFormBinder.java

private MutablePropertyValues createPropertyValues(ParameterForm parameterForm,
        final MultiValueMap<String, String> requestParameters) {
    final MutablePropertyValues mpvs = new MutablePropertyValues();

    parameterForm.accept(new AbstractParameterVisitor() {
        @Override//from  w w  w.  jav a2  s  . c  om
        public <V, T> void visit(ScalarParameter<V, T> parameter) {
            String name = parameter.getName();
            String propertyPath = ParameterUtils.nameToTextPath(name);
            Class<T> textType = parameter.getTextType();

            if (requestParameters.containsKey(name)) {
                addText(name, propertyPath, textType);
            } else if (requestParameters.containsKey('_' + name)) {
                addText('_' + name, propertyPath, textType);
            }
        }

        private <T> void addText(String name, String propertyPath, Class<T> textType) {
            List<String> values = requestParameters.get(name);
            if (textType.isArray()) {
                mpvs.add(propertyPath, values.toArray());
            } else {
                for (String requestValue : values) {
                    mpvs.add(propertyPath, requestValue);
                }
            }
        }
    });
    return mpvs;
}

From source file:grails.plugin.cache.CacheBeanPostProcessor.java

public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
    log.info("postProcessBeanDefinitionRegistry start");

    AbstractBeanDefinition beanDef = findBeanDefinition(registry);
    if (beanDef == null) {
        log.error("Unable to find the AnnotationCacheOperationSource bean definition");
        return;/*from  w  w  w  .  j av a 2 s  .com*/
    }

    // change the class to the plugin's subclass
    beanDef.setBeanClass(GrailsAnnotationCacheOperationSource.class);

    // wire in the dependency for the grailsApplication
    MutablePropertyValues props = beanDef.getPropertyValues();
    if (props == null) {
        props = new MutablePropertyValues();
        beanDef.setPropertyValues(props);
    }
    props.addPropertyValue("grailsApplication", new RuntimeBeanReference("grailsApplication", true));

    log.debug("updated {}", beanDef);
}

From source file:org.hdiv.web.servlet.SimpleWebApplicationContext.java

public void refresh() throws BeansException {
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("commandClass", "org.hdiv.beans.TestBean");
    pvs.add("formView", "form");
    registerSingleton("/form.do", SimpleFormController.class, pvs);

    registerSingleton("/locale.do", LocaleChecker.class);

    addMessage("test", Locale.ENGLISH, "test message");
    addMessage("test", Locale.CANADA, "Canadian & test message");
    addMessage("testArgs", Locale.ENGLISH, "test {0} message {1}");
    addMessage("testArgsFormat", Locale.ENGLISH, "test {0} message {1,number,#.##} X");

    registerSingleton(UiApplicationContextUtils.THEME_SOURCE_BEAN_NAME, DummyThemeSource.class);

    registerSingleton("handlerMapping", BeanNameUrlHandlerMapping.class);
    registerSingleton("viewResolver", InternalResourceViewResolver.class);

    pvs = new MutablePropertyValues();
    pvs.add("location", "org/hdiv/web/context/WEB-INF/sessionContext.xml");
    registerSingleton("viewResolver2", XmlViewResolver.class, pvs);

    super.refresh();
}

From source file:com.github.dbourdette.glass.job.GlassJobFactory.java

private void setProperties(TriggerFiredBundle bundle, Job job) {
    MutablePropertyValues pvs = new MutablePropertyValues();

    pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
    pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());

    buildAccessor(job).setPropertyValues(pvs, true);
}

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

public void testConfigureFlushingInterceptor() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    parser.configureFlushingInterceptor(propertyValues, registry);
    assertAttributesPropertyIsPresent(propertyValues);
}

From source file:org.jasig.springframework.web.portlet.SimplePortletApplicationContext.java

public void refresh() throws BeansException {
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("commandClass", "org.jasig.springframework.beans.TestBean");
    pvs.add("formView", "form");
    registerSingleton("/form.do", SimpleFormController.class, pvs);

    registerSingleton("/locale.do", LocaleChecker.class);

    addMessage("test", Locale.ENGLISH, "test message");
    addMessage("test", Locale.CANADA, "Canadian & test message");
    addMessage("testArgs", Locale.ENGLISH, "test {0} message {1}");
    addMessage("testArgsFormat", Locale.ENGLISH, "test {0} message {1,number,#.##} X");

    registerSingleton(UiApplicationContextUtils.THEME_SOURCE_BEAN_NAME, DummyThemeSource.class);

    registerSingleton("handlerMapping", BeanNameUrlHandlerMapping.class);
    registerSingleton("viewResolver", InternalResourceViewResolver.class);

    pvs = new MutablePropertyValues();
    pvs.add("location", "org/springframework/web/context/WEB-INF/sessionContext.xml");
    registerSingleton("viewResolver2", XmlViewResolver.class, pvs);

    super.refresh();
}

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

public void testConfigureFlushingInterceptor() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    parser.configureFlushingInterceptor(propertyValues, registry);

    Class targetClass = AnnotationFlushingAttributeSource.class;
    String beanName = targetClass.getName();
    AbstractBeanDefinition definition = (AbstractBeanDefinition) registry.getBeanDefinition(beanName);

    ConfigAssert.assertBeanDefinitionWrapsClass(definition, targetClass);

    PropertyValue expected = new PropertyValue("flushingAttributeSource", new RuntimeBeanReference(beanName));

    ConfigAssert.assertPropertyIsPresent(propertyValues, expected);
}

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

/**
 * Parses the given XML element containing the properties of the cache manager
 * to register in the given registry of bean definitions.
 * //from   w ww  . java  2 s  . c o m
 * @param element
 *          the XML element to parse
 * @param registry
 *          the registry of bean definitions
 * 
 * @see AbstractCacheProviderFacadeParser#doParse(String, Element,
 *      BeanDefinitionRegistry)
 */
protected final void doParse(String cacheProviderFacadeId, Element element, BeanDefinitionRegistry registry) {
    String id = "cacheManager";
    Class clazz = getCacheManagerClass();
    RootBeanDefinition cacheManager = new RootBeanDefinition(clazz);
    MutablePropertyValues cacheManagerProperties = new MutablePropertyValues();
    cacheManager.setPropertyValues(cacheManagerProperties);

    PropertyValue configLocation = parseConfigLocationProperty(element);
    cacheManagerProperties.addPropertyValue(configLocation);
    registry.registerBeanDefinition(id, cacheManager);

    BeanDefinition cacheProviderFacade = registry.getBeanDefinition(cacheProviderFacadeId);
    cacheProviderFacade.getPropertyValues().addPropertyValue("cacheManager", new RuntimeBeanReference(id));
}

From source file:net.tirasa.blog.springquartz.SpringBeanJobFactory.java

/**
 * An implementation of SpringBeanJobFactory that retrieves the bean from
 * the Spring context so that autowiring and transactions work
 *
 * This method is overriden./*from www. j  a va 2 s.com*/
 * @see org.springframework.scheduling.quartz.SpringBeanJobFactory#createJobInstance(org.quartz.spi.TriggerFiredBundle)
 */
@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {

    final ConfigurableApplicationContext ctx = ((ConfigurableApplicationContext) schedulerContext
            .get("applicationContext"));
    final Object job = ctx.getBean(bundle.getJobDetail().getName());
    final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(job);
    if (isEligibleForPropertyPopulation(wrapper.getWrappedInstance())) {
        final MutablePropertyValues pvs = new MutablePropertyValues();
        if (this.schedulerContext != null) {
            pvs.addPropertyValues(this.schedulerContext);
        }
        pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
        pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
        if (this.ignoredUnknownProperties == null) {
            wrapper.setPropertyValues(pvs, true);
        } else {
            for (String propName : this.ignoredUnknownProperties) {
                if (pvs.contains(propName) && !wrapper.isWritableProperty(propName)) {

                    pvs.removePropertyValue(propName);
                }
            }
            wrapper.setPropertyValues(pvs);
        }
    }
    return job;
}

From source file:com.opensymphony.able.action.JpaCrudActionBeanTest.java

@Test
public void testIntrospection() throws Exception {
    Person bug = new Person();

    DataBinder binder = new DataBinder(bug);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.addPropertyValue("id", "123456");
    binder.bind(propertyValues);//  w  ww .  j a v a 2 s.co  m

    Assert.assertEquals(new Integer(123456), bug.getId());

    TypeConverter typeConverter = new BeanWrapperImpl();
    Object value = typeConverter.convertIfNecessary("123456", Integer.class);
    Assert.assertEquals(new Integer(123456), value);
}