Java 类org.springframework.beans.factory.xml.XmlBeanDefinitionReader 实例源码

项目:spring4-understanding    文件:CallbacksSecurityTests.java   
@Before
public void setUp() throws Exception {

    final ProtectionDomain empty = new ProtectionDomain(null,
            new Permissions());

    provider = new SecurityContextProvider() {
        private final AccessControlContext acc = new AccessControlContext(
                new ProtectionDomain[] { empty });

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

    DefaultResourceLoader drl = new DefaultResourceLoader();
    Resource config = drl
            .getResource("/org/springframework/beans/factory/support/security/callbacks.xml");
    beanFactory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(config);
    beanFactory.setSecurityContextProvider(provider);
}
项目:gemini.blueprint    文件:NestedReferencesTest.java   
protected void setUp() throws Exception {

        BundleContext bundleContext = new MockBundleContext() {
            // service reference already registered
            public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
                return new ServiceReference[0];
            }
        };

        appContext = new GenericApplicationContext();
        appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
        appContext.setClassLoader(getClass().getClassLoader());

        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
        // reader.setEventListener(this.listener);
        reader.loadBeanDefinitions(new ClassPathResource("osgiReferenceNestedBeans.xml", getClass()));
        appContext.refresh();
    }
项目:gemini.blueprint    文件:OsgiDefaultsTests.java   
protected void setUp() throws Exception {
    BundleContext bundleContext = new MockBundleContext() {
        // service reference already registered
        public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
            return new ServiceReference[] { new MockServiceReference(new String[] { Serializable.class.getName() }) };
        }
    };

    appContext = new GenericApplicationContext();
    appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    appContext.setClassLoader(getClass().getClassLoader());

    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
    reader.loadBeanDefinitions(new ClassPathResource("osgiDefaults.xml", getClass()));
    appContext.refresh();
}
项目:gemini.blueprint    文件:BaseMetadataTest.java   
protected void setUp() throws Exception {
    bundleContext = new MockBundleContext();
    applicationContext = new GenericApplicationContext();
    applicationContext.setClassLoader(getClass().getClassLoader());
    applicationContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    applicationContext.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            beanFactory.addPropertyEditorRegistrar(new BlueprintEditorRegistrar());
        }
    });
    reader = new XmlBeanDefinitionReader(applicationContext);
    reader.setDocumentLoader(new PublicBlueprintDocumentLoader());
    reader.loadBeanDefinitions(new ClassPathResource(getConfig(), getClass()));
    applicationContext.refresh();
    blueprintContainer = new SpringBlueprintContainer(applicationContext);
}
项目:gemini.blueprint    文件:NestedDefinitionMetadataTest.java   
protected void setUp() throws Exception {
    bundleContext = new MockBundleContext();

    context = new GenericApplicationContext();
    context.setClassLoader(getClass().getClassLoader());
    context.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            beanFactory.addPropertyEditorRegistrar(new BlueprintEditorRegistrar());
        }
    });

    reader = new XmlBeanDefinitionReader(context);
    reader.setDocumentLoader(new PublicBlueprintDocumentLoader());
    reader.loadBeanDefinitions(new ClassPathResource(CONFIG, getClass()));
    context.refresh();

    blueprintContainer = new SpringBlueprintContainer(context);
}
项目:gemini.blueprint    文件:SpringDmRfc124Test.java   
protected void setUp() throws Exception {
    BundleContext bundleContext = new MockBundleContext() {

        // service reference already registered
        public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
            return new ServiceReference[] { new MockServiceReference(new String[] { Cloneable.class.getName() }) };
        }
    };

    context = new GenericApplicationContext();
    context.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    context.setClassLoader(getClass().getClassLoader());

    reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(new ClassPathResource(CONFIG, getClass()));
    context.refresh();
}
项目:gemini.blueprint    文件:GenericsTest.java   
protected void setUp() throws Exception {
    bundleContext = new MockBundleContext();

    context = new GenericApplicationContext();
    context.setClassLoader(getClass().getClassLoader());
    context.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    SpringBlueprintConverterService converterService =
            new SpringBlueprintConverterService(null, context.getBeanFactory());
    converterService.add(new GenericConverter());
    context.getBeanFactory().setConversionService(converterService);

    reader = new XmlBeanDefinitionReader(context);
    reader.setDocumentLoader(new PublicBlueprintDocumentLoader());
    reader.loadBeanDefinitions(new ClassPathResource(CONFIG, getClass()));
    context.refresh();

    blueprintContainer = new SpringBlueprintContainer(context);
}
项目:gemini.blueprint    文件:TestLazyBeansTest.java   
protected void setUp() throws Exception {
    bundleContext = new MockBundleContext();

    context = new GenericApplicationContext();
    context.setClassLoader(getClass().getClassLoader());
    context.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            beanFactory.addPropertyEditorRegistrar(new BlueprintEditorRegistrar());
            beanFactory.registerSingleton("blueprintContainer",
                    new SpringBlueprintContainer(context));
        }
    });

    reader = new XmlBeanDefinitionReader(context);
    reader.setDocumentLoader(new PublicBlueprintDocumentLoader());
    reader.loadBeanDefinitions(new ClassPathResource(CONFIG, getClass()));
    context.refresh();

    blueprintContainer = new SpringBlueprintContainer(context);
}
项目:gemini.blueprint    文件:TestBlueprintBuiltinConvertersTest.java   
protected void setUp() throws Exception {
    bundleContext = new MockBundleContext();

    context = new GenericApplicationContext();
    context.setClassLoader(getClass().getClassLoader());
    context.getBeanFactory().setConversionService(
            new SpringBlueprintConverterService(null, context.getBeanFactory()));
    context.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));

    reader = new XmlBeanDefinitionReader(context);
    reader.setDocumentLoader(new PublicBlueprintDocumentLoader());
    reader.loadBeanDefinitions(new ClassPathResource(CONFIG, getClass()));
    context.refresh();

    blueprintContainer = new SpringBlueprintContainer(context);
}
项目:gemini.blueprint    文件:LazyExporterTest.java   
protected void setUp() throws Exception {
    bundleContext = new MockBundleContext();

    context = new GenericApplicationContext();
    context.setClassLoader(getClass().getClassLoader());
    context.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            beanFactory.addPropertyEditorRegistrar(new BlueprintEditorRegistrar());
        }
    });

    reader = new XmlBeanDefinitionReader(context);
    reader.setDocumentLoader(new PublicBlueprintDocumentLoader());
    reader.loadBeanDefinitions(new ClassPathResource(CONFIG, getClass()));
    context.refresh();

    blueprintContainer = new SpringBlueprintContainer(context);
}
项目:lams    文件:XmlWebApplicationContext.java   
/**
 * Loads the bean definitions via an XmlBeanDefinitionReader.
 * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 * @see #initBeanDefinitionReader
 * @see #loadBeanDefinitions
 */
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {
    // Create a new XmlBeanDefinitionReader for the given BeanFactory.
    XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

    // Configure the bean definition reader with this context's
    // resource loading environment.
    beanDefinitionReader.setEnvironment(getEnvironment());
    beanDefinitionReader.setResourceLoader(this);
    beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

    // Allow a subclass to provide custom initialization of the reader,
    // then proceed with actually loading the bean definitions.
    initBeanDefinitionReader(beanDefinitionReader);
    loadBeanDefinitions(beanDefinitionReader);
}
项目:lams    文件:AbstractXmlApplicationContext.java   
/**
 * Loads the bean definitions via an XmlBeanDefinitionReader.
 * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 * @see #initBeanDefinitionReader
 * @see #loadBeanDefinitions
 */
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {
    // Create a new XmlBeanDefinitionReader for the given BeanFactory.
    XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

    // Configure the bean definition reader with this context's
    // resource loading environment.
    beanDefinitionReader.setEnvironment(this.getEnvironment());
    beanDefinitionReader.setResourceLoader(this);
    beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

    // Allow a subclass to provide custom initialization of the reader,
    // then proceed with actually loading the bean definitions.
    initBeanDefinitionReader(beanDefinitionReader);
    loadBeanDefinitions(beanDefinitionReader);
}
项目:spring4-understanding    文件:RegexpMethodPointcutAdvisorIntegrationTests.java   
@Test
public void testSinglePattern() throws Throwable {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
    ITestBean advised = (ITestBean) bf.getBean("settersAdvised");
    // Interceptor behind regexp advisor
    NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
    assertEquals(0, nop.getCount());

    int newAge = 12;
    // Not advised
    advised.exceptional(null);
    assertEquals(0, nop.getCount());
    advised.setAge(newAge);
    assertEquals(newAge, advised.getAge());
    // Only setter fired
    assertEquals(1, nop.getCount());
}
项目:spring4-understanding    文件:RegexpMethodPointcutAdvisorIntegrationTests.java   
@Test
public void testMultiplePatterns() throws Throwable {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
    // This is a CGLIB proxy, so we can proxy it to the target class
    TestBean advised = (TestBean) bf.getBean("settersAndAbsquatulateAdvised");
    // Interceptor behind regexp advisor
    NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
    assertEquals(0, nop.getCount());

    int newAge = 12;
    // Not advised
    advised.exceptional(null);
    assertEquals(0, nop.getCount());

    // This is proxied
    advised.absquatulate();
    assertEquals(1, nop.getCount());
    advised.setAge(newAge);
    assertEquals(newAge, advised.getAge());
    // Only setter fired
    assertEquals(2, nop.getCount());
}
项目:spring4-understanding    文件:XmlPortletApplicationContext.java   
/**
 * Loads the bean definitions via an XmlBeanDefinitionReader.
 * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 * @see #initBeanDefinitionReader
 * @see #loadBeanDefinitions
 */
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {
    // Create a new XmlBeanDefinitionReader for the given BeanFactory.
    XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

    // Configure the bean definition reader with this context's
    // resource loading environment.
    beanDefinitionReader.setEnvironment(this.getEnvironment());
    beanDefinitionReader.setResourceLoader(this);
    beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

    // Allow a subclass to provide custom initialization of the reader,
    // then proceed with actually loading the bean definitions.
    initBeanDefinitionReader(beanDefinitionReader);
    loadBeanDefinitions(beanDefinitionReader);
}
项目:spring4-understanding    文件:PropertyPathFactoryBeanTests.java   
@Test
public void testPropertyPathFactoryBeanWithPrototypeResult() {
    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
    assertNull(xbf.getType("tb.spouse"));
    assertEquals(TestBean.class, xbf.getType("propertyPath3"));
    Object result1 = xbf.getBean("tb.spouse");
    Object result2 = xbf.getBean("propertyPath3");
    Object result3 = xbf.getBean("propertyPath3");
    assertTrue(result1 instanceof TestBean);
    assertTrue(result2 instanceof TestBean);
    assertTrue(result3 instanceof TestBean);
    assertEquals(11, ((TestBean) result1).getAge());
    assertEquals(11, ((TestBean) result2).getAge());
    assertEquals(11, ((TestBean) result3).getAge());
    assertTrue(result1 != result2);
    assertTrue(result1 != result3);
    assertTrue(result2 != result3);
}
项目:spring4-understanding    文件:AbstractXmlApplicationContext.java   
/**
 * Loads the bean definitions via an XmlBeanDefinitionReader.
 * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 * @see #initBeanDefinitionReader
 * @see #loadBeanDefinitions
 */
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {
    // Create a new XmlBeanDefinitionReader for the given BeanFactory.
    XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

    // Configure the bean definition reader with this context's
    // resource loading environment.
    beanDefinitionReader.setEnvironment(this.getEnvironment());
    beanDefinitionReader.setResourceLoader(this);
    beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

    // Allow a subclass to provide custom initialization of the reader,
    // then proceed with actually loading the bean definitions.
    initBeanDefinitionReader(beanDefinitionReader);
    loadBeanDefinitions(beanDefinitionReader);
}
项目:meta    文件:TestDefaultListableBeanFactory.java   
public static void main(String[] args) throws IOException {
        ClassPathResource classPathResource = new ClassPathResource("beans.xml");
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);

        reader.loadBeanDefinitions(classPathResource);

        Person person = factory.getBean("person",Person.class);
        System.out.println(person.getHand());

        System.out.println(person.getName());
        System.out.println(classPathResource.getURL());
        System.out.println(classPathResource.getFile().getAbsolutePath());

        String fileUrl = classPathResource.getFile().getAbsolutePath();
        ApplicationContext context = new FileSystemXmlApplicationContext("/Users/fahai/soft/project/meta/src/main/resources/beans.xml");
        Person person1 = (Person) factory.getBean("person");
