Java 类org.springframework.beans.factory.support.AbstractBeanFactory 实例源码

项目:gemini.blueprint    文件:CMUtils.java   
/**
 * Injects the properties from the given Map to the given object. Additionally, a bean factory can be passed in for
 * copying property editors inside the injector.
 * 
 * @param instance bean instance to configure
 * @param properties
 * @param beanFactory
 */
public static void applyMapOntoInstance(Object instance, Map<String, ?> properties, AbstractBeanFactory beanFactory) {
    if (properties != null && !properties.isEmpty()) {
        BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(instance);
        beanWrapper.setAutoGrowNestedPaths(true);

        // configure bean wrapper (using method from Spring 2.5.6)
        if (beanFactory != null) {
            beanFactory.copyRegisteredEditorsTo(beanWrapper);
        }
        for (Iterator<?> iterator = properties.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry<String, ?> entry = (Map.Entry<String, ?>) iterator.next();
            String propertyName = entry.getKey();
            if (beanWrapper.isWritableProperty(propertyName)) {
                beanWrapper.setPropertyValue(propertyName, entry.getValue());
            }
        }
    }
}
项目:spring-osgi    文件:CMUtils.java   
/**
 * Injects the properties from the given Map to the given object.
 * Additionally, a bean factory can be passed in for copying property
 * editors inside the injector.
 * 
 * @param instance bean instance to configure
 * @param properties
 * @param beanFactory
 */
public static void applyMapOntoInstance(Object instance, Map properties, AbstractBeanFactory beanFactory) {
    if (properties != null && !properties.isEmpty()) {
        BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(instance);
        // configure bean wrapper (using method from Spring 2.5.6)
        if (beanFactory != null) {
            beanFactory.copyRegisteredEditorsTo(beanWrapper);
        }
        for (Iterator iterator = properties.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();
            String propertyName = (String) entry.getKey();
            if (beanWrapper.isWritableProperty(propertyName)) {
                beanWrapper.setPropertyValue(propertyName, entry.getValue());
            }
        }
    }
}
项目:gemini.blueprint    文件:DefaultManagedServiceBeanManager.java   
public DefaultManagedServiceBeanManager(boolean autowireOnUpdate, String methodName,
        ConfigurationAdminManager cam, BeanFactory beanFactory) {

    updateCallback = CMUtils.createCallback(autowireOnUpdate, methodName, beanFactory);
    bf = (beanFactory instanceof AbstractBeanFactory ? (AbstractBeanFactory) beanFactory : null);
    this.cam = cam;
    this.cam.setBeanManager(this);
}
项目:gemini.blueprint    文件:AbstractOsgiBundleApplicationContext.java   
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    super.postProcessBeanFactory(beanFactory);

    beanFactory.addBeanPostProcessor(new BundleContextAwareProcessor(this.bundleContext));
    beanFactory.ignoreDependencyInterface(BundleContextAware.class);

    if (beanFactory instanceof AbstractBeanFactory) {
        AbstractBeanFactory bf = (AbstractBeanFactory) beanFactory;
        bf.setSecurityContextProvider(new SecurityContextProvider() {

            public AccessControlContext getAccessControlContext() {
                return acc;
            }
        });
    }

    enforceExporterImporterDependency(beanFactory);

    // add predefined beans
    // bundleContext
    addPredefinedBean(beanFactory, BUNDLE_CONTEXT_BEAN_NAME, this.bundleContext);
    addPredefinedBean(beanFactory, BUNDLE_BEAN_NAME, this.bundle);

    // register property editors
    registerPropertyEditors(beanFactory);

    // register a 'bundle' scope
    beanFactory.registerScope(OsgiBundleScope.SCOPE_NAME, new OsgiBundleScope());
}
项目:gemini.blueprint    文件:BlueprintConverterConfigurer.java   
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
    if (beanFactory instanceof AbstractBeanFactory) {
        AbstractBeanFactory bf = ((AbstractBeanFactory) beanFactory);
        ConversionService cs = bf.getConversionService();
        if (cs instanceof SpringBlueprintConverterService) {
            cs = null;
        }
        SpringBlueprintConverterService sbc = new SpringBlueprintConverterService(cs, bf);
        sbc.add(converters);
        bf.setConversionService(sbc);
    }
}
项目:multi-task    文件:TaskBeanContainer.java   
/**
 * 注册一个Fetcher
 *
 * @param service
 * @param method
 * @param beanName
 */
