Package org.springframework.beans

Examples of org.springframework.beans.PropertyValue


  private void doTestFieldSettingWithInstantiationAwarePostProcessor(final boolean skipPropertyPopulation) {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    int ageSetByPropertyValue = 27;
    bd.getPropertyValues().addPropertyValue(new PropertyValue("age", new Integer(ageSetByPropertyValue)));
    lbf.registerBeanDefinition("test", bd);
    final String nameSetOnField = "nameSetOnField";
    lbf.addBeanPostProcessor(new InstantiationAwareBeanPostProcessorAdapter() {
      public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        TestBean tb = (TestBean) bean;
View Full Code Here


  public void testNoArgGetter() {
    StaticApplicationContext ctx = new StaticApplicationContext();
    ctx.registerSingleton("testService", TestService.class, new MutablePropertyValues());
    MutablePropertyValues mpv = new MutablePropertyValues();
    mpv.addPropertyValue(new PropertyValue("serviceLocatorInterface", TestServiceLocator.class));
    ctx.registerSingleton("factory", ServiceLocatorFactoryBean.class, mpv);
    ctx.refresh();

    TestServiceLocator factory = (TestServiceLocator) ctx.getBean("factory");
    TestService testService = factory.getTestService();
View Full Code Here

  public void testErrorOnTooManyOrTooFew() throws Exception {
    StaticApplicationContext ctx = new StaticApplicationContext();
    ctx.registerSingleton("testService", TestService.class, new MutablePropertyValues());
    ctx.registerSingleton("testServiceInstance2", TestService.class, new MutablePropertyValues());
    MutablePropertyValues mpv = new MutablePropertyValues();
    mpv.addPropertyValue(new PropertyValue("serviceLocatorInterface", TestServiceLocator.class));
    ctx.registerSingleton("factory", ServiceLocatorFactoryBean.class, mpv);
    mpv = new MutablePropertyValues();
    mpv.addPropertyValue(new PropertyValue("serviceLocatorInterface", TestServiceLocator2.class));
    ctx.registerSingleton("factory2", ServiceLocatorFactoryBean.class, mpv);
    mpv = new MutablePropertyValues();
    mpv.addPropertyValue(new PropertyValue("serviceLocatorInterface", TestService2Locator.class));
    ctx.registerSingleton("factory3", ServiceLocatorFactoryBean.class, mpv);
    ctx.refresh();

    final TestServiceLocator factory = (TestServiceLocator) ctx.getBean("factory");
    new AssertThrows(NoSuchBeanDefinitionException.class, "Must fail on more than one matching type") {
View Full Code Here

  public void testErrorOnTooManyOrTooFewWithCustomServiceLocatorException() {
    StaticApplicationContext ctx = new StaticApplicationContext();
    ctx.registerSingleton("testService", TestService.class, new MutablePropertyValues());
    ctx.registerSingleton("testServiceInstance2", TestService.class, new MutablePropertyValues());
    MutablePropertyValues mpv = new MutablePropertyValues();
    mpv.addPropertyValue(new PropertyValue("serviceLocatorInterface", TestServiceLocator.class));
    mpv.addPropertyValue(new PropertyValue("serviceLocatorExceptionClass", CustomServiceLocatorException1.class));
    ctx.registerSingleton("factory", ServiceLocatorFactoryBean.class, mpv);
    mpv = new MutablePropertyValues();
    mpv.addPropertyValue(new PropertyValue("serviceLocatorInterface", TestServiceLocator2.class));
    mpv.addPropertyValue(new PropertyValue("serviceLocatorExceptionClass", CustomServiceLocatorException2.class));
    ctx.registerSingleton("factory2", ServiceLocatorFactoryBean.class, mpv);
    mpv = new MutablePropertyValues();
    mpv.addPropertyValue(new PropertyValue("serviceLocatorInterface", TestService2Locator.class));
    mpv.addPropertyValue(new PropertyValue("serviceLocatorExceptionClass", CustomServiceLocatorException3.class));
    ctx.registerSingleton("factory3", ServiceLocatorFactoryBean.class, mpv);
    ctx.refresh();

    TestServiceLocator factory = (TestServiceLocator) ctx.getBean("factory");
    try {
View Full Code Here

  public void testStringArgGetter() throws Exception {
    StaticApplicationContext ctx = new StaticApplicationContext();
    ctx.registerSingleton("testService", TestService.class, new MutablePropertyValues());
    MutablePropertyValues mpv = new MutablePropertyValues();
    mpv.addPropertyValue(new PropertyValue("serviceLocatorInterface", TestServiceLocator2.class));
    ctx.registerSingleton("factory", ServiceLocatorFactoryBean.class, mpv);
    ctx.refresh();

    // test string-arg getter with null id
    final TestServiceLocator2 factory = (TestServiceLocator2) ctx.getBean("factory");
View Full Code Here

            BeanDefinition def = ctxt.getBeanFactory().getBeanDefinition(beanName);
            if (!ctxt.getBeanFactory().isSingleton(beanName) || def.isAbstract()) {
                return false;
            }
            Collection<?> ids = null;
            PropertyValue pv = def.getPropertyValues().getPropertyValue(propertyName);
           
            if (pv != null) {
                Object value = pv.getValue();
                if (!(value instanceof Collection)) {
                    throw new RuntimeException("The property " + propertyName + " must be a collection!");
                }
   
                if (value instanceof Mergeable) {
View Full Code Here

    private DefaultListableBeanFactory beanFactory;

    private SpringBeanFinder finder;

    private MutablePropertyValues createServerResourcePropertyValues() {
        return new MutablePropertyValues(Arrays.asList(new PropertyValue("src",
                "spring")));
    }
View Full Code Here

        public void insertBeanInTarget(String oldName)
        {
            assertTargetPresent();
            String newName = bestGuessName(targetConfig, oldName, target.getBeanClassName());
            MutablePropertyValues targetProperties = target.getPropertyValues();
            PropertyValue pv = targetProperties.getPropertyValue(newName);
            Object oldValue = null == pv ? null : pv.getValue();

            BeanDefinitionBuilder wrapper = BeanDefinitionBuilder.genericBeanDefinition(wrapperClass);
            wrapper.addPropertyValue(propertyNameInWrapper, bean.getBeanDefinition());

            if (oldValue == null)
            {
                oldValue = new ManagedList();
                pv = new PropertyValue(newName, oldValue);
                targetProperties.addPropertyValue(pv);
            }
            if (targetConfig.isCollection(oldName))
            {
                List list = retrieveList(oldValue);
View Full Code Here

                newName).getValue()).get(0);

            BeanDefinitionBuilder messageFilter = BeanDefinitionBuilder.genericBeanDefinition(MessageFilter.class);
            messageFilter.addPropertyValue(FILTER, ref);

            PropertyValue pv = targetProperties.getPropertyValue(newName);
            Object oldValue = null == pv ? null : pv.getValue();

            if (oldValue == null)
            {
                oldValue = new ManagedList();
                pv = new PropertyValue(newName, oldValue);
                targetProperties.addPropertyValue(pv);
            }
            if (targetConfig.isCollection(oldName))
            {
                List list = retrieveList(oldValue);
View Full Code Here

        assertTargetPresent();
        String beanClass = bean.getBeanDefinition().getBeanClassName();
        PropertyValues sourceProperties = bean.getRawBeanDefinition().getPropertyValues();
        String newName = bestGuessName(targetConfig, oldName, target.getBeanClassName());
        MutablePropertyValues targetProperties = target.getPropertyValues();
        PropertyValue pv = targetProperties.getPropertyValue(newName);
        Object oldValue = null == pv ? null : pv.getValue();

        if (! targetConfig.isIgnored(oldName))
        {
            if (targetConfig.isCollection(oldName) ||
                    beanClass.equals(ChildListEntryDefinitionParser.ListEntry.class.getName()))
            {
                if (null == oldValue)
                {
                    if (beanClass.equals(ChildMapEntryDefinitionParser.KeyValuePair.class.getName()) ||
                            beanClass.equals(MapEntryCombiner.class.getName()) ||
                            beanClass.equals(MapFactoryBean.class.getName()))
                    {
                        // a collection of maps requires an extra intermediate object that does the
                        // lazy combination/caching of maps when first used
                        BeanDefinitionBuilder combiner = BeanDefinitionBuilder.rootBeanDefinition(MapCombiner.class);
                        targetProperties.addPropertyValue(newName, combiner.getBeanDefinition());
                        MutablePropertyValues combinerProperties = combiner.getBeanDefinition().getPropertyValues();
                        oldValue = new ManagedList();
                        pv = new PropertyValue(MapCombiner.LIST, oldValue);
                        combinerProperties.addPropertyValue(pv);
                    }
                    else
                    {
                        oldValue = new ManagedList();
                        pv = new PropertyValue(newName, oldValue);
                        targetProperties.addPropertyValue(pv);
                    }
                }

                List list = retrieveList(oldValue);
                if (ChildMapEntryDefinitionParser.KeyValuePair.class.getName().equals(beanClass))
                {
                    list.add(new ManagedMap());
                    retrieveMap(list.get(list.size() - 1)).put(
                            sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.KEY).getValue(),
                            sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.VALUE).getValue());
                }
                else if (beanClass.equals(ChildListEntryDefinitionParser.ListEntry.class.getName()))
                {
                    list.add(sourceProperties.getPropertyValue(ChildListEntryDefinitionParser.VALUE).getValue());
                }
                else
                {
                    list.add(bean.getBeanDefinition());
                }
            }
            else
            {
                // not a collection

                if (ChildMapEntryDefinitionParser.KeyValuePair.class.getName().equals(beanClass))
                {
                    if (null == pv || null == oldValue)
                    {
                        pv = new PropertyValue(newName, new ManagedMap());
                        targetProperties.addPropertyValue(pv);
                    }
                    retrieveMap(pv.getValue()).put(
                            sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.KEY).getValue(),
                            sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.VALUE).getValue());
                }
                else
                {
View Full Code Here

TOP

Related Classes of org.springframework.beans.PropertyValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.