//        System.out.println(person1.getName());
//        DefaultListableBeanFactory


    }
项目:spring4-understanding    文件:ClassPathXmlApplicationContextTests.java   
@Test
public void testGenericApplicationContextWithXmlBeanDefinitionsAndClassLoaderNull() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    ctx.setClassLoader(null);
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
    reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass()));
    reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_C, getClass()));
    reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_A, getClass()));
    ctx.refresh();
    assertEquals(ObjectUtils.identityToString(ctx), ctx.getId());
    assertEquals(ObjectUtils.identityToString(ctx), ctx.getDisplayName());
    assertTrue(ctx.containsBean("service"));
    assertTrue(ctx.containsBean("logicOne"));
    assertTrue(ctx.containsBean("logicTwo"));
    ctx.close();
}
项目:spring4-understanding    文件:ClassPathXmlApplicationContextTests.java   
@Test
public void testGenericApplicationContextWithXmlBeanDefinitionsAndSpecifiedId() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    ctx.setId("testContext");
    ctx.setDisplayName("Test Context");
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
    reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass()));
    reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_C, getClass()));
    reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_A, getClass()));
    ctx.refresh();
    assertEquals("testContext", ctx.getId());
    assertEquals("Test Context", ctx.getDisplayName());
    assertTrue(ctx.containsBean("service"));
    assertTrue(ctx.containsBean("logicOne"));
    assertTrue(ctx.containsBean("logicTwo"));
    ctx.close();
}
项目:spring4-understanding    文件:AspectJAutoProxyCreatorTests.java   
@Test
public void testAspectsAndAdvisorNotAppliedToManySingletonsIsFastEnough() {
    Assume.group(TestGroup.PERFORMANCE);
    Assume.notLogging(factoryLog);
    GenericApplicationContext ac = new GenericApplicationContext();
    new XmlBeanDefinitionReader(ac).loadBeanDefinitions(new ClassPathResource(qName("aspectsPlusAdvisor.xml"),
            getClass()));
    for (int i = 0; i < 10000; i++) {
        ac.registerBeanDefinition("singleton" + i, new RootBeanDefinition(NestedTestBean.class));
    }
    StopWatch sw = new StopWatch();
    sw.start("Singleton Creation");
    ac.refresh();
    sw.stop();

    // What's a reasonable expectation for _any_ server or developer machine load?
    // 8 seconds?
    assertStopWatchTimeLimit(sw, 8000);
}
项目:spring    文件:AbstractXmlApplicationContext.java   
/**
 * Loads the bean definitions via an XmlBeanDefinitionReader.
 * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 * @see #initBeanDefinitionReader
 * @see #loadBeanDefinitions
 */
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {
    // Create a new XmlBeanDefinitionReader for the given BeanFactory.
    XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory); // 创建XmlBeanDefinitionReader

    // Configure the bean definition reader with this context's
    // resource loading environment.
    beanDefinitionReader.setEnvironment(this.getEnvironment());
    beanDefinitionReader.setResourceLoader(this);
    beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

    // Allow a subclass to provide custom initialization of the reader,
    // then proceed with actually loading the bean definitions.
    initBeanDefinitionReader(beanDefinitionReader);
    loadBeanDefinitions(beanDefinitionReader); // 使用XmlBeanDefinitionReader加载BeanDefinition
}
项目:spring4-understanding    文件:ProxyFactoryBeanTests.java   
@Test
public void testGetObjectTypeWithDirectTarget() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS));

    // We have a counting before advice here
    CountingBeforeAdvice cba = (CountingBeforeAdvice) bf.getBean("countingBeforeAdvice");
    assertEquals(0, cba.getCalls());

    ITestBean tb = (ITestBean) bf.getBean("directTarget");
    assertTrue(tb.getName().equals("Adam"));
    assertEquals(1, cba.getCalls());

    ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&directTarget");
    assertTrue("Has correct object type", TestBean.class.isAssignableFrom(pfb.getObjectType()));
}
项目:spring4-understanding    文件:ProxyFactoryBeanTests.java   
@Test
public void testGetObjectTypeWithNoTargetOrTargetSource() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS));

    ITestBean tb = (ITestBean) bf.getBean("noTarget");
    try {
        tb.getName();
        fail();
    }
    catch (UnsupportedOperationException ex) {
        assertEquals("getName", ex.getMessage());
    }
    FactoryBean<?> pfb = (ProxyFactoryBean) bf.getBean("&noTarget");
    assertTrue("Has correct object type", ITestBean.class.isAssignableFrom(pfb.getObjectType()));
}
项目:spring4-understanding    文件:ProxyFactoryBeanTests.java   
@Test
public void testSerializableSingletonProxy() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
    Person p = (Person) bf.getBean("serializableSingleton");
    assertSame("Should be a Singleton", p, bf.getBean("serializableSingleton"));
    Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
    assertEquals(p, p2);
    assertNotSame(p, p2);
    assertEquals("serializableSingleton", p2.getName());

    // Add unserializable advice
    Advice nop = new NopInterceptor();
    ((Advised) p).addAdvice(nop);
    // Check it still works
    assertEquals(p2.getName(), p2.getName());
    assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p));

    // Remove offending interceptor...
    assertTrue(((Advised) p).removeAdvice(nop));
    assertTrue("Serializable again because offending interceptor was removed", SerializationTestUtils.isSerializable(p));
}
项目:spring4-understanding    文件:FactoryBeanTests.java   
@Test
public void testFactoryBeansWithAutowiring() throws Exception {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);

    BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
    ppc.postProcessBeanFactory(factory);

    assertNull(factory.getType("betaFactory"));

    Alpha alpha = (Alpha) factory.getBean("alpha");
    Beta beta = (Beta) factory.getBean("beta");
    Gamma gamma = (Gamma) factory.getBean("gamma");
    Gamma gamma2 = (Gamma) factory.getBean("gammaFactory");

    assertSame(beta, alpha.getBeta());
    assertSame(gamma, beta.getGamma());
    assertSame(gamma2, beta.getGamma());
    assertEquals("yourName", beta.getName());
}
项目:spring4-understanding    文件:XmlWebApplicationContext.java   
/**
 * Loads the bean definitions via an XmlBeanDefinitionReader.
 * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 * @see #initBeanDefinitionReader
 * @see #loadBeanDefinitions
 */
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {
    // Create a new XmlBeanDefinitionReader for the given BeanFactory.
    XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

    // Configure the bean definition reader with this context's
    // resource loading environment.
    beanDefinitionReader.setEnvironment(getEnvironment());
    beanDefinitionReader.setResourceLoader(this);
    beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

    // Allow a subclass to provide custom initialization of the reader,
    // then proceed with actually loading the bean definitions.
    initBeanDefinitionReader(beanDefinitionReader);
    loadBeanDefinitions(beanDefinitionReader);
}
项目:spring4-understanding    文件:BeanFactoryUtilsTests.java   
@Before
public void setUp() {
    // Interesting hierarchical factory to test counts.
    // Slow to read so we cache it.

    DefaultListableBeanFactory grandParent = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(grandParent).loadBeanDefinitions(ROOT_CONTEXT);
    DefaultListableBeanFactory parent = new DefaultListableBeanFactory(grandParent);
    new XmlBeanDefinitionReader(parent).loadBeanDefinitions(MIDDLE_CONTEXT);
    DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
    new XmlBeanDefinitionReader(child).loadBeanDefinitions(LEAF_CONTEXT);

    this.dependentBeansFactory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(this.dependentBeansFactory).loadBeanDefinitions(DEPENDENT_BEANS_CONTEXT);
    dependentBeansFactory.preInstantiateSingletons();
    this.listableBeanFactory = child;
}
项目:CodesOfLightweightJavaEE    文件:BeanTest.java   
public static void main(String[] args)throws Exception
    {
        // �������·���µ�beans.xml�ļ�������Spring����
//      ApplicationContext ctx = new
//          ClassPathXmlApplicationContext("beans.xml");
//      Person p = (Person)ctx.getBean("chinese");

        // ���������·���µ�beans.xml�ļ�����Resource����
        Resource isr = new ClassPathResource("beans.xml");
        // ����Ĭ�ϵ�BeanFactory����
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        // ��Ĭ�ϵ�BeanFactory��������isr��Ӧ��XML�����ļ�
        new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(isr);
        // ��ȡ�����е�Bean������
        BeanPostProcessor bp = (BeanPostProcessor)beanFactory.getBean("bp");
        // ע��Bean������
        beanFactory.addBeanPostProcessor(bp);
        Person p = (Person)beanFactory.getBean("chinese");

        p.useAxe();
    }
