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:org.springmodules.cache.config.MetadataAttributesParserTests.java

private MutablePropertyValues flushingInterceptorPropertyValues() {
    MutablePropertyValues pv = new MutablePropertyValues();

    pv.addPropertyValue(propertySource.getCacheProviderFacadeProperty());
    pv.addPropertyValue(propertySource.getFlushingModelsProperty());

    return pv;//from   w  w w.  ja  va 2s  .c  o  m
}

From source file:co.paralleluniverse.common.spring.SpringContainerHelper.java

private static BeanDefinition getMBeanExporterBeanDefinition(String defaultDomain) {
    final AnnotationJmxAttributeSource annotationSource = new AnnotationJmxAttributeSource();

    final GenericBeanDefinition bean = new GenericBeanDefinition();
    bean.setBeanClass(MBeanExporter.class);
    MutablePropertyValues properties = new MutablePropertyValues();
    properties.add("server", ManagementFactory.getPlatformMBeanServer());
    properties.add("autodetectMode", MBeanExporter.AUTODETECT_ASSEMBLER);
    properties.add("assembler", new MetadataMBeanInfoAssembler(annotationSource));
    properties.add("namingStrategy", new MBeanNamingStrategy(annotationSource).setDefaultDomain(defaultDomain));
    bean.setPropertyValues(properties);//from  w  ww . ja v  a2 s  . c o  m
    return bean;
}

From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java

@Test
public void testEmptyPropertyValuesSet() {
    TestBean t = new TestBean();
    int age = 50;
    String name = "Tony";
    t.setAge(age);/*  w w  w. ja  v a2 s. c  o m*/
    t.setName(name);
    try {
        BeanWrapper bw = new JuffrouSpringBeanWrapper(t);
        assertTrue("age is OK", t.getAge() == age);
        assertTrue("name is OK", name.equals(t.getName()));
        bw.setPropertyValues(new MutablePropertyValues());
        // Check its unchanged
        assertTrue("age is OK", t.getAge() == age);
        assertTrue("name is OK", name.equals(t.getName()));
    } catch (BeansException ex) {
        fail("Shouldn't throw exception when everything is valid");
    }
}

From source file:org.atomserver.utils.test.TestingAtomServer.java

private Server createServer(int port, String atomserverServletContext) {
    // set up the server and the atomserver web application context
    Server server = new Server(port);
    Context context = new Context(server, "/" + atomserverServletContext, true /*sessions*/,
            false /*no security*/);

    // we need to hard-code certain system properties to get the behavior we want here - we
    // will re-set them when we're done
    Properties properties = (Properties) System.getProperties().clone();
    System.setProperty("atomserver.env", "asdev-hsql-mem");
    System.setProperty("atomserver.servlet.context", atomserverServletContext);

    // TODO: this should be removed
    System.setProperty("atomserver.servlet.mapping", "v1");

    // our Spring application context will start off by loading the basic built-in bean
    // definitions
    appContext = new GenericWebApplicationContext();

    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appContext);
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/propertyConfigurerBeans.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/databaseBeans.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/logBeans.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/storageBeans.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/abderaBeans.xml"));

    // if we were given a Spring config location, we use that -- otherwise we configure the
    // workspaces that were set up through the API
    if (springBeansLocation != null) {
        xmlReader.loadBeanDefinitions(new ClassPathResource(springBeansLocation));
    } else {//from  ww  w  .  ja v  a  2  s.c o  m
        RootBeanDefinition workspaces = new RootBeanDefinition(HashSet.class);
        ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
        constructorArgumentValues.addGenericArgumentValue(workspaceSet);
        workspaces.setConstructorArgumentValues(constructorArgumentValues);

        appContext.registerBeanDefinition("org.atomserver-workspaces", workspaces);
    }

    // override the base content storage to use DB-based storage
    RootBeanDefinition storage = new RootBeanDefinition(DBBasedContentStorage.class);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.addPropertyValue("contentDAO", new RuntimeBeanReference("org.atomserver-contentDAO"));
    propertyValues.addPropertyValue("entriesDAO", new RuntimeBeanReference("org.atomserver-entriesDAO"));
    storage.setPropertyValues(propertyValues);
    appContext.registerBeanDefinition("org.atomserver-contentStorage", storage);

    // clear the existing ENV
    ConfigurationAwareClassLoader.invalidateENV();

    // refresh the context to actually instantiate everything.
    appContext.refresh();

    // re-set the system properties
    System.setProperties(properties);

    // clear the update ENV
    ConfigurationAwareClassLoader.invalidateENV();

    // put our app context into the servlet context
    context.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext);

    // load and init the service context for v1
    final ServiceContext serviceContext = (ServiceContext) appContext.getBean(ServiceContext.class.getName());
    serviceContext.init(new Abdera(), Collections.EMPTY_MAP);

    // create a new AtomServerServlet - but override the createServiceContext method
    AtomServerServlet servlet = new AtomServerServlet() {
        protected ServiceContext createServiceContext() {
            return serviceContext;
        }
    };

    // load and init the service context for v2
    final ServiceContext serviceContextV2 = (ServiceContext) appContext
            .getBean("org.atomserver-serviceContext.v2");
    serviceContextV2.init(new Abdera(), Collections.EMPTY_MAP);

    // create a new AtomServerServlet - but override the createServiceContext method
    AtomServerServlet servletV2 = new AtomServerServlet() {
        protected ServiceContext createServiceContext() {
            return serviceContextV2;
        }
    };

    // register the servlets
    context.addServlet(new ServletHolder(servlet), "/v1/*");
    context.addServlet(new ServletHolder(servletV2), "/v2/*");

    EntriesDAOiBatisImpl entriesDAO = (EntriesDAOiBatisImpl) appContext.getBean("org.atomserver-entriesDAO");
    entriesDAO.setUseWorkspaceCollectionCache(false);

    // ready to be started
    return server;
}

