Package org.springframework.beans.factory

Examples of org.springframework.beans.factory.BeanFactory


        this.springBeanFactoryHolder = springBeanFactoryHolder;
    }

    public void initialize(HttpServlet servlet) {
        ServletContext servletContext = servlet.getServletContext();
        BeanFactory beanFactory = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        this.springBeanFactoryHolder.setBeanFactory(beanFactory);
    }
View Full Code Here


    BeanFactoryReference reference2 = locator2.useBeanFactory(INSTANCE_2);
    BeanFactoryReference aliasRef1 = locator1.useBeanFactory("alias1");
    BeanFactoryReference aliasRef2 = locator1.useBeanFactory("alias2");

    // verify the static map
    BeanFactory factory1 = reference1.getFactory();
    BeanFactory factory2 = reference2.getFactory();
    BeanFactory factory3 = reference2.getFactory();
    // get the alias from different factories
    BeanFactory alias1 = aliasRef1.getFactory();
    BeanFactory alias2 = aliasRef2.getFactory();

    assertSame(factory1, factory2);
    assertSame(factory1, factory3);
    // verify it's the same bean factory as the application context
    assertSame(factory1, applicationContext.getBeanFactory());
View Full Code Here

  /**
   * @see org.springframework.beans.factory.access.BeanFactoryLocator#useBeanFactory(java.lang.String)
   */
  public BeanFactoryReference useBeanFactory(String factoryKey) throws BeansException {
    // see if there is a default FactoryBean
    BeanFactory factory;

    if (factoryKey == null) {
      if (!canUseDefaultBeanFactory)
        throw new IllegalArgumentException(
            "a non-null factoryKey needs to be specified as there are more then one factoryKeys available ");
      factory = defaultFactory;
    }
    else {
      factory = (BeanFactory) beanFactories.get(factoryKey);
      if (factory == null)
        throw new IllegalArgumentException("there is no beanFactory under key " + factoryKey);
    }

    // increment counter
    synchronized (referenceCounter) {
      Integer counter = (Integer) referenceCounter.get(factory);
      referenceCounter.put(factory, new Integer(counter.intValue() + 1));
    }

    final BeanFactory finalFactory = factory;

    // simple implementation
    return new BeanFactoryReference() {
      private BeanFactory fact = finalFactory;

View Full Code Here

  /**
   * @see org.springframework.beans.factory.access.BeanFactoryLocator#useBeanFactory(java.lang.String)
   */
  public BeanFactoryReference useBeanFactory(String factoryKey) throws BeansException {
    // see if there is a default FactoryBean
    BeanFactory factory;

    if (factoryKey == null) {
      if (!canUseDefaultBeanFactory)
        throw new IllegalArgumentException(
            "a non-null factoryKey needs to be specified as there are more then one factoryKeys available ");
      factory = defaultFactory;
    }
    else {
      factory = (BeanFactory) beanFactories.get(factoryKey);
      if (factory == null)
        throw new IllegalArgumentException("there is no beanFactory under key " + factoryKey);
    }

    // increment counter
    synchronized (referenceCounter) {
      Integer counter = (Integer) referenceCounter.get(factory);
      referenceCounter.put(factory, new Integer(counter.intValue() + 1));
    }

    final BeanFactory finalFactory = factory;

    // simple implementation
    return new BeanFactoryReference() {
      private BeanFactory fact = finalFactory;

View Full Code Here

        servlet.init(servletConfig);

        Registry hiveMindRegistry = (Registry) servletContext.getAttribute("org.apache.tapestry.Registry:servlet");
        assertNotNull("HiveMind registry is not available in servlet context", hiveMindRegistry);

        BeanFactory beanFactory = (BeanFactory) hiveMindRegistry.getService("hivemind.lib.DefaultSpringBeanFactory", BeanFactory.class);
        String name = (String) beanFactory.getBean("name", String.class);
        assertNotNull(name);
        assertEquals("Steven Devijver", name);
    }
View Full Code Here

    {
      return beanFactory.getBeanDefinition(name);
    }
    else
    {
      BeanFactory parent = beanFactory.getParentBeanFactory();
      if ((parent != null) && (parent instanceof ConfigurableListableBeanFactory))
      {
        return getBeanDefinition((ConfigurableListableBeanFactory)parent, name);
      }
      else
View Full Code Here

        SpringBeanFactorySource s = p.getBeanFactorySource();

        if (s == null)
            s = _defaultBeanFactorySource;

        BeanFactory f = s.getBeanFactory();

        return f.getBean(beanName, serviceInterface);
    }
View Full Code Here

    {
      return beanFactory.getBeanDefinition(name);
    }
    else
    {
      BeanFactory parent = beanFactory.getParentBeanFactory();
      if ((parent != null) && (parent instanceof ConfigurableListableBeanFactory))
      {
        return getBeanDefinition((ConfigurableListableBeanFactory)parent, name);
      }
      else
View Full Code Here

    public void testDefaultFactory()
    {
        SpringLookupFactory lf = new SpringLookupFactory();

        BeanFactory beanFactory = (BeanFactory) newMock(BeanFactory.class);

        ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) newMock(ServiceImplementationFactoryParameters.class);

        lf.setDefaultBeanFactory(beanFactory);

        SpringBeanParameter param = buildParameter("fred", null);

        Object fred = new Object();

        beanFactory.getBean("fred", List.class);
        setReturnValue(beanFactory, fred);

        fp.getFirstParameter();
        setReturnValue(fp, param);
View Full Code Here

    }

    public void testBeanSpecificFactory()
    {
        SpringLookupFactory lf = new SpringLookupFactory();
        BeanFactory beanFactory = (BeanFactory) newMock(BeanFactory.class);

        ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) newMock(ServiceImplementationFactoryParameters.class);

        SpringBeanParameter param = buildParameter("fred", beanFactory);

        Object fred = new Object();

        beanFactory.getBean("fred", List.class);
        setReturnValue(beanFactory, fred);

        fp.getFirstParameter();
        setReturnValue(fp, param);
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.BeanFactory

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.