项目:alfresco-repository    文件:ContextDependencyLister.java   
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
   super.initBeanDefinitionReader(reader);

   btl = new BeanTrackingListener();
   reader.setEventListener(btl);
   // Work around a spring bug where setting the listener does nothing 
   try {
      Field f = reader.getClass().getDeclaredField("eventListener");
      f.setAccessible(true);
      f.set(reader, btl);
   } catch(Exception e) {
      throw new RuntimeException(e);
   }
}
项目:gemini.blueprint    文件:ConfigPropertiesHandlerTest.java   
protected void setUp() throws Exception {
    adminControl = createControl();
    admin = adminControl.createMock(ConfigurationAdmin.class);
    cfg = createMock(Configuration.class);

    config = new Hashtable<String, Object>();

    expect(admin.getConfiguration(persistentId)).andReturn(cfg).atLeastOnce();
    expect(cfg.getProperties()).andReturn(config).atLeastOnce();

    adminControl.replay();
    replay(cfg);

    bundleContext = new MockBundleContext() {

        // add Configuration admin support
        @Override
        public Object getService(ServiceReference reference) {
            return admin;
        }

        // ManagedService registration
        @Override
        public ServiceRegistration registerService(String clazz, Object service, Dictionary properties) {
            // save the callback
            if (ManagedService.class.getName().equals(clazz)) {
                msCallback = (ManagedService) service;
            }
            return super.registerService(clazz, service, properties);
        }
    };

    appContext = new GenericApplicationContext();
    appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));

    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
    // reader.setEventListener(this.listener);
    reader.loadBeanDefinitions(new ClassPathResource("configProperties.xml", getClass()));
    appContext.refresh();
}
项目:gemini.blueprint    文件:CmConfigAndCtxPropertiesConfigurationTest.java   
protected void setUp() throws Exception {
    admin = createMock(ConfigurationAdmin.class);
    Configuration cfg = createMock(Configuration.class);

    Dictionary config = new Hashtable();

    expect(admin.getConfiguration("com.xyz.myapp")).andReturn(cfg).atLeastOnce();
    expect(cfg.getProperties()).andReturn(config).atLeastOnce();

    replay(admin, cfg);

    BundleContext bundleContext = new MockBundleContext() {

        // add Configuration admin support
        public Object getService(ServiceReference reference) {
            return admin;
        }
    };

    GenericApplicationContext appContext = new GenericApplicationContext();
    appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));

    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
    // reader.setEventListener(this.listener);
    reader.loadBeanDefinitions(new ClassPathResource("osgiPropertyPlaceholder.xml", getClass()));
    appContext.refresh();
}
项目:gemini.blueprint    文件:ManagedServiceFactoryTest.java   
protected void setUp() throws Exception {


        final Configuration cfg = createMock(Configuration.class);
        expect(cfg.getProperties()).andReturn(new Hashtable<String, Object>());
        replay(cfg);

        BundleContext bundleContext = new MockBundleContext() {

            // always return a ConfigurationAdmin
            public Object getService(ServiceReference reference) {
                return new MockConfigurationAdmin() {

                    public Configuration getConfiguration(String pid) throws IOException {
                        return cfg;
                    }
                };
            }
        };

        appContext = new GenericApplicationContext();
        appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
        appContext.setClassLoader(getClass().getClassLoader());

        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
        reader.loadBeanDefinitions(new ClassPathResource("managedServiceFactory.xml", getClass()));
        appContext.refresh();
    }