From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java

@Test
public void testAllValid() {
    TestBean t = new TestBean();
    String newName = "tony";
    int newAge = 65;
    String newTouchy = "valid";
    try {/*from  w  w w.j  ava 2 s  . c  o m*/
        BeanWrapper bw = new JuffrouSpringBeanWrapper(t);
        MutablePropertyValues pvs = new MutablePropertyValues();
        pvs.addPropertyValue(new PropertyValue("age", new Integer(newAge)));
        pvs.addPropertyValue(new PropertyValue("name", newName));

        pvs.addPropertyValue(new PropertyValue("touchy", newTouchy));
        bw.setPropertyValues(pvs);
        assertTrue("Validly set property must stick", t.getName().equals(newName));
        assertTrue("Validly set property must stick", t.getTouchy().equals(newTouchy));
        assertTrue("Validly set property must stick", t.getAge() == newAge);
    } catch (BeansException ex) {
        fail("Shouldn't throw exception when everything is valid");
    }
}

From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java

@Test
public void testIgnoringIndexedProperty() {
    MutablePropertyValues values = new MutablePropertyValues();
    values.add("toBeIgnored[0]", new Integer(42));
    BeanWrapper bw = new JuffrouSpringBeanWrapper(new Object());
    bw.setPropertyValues(values, true);/*from   w w  w  .j  a v a  2  s  .co m*/
}

From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java

@Test
public void testConvertPrimitiveToString() {
    MutablePropertyValues values = new MutablePropertyValues();
    values.add("name", new Integer(42));
    TestBean tb = new TestBean();
    BeanWrapper bw = new JuffrouSpringBeanWrapper(tb);
    bw.setPropertyValues(values);// w  w  w  .j  a  v  a  2s  . c o  m
    assertEquals("42", tb.getName());
}

From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java

@Test
public void testConvertClassToString() {
    MutablePropertyValues values = new MutablePropertyValues();
    values.add("name", Integer.class);
    TestBean tb = new TestBean();
    BeanWrapper bw = new JuffrouSpringBeanWrapper(tb);
    bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
        @Override/*from w w  w .j  a  v  a2 s  .c  o m*/
        public void setValue(Object value) {
            super.setValue(value.toString());
        }
    });
    bw.setPropertyValues(values);
    assertEquals(Integer.class.toString(), tb.getName());
}

From source file:net.frontlinesms.FrontlineSMS.java

/**
 * Create the configLocations bean for the Hibernate config.
 * This method should only be called from within {@link FrontlineSMS#initApplicationContext()}
 * @return {@link BeanDefinition} containing details of the hibernate config for the app and its plugins.
 *//*from w w  w.  j a v a  2  s .  c om*/
private BeanDefinition createHibernateConfigLocationsBeanDefinition() {
    // Initialise list of hibernate config files
    List<String> hibernateConfigList = new ArrayList<String>();
    // Add main hibernate config location
    hibernateConfigList.add("classpath:frontlinesms.hibernate.cfg.xml");
    // Add hibernate config locations for plugins
    for (Class<PluginController> pluginClass : PluginProperties.getInstance().getPluginClasses()) {
        LOG.info("Processing plugin class: " + pluginClass.getName());
        if (pluginClass.isAnnotationPresent(PluginControllerProperties.class)) {
            PluginControllerProperties properties = pluginClass.getAnnotation(PluginControllerProperties.class);
            String pluginHibernateLocation = properties.hibernateConfigPath();
            if (!PluginControllerProperties.NO_VALUE.equals(pluginHibernateLocation)) {
                hibernateConfigList.add(pluginHibernateLocation);
            }
        }
    }

    GenericBeanDefinition myBeanDefinition = new GenericBeanDefinition();
    myBeanDefinition.setBeanClass(ListFactoryBean.class);
    MutablePropertyValues values = new MutablePropertyValues();
    values.addPropertyValue("sourceList", hibernateConfigList);
    myBeanDefinition.setPropertyValues(values);

    return myBeanDefinition;
}

From source file:org.codehaus.groovy.grails.web.binding.GrailsDataBinder.java

private PropertyValues filterPropertyValues(PropertyValues propertyValues, String prefix) {
    if (prefix == null || prefix.length() == 0)
        return propertyValues;

    PropertyValue[] valueArray = propertyValues.getPropertyValues();
    MutablePropertyValues newValues = new MutablePropertyValues();
    for (PropertyValue propertyValue : valueArray) {
        String name = propertyValue.getName();
        final String prefixWithDot = prefix + PREFIX_SEPERATOR;
        if (name.startsWith(prefixWithDot)) {
            name = name.substring(prefixWithDot.length(), name.length());
            newValues.addPropertyValue(name, propertyValue.getValue());
        }//from   w  w w. j  a  v  a  2s . com
    }
    return newValues;
}