Package org.springframework.beans.factory

Examples of org.springframework.beans.factory.ObjectFactory


     */
    @Test
    public void testCrossContextScopeGet() {
        ServletContextScope scs = getServletContextScope(false);
       
        String value = (String)scs.get(CONTEXT_KEY, new ObjectFactory() {
            public Object getObject() throws BeansException {
                return SIMPLE_FORM_CONTEXT_VALUE;
            }
        });
       
        String expected = SIMPLE_FORM_CONTEXT_VALUE;

        assertNotNull("Simple form context value is null.", value);
        assertEquals("Simple form context value string should be '" + expected + "'.", expected, value);

        // try again, but fail if the factory is called again.
        value = (String)scs.get(CONTEXT_KEY, new ObjectFactory() {
            public Object getObject() throws BeansException {
                fail("Bean should have been retrieved from ServletContext and not created again from the ObjectFactory.");
               
                return SIMPLE_FORM_CONTEXT_VALUE;
            }
View Full Code Here


    Object singletonObject = this.singletonObjects.get(beanName);
    if (singletonObject == null) {
      synchronized (this.singletonObjects) {
        singletonObject = this.earlySingletonObjects.get(beanName);
        if (singletonObject == null && allowEarlyReference) {
          ObjectFactory singletonFactory = (ObjectFactory) this.singletonFactories.get(beanName);
          if (singletonFactory != null) {
            singletonObject = singletonFactory.getObject();
            this.earlySingletonObjects.put(beanName, singletonObject);
            this.singletonFactories.remove(beanName);
          }
        }
      }
View Full Code Here

    if (earlySingletonExposure) {
      if (logger.isDebugEnabled()) {
        logger.debug("Eagerly caching bean '" + beanName +
            "' to allow for resolving potential circular references");
      }
      addSingletonFactory(beanName, new ObjectFactory() {
        public Object getObject() throws BeansException {
          return getEarlyBeanReference(beanName, mbd, bean);
        }
      });
    }
View Full Code Here

  public Class getObjectType() {
    return ObjectFactory.class;
  }

  protected Object createInstance() {
    return new ObjectFactory() {
      public Object getObject() throws BeansException {
        return getTargetBean(targetBeanName);
      }
    };
  }
View Full Code Here

        }
      }

      // Create bean instance.
      if (mbd.isSingleton()) {
        sharedInstance = getSingleton(beanName, new ObjectFactory() {
          public Object getObject() throws BeansException {
            try {
              return createBean(beanName, mbd, args);
            }
            catch (BeansException ex) {
              // Explicitly remove instance from singleton cache: It might have been put there
              // eagerly by the creation process, to allow for circular reference resolution.
              // Also remove any beans that received a temporary reference to the bean.
              destroySingleton(beanName);
              throw ex;
            }
          }
        });
        bean = getObjectForBeanInstance(sharedInstance, name, beanName, mbd);
      }

      else if (mbd.isPrototype()) {
        // It's a prototype -> create a new instance.
        Object prototypeInstance = null;
        try {
          beforePrototypeCreation(beanName);
          prototypeInstance = createBean(beanName, mbd, args);
        }
        finally {
          afterPrototypeCreation(beanName);
        }
        bean = getObjectForBeanInstance(prototypeInstance, name, beanName, mbd);
      }

      else {
        String scopeName = mbd.getScope();
        final Scope scope = (Scope) this.scopes.get(scopeName);
        if (scope == null) {
          throw new IllegalStateException("No Scope registered for scope '" + scopeName + "'");
        }
        try {
          Object scopedInstance = scope.get(beanName, new ObjectFactory() {
            public Object getObject() throws BeansException {
              beforePrototypeCreation(beanName);
              try {
                return createBean(beanName, mbd, args);
              }
View Full Code Here

    }

    @Override
    protected Object instantiateIoCBean() throws Exception
    {
        ObjectFactory objectFactory = getObjectFactory();
        if (objectFactory == null)
        {
            return beanfactory.getBean(springBeanName);
        }
        setObjectFactory(null);
        return objectFactory.getObject();
    }
View Full Code Here

    if (bean instanceof FactoryBean && !FactoryBean.class.isAssignableFrom(component.getBeanClass()))
        {
      return bean;
    }
    // Wrap our bean instance in an object factory for the SpringComponent to use
    SpringComponent.setObjectFactory(new ObjectFactory() {
      public Object getObject() throws BeansException
         {
        return bean;
      }
    });
View Full Code Here

    }

    @Override
    protected Object instantiateIoCBean() throws Exception
    {
        ObjectFactory objectFactory = getObjectFactory();
        if (objectFactory == null)
        {
            return beanfactory.getBean(springBeanName);
        }
        setObjectFactory(null);
        return objectFactory.getObject();
    }
View Full Code Here

    if (earlySingletonExposure) {
      if (logger.isDebugEnabled()) {
        logger.debug("Eagerly caching bean '" + beanName +
            "' to allow for resolving potential circular references");
      }
      addSingletonFactory(beanName, new ObjectFactory() {
        public Object getObject() throws BeansException {
          return getEarlyBeanReference(beanName, mbd, bean);
        }
      });
    }
View Full Code Here

        }
      }

      // Create bean instance.
      if (mbd.isSingleton()) {
        sharedInstance = getSingleton(beanName, new ObjectFactory() {
          public Object getObject() throws BeansException {
            try {
              return createBean(beanName, mbd, args);
            }
            catch (BeansException ex) {
              // Explicitly remove instance from singleton cache: It might have been put there
              // eagerly by the creation process, to allow for circular reference resolution.
              // Also remove any beans that received a temporary reference to the bean.
              destroySingleton(beanName);
              throw ex;
            }
          }
        });
        bean = getObjectForBeanInstance(sharedInstance, name, beanName, mbd);
      }

      else if (mbd.isPrototype()) {
        // It's a prototype -> create a new instance.
        Object prototypeInstance = null;
        try {
          beforePrototypeCreation(beanName);
          prototypeInstance = createBean(beanName, mbd, args);
        }
        finally {
          afterPrototypeCreation(beanName);
        }
        bean = getObjectForBeanInstance(prototypeInstance, name, beanName, mbd);
      }

      else {
        String scopeName = mbd.getScope();
        final Scope scope = this.scopes.get(scopeName);
        if (scope == null) {
          throw new IllegalStateException("No Scope registered for scope '" + scopeName + "'");
        }
        try {
          Object scopedInstance = scope.get(beanName, new ObjectFactory() {
            public Object getObject() throws BeansException {
              beforePrototypeCreation(beanName);
              try {
                return createBean(beanName, mbd, args);
              }
View Full Code Here

TOP

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

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.