private static void registerFetcher(final Object service, final Method method, final String beanName) {
    if (TaskBeanContainer.containsBean(beanName)) {
        throw new TaskBizException("Fetcher bean duplicate for Spring:" + beanName);
    }

    final int paramLen = method.getGenericParameterTypes().length;
    Taskable<?> fetcher = TaskBeanHelper.newFetcher(service, method, beanName, paramLen);

    BeanFactory factory = applicationContext.getAutowireCapableBeanFactory();

    if (factory instanceof DefaultListableBeanFactory) {
        DefaultListableBeanFactory defaultFactory = (DefaultListableBeanFactory) factory;
        defaultFactory.registerSingleton(beanName, fetcher);
        // GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        // beanDefinition.setBeanClass(task.getClass());
        // listFactory.registerBeanDefinition(beanName, beanDefinition);
        LOG.info("DefaultListableBeanFactory Fetcher register: " + beanName);
    } else if (factory instanceof AbstractBeanFactory) {
        AbstractBeanFactory abstFactory = (AbstractBeanFactory) factory;
        abstFactory.registerSingleton(beanName, fetcher);
        LOG.info("AbstractBeanFactory Fetcher register: " + beanName);
    } else {
        container.put(beanName, fetcher);
        LOG.info("LocalContainer Fetcher register: " + beanName);
    }
}
项目:spring4-understanding    文件:DefaultListableBeanFactoryTests.java   
@Test
public void testBeanDefinitionWithAbstractClass() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.registerBeanDefinition("test", new RootBeanDefinition(AbstractBeanFactory.class));
    try {
        lbf.getBean("test");
        fail("Should have thrown BeanCreationException");
    }
    catch (BeanCreationException ex) {
        assertEquals("test", ex.getBeanName());
        assertTrue(ex.getMessage().toLowerCase().contains("abstract"));
    }
}
项目:class-guard    文件:DefaultListableBeanFactoryTests.java   
@Test
public void testBeanDefinitionWithAbstractClass() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.registerBeanDefinition("test", new RootBeanDefinition(AbstractBeanFactory.class));
    try {
        lbf.getBean("test");
        fail("Should have thrown BeanCreationException");
    }
    catch (BeanCreationException ex) {
        assertEquals("test", ex.getBeanName());
        assertTrue(ex.getMessage().toLowerCase().indexOf("abstract") != -1);
    }
}
项目:spring-osgi    文件:DefaultManagedServiceBeanManager.java   
public DefaultManagedServiceBeanManager(UpdateStrategy updateStrategy, String methodName,
        ConfigurationAdminManager cam, BeanFactory beanFactory) {

    updateCallback = CMUtils.createCallback(updateStrategy, methodName, beanFactory);
    bf = (beanFactory instanceof AbstractBeanFactory ? (AbstractBeanFactory) beanFactory : null);
    this.cam = cam;
    this.cam.setBeanManager(this);
}
项目:gemini.blueprint    文件:ContainerManagedUpdate.java   
/**
 * Constructs a new <code>ContainerManagedUpdate</code> instance.
 * 
 * @param beanFactory
 */
public ContainerManagedUpdate(BeanFactory beanFactory) {
    super();
    this.beanFactory = (beanFactory instanceof AbstractBeanFactory ? (AbstractBeanFactory) beanFactory : null);
}
项目:spring-osgi    文件:ContainerManagedUpdate.java   
/**
 * Constructs a new <code>ContainerManagedUpdate</code> instance.
 * 
 * @param beanFactory
 */
public ContainerManagedUpdate(BeanFactory beanFactory) {
    super();
    this.beanFactory = (beanFactory instanceof AbstractBeanFactory ? (AbstractBeanFactory) beanFactory : null);
}