项目:gemini.blueprint    文件:OsgiReferenceNamespaceHandlerTest.java   
protected void setUp() throws Exception {
    // reset counter just to be sure
    DummyListener.BIND_CALLS = 0;
    DummyListener.UNBIND_CALLS = 0;

    DummyListenerServiceSignature.BIND_CALLS = 0;
    DummyListenerServiceSignature.UNBIND_CALLS = 0;

    DummyListenerServiceSignature2.BIND_CALLS = 0;
    DummyListenerServiceSignature2.UNBIND_CALLS = 0;

    BundleContext bundleContext = new MockBundleContext() {
        // service reference already registered
        public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
            return new ServiceReference[] { new MockServiceReference(new String[] { Cloneable.class.getName() }) };
        }
    };

    appContext = new GenericApplicationContext();
    appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    appContext.setClassLoader(getClass().getClassLoader());

    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
    // reader.setEventListener(this.listener);
    reader.loadBeanDefinitions(new ClassPathResource("osgiReferenceNamespaceHandlerTests.xml", getClass()));
    appContext.refresh();
}
项目:gemini.blueprint    文件:BundleFactoryBeanParserTest.java   
private void refresh() {
    replay(installBundle, startBundle, updateBundle);

    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
    reader.loadBeanDefinitions(new ClassPathResource("bundleBeanFactoryTest.xml", getClass()));

    appContext.refresh();
}
项目:gemini.blueprint    文件:OsgiReferenceCollectionNamespaceHandlerTest.java   
protected void setUp() throws Exception {
    // reset counter just to be sure
    DummyListener.BIND_CALLS = 0;
    DummyListener.UNBIND_CALLS = 0;

    DummyListenerServiceSignature.BIND_CALLS = 0;
    DummyListenerServiceSignature.UNBIND_CALLS = 0;

    DummyListenerServiceSignature2.BIND_CALLS = 0;
    DummyListenerServiceSignature2.UNBIND_CALLS = 0;

    BundleContext bundleContext = new MockBundleContext() {

        // service reference already registered
        public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
            return new ServiceReference[0];
        }
    };

    appContext = new GenericApplicationContext();
    appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    appContext.setClassLoader(getClass().getClassLoader());

    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
    // reader.setEventListener(this.listener);
    reader.loadBeanDefinitions(new ClassPathResource("osgiReferenceCollectionNamespaceHandlerTests.xml", getClass()));
    appContext.refresh();
}
项目:gemini.blueprint    文件:InvalidOsgiDefaultsTest.java   
public void testInvalidDefaultsCheck() throws Exception {
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);

    try {
        reader.loadBeanDefinitions(new ClassPathResource("osgiInvalidDefaults.xml", getClass()));
        fail("should have failed since osgi:defaults cannot be used outside the root element");
    }
    catch (BeanDefinitionParsingException ex) {
        // expected
    }
}
项目:gemini.blueprint    文件:OsgiServiceNamespaceHandlerTest.java   
protected void setUp() throws Exception {

        services.clear();

        RegistrationListener.BIND_CALLS = 0;
        RegistrationListener.UNBIND_CALLS = 0;

        CustomRegistrationListener.REG_CALLS = 0;
        CustomRegistrationListener.UNREG_CALLS = 0;

        registration = new MockServiceRegistration();

        bundleContext = new MockBundleContext() {

            public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
                return new ServiceReference[] { new MockServiceReference(new String[] { Cloneable.class.getName() }) };
            }

            public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties) {
                services.add(service);
                return registration;
            }
        };

        appContext = new GenericApplicationContext();
        appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));

        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
        // reader.setEventListener(this.listener);
        reader.loadBeanDefinitions(new ClassPathResource("osgiServiceNamespaceHandlerTests.xml", getClass()));
        appContext.refresh();
    }
项目:gemini.blueprint    文件:ConstructorInjectionTest.java   
protected void setUp() throws Exception {
    context = new GenericApplicationContext();
    context.setClassLoader(getClass().getClassLoader());
    reader = new XmlBeanDefinitionReader(context);
    reader.setDocumentLoader(new PublicBlueprintDocumentLoader());
    reader.loadBeanDefinitions(new ClassPathResource(CONFIG, getClass()));
    context.getBeanFactory().setConversionService(new SpringBlueprintConverterService(null, context.getBeanFactory()));
    context.refresh();
    container = new SpringBlueprintContainer(context);
}
项目:gemini.blueprint    文件:ComponentSubElementTest.java   
protected void setUp() throws Exception {
    bundleContext = new MockBundleContext();

    context = new GenericApplicationContext();
    context.setClassLoader(getClass().getClassLoader());
    context.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            beanFactory.addPropertyEditorRegistrar(new BlueprintEditorRegistrar());
        }
    });

    reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(new ClassPathResource(CONFIG, getClass()));
    context.refresh();

    BlueprintContainer = new SpringBlueprintContainer(context);
}