Package org.springframework.beans.factory

Examples of org.springframework.beans.factory.ObjectFactory


    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


    return ObjectFactory.class;
  }

  @Override
  protected Object createInstance() {
    return new ObjectFactory() {
      public Object getObject() throws BeansException {
        return getTargetBean(targetBeanName);
      }
    };
  }
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 = this.singletonFactories.get(beanName);
          if (singletonFactory != null) {
            singletonObject = singletonFactory.getObject();
            this.earlySingletonObjects.put(beanName, singletonObject);
            this.singletonFactories.remove(beanName);
          }
        }
      }
View Full Code Here

  public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory) {
    beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope());
    beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(false));
    beanFactory.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, new SessionScope(true));

    beanFactory.registerResolvableDependency(ServletRequest.class, new ObjectFactory() {
      public Object getObject() {
        RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes();
        if (!(requestAttr instanceof ServletRequestAttributes)) {
          throw new IllegalStateException("Current request is not a servlet request");
        }
        return ((ServletRequestAttributes) requestAttr).getRequest();
      }
    });
    beanFactory.registerResolvableDependency(HttpSession.class, new ObjectFactory() {
      public Object getObject() {
        RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes();
        if (!(requestAttr instanceof ServletRequestAttributes)) {
          throw new IllegalStateException("Current request is not a servlet request");
        }
View Full Code Here

      final RootBeanDefinition mbd = getMergedBeanDefinition(beanName, false);
      checkMergedBeanDefinition(mbd, beanName, args);

      // 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, 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, 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 {
                Object bean = createBean(beanName, mbd, args);
                if (requiresDestruction(bean, mbd)) {
View Full Code Here

    beanFactory.addBeanPostProcessor(new BootstrapContextAwareProcessor(this.bootstrapContext));
    beanFactory.ignoreDependencyInterface(BootstrapContextAware.class);
    beanFactory.registerResolvableDependency(BootstrapContext.class, this.bootstrapContext);

    // JCA WorkManager resolved lazily - may not be available.
    beanFactory.registerResolvableDependency(WorkManager.class, new ObjectFactory() {
      public Object getObject() {
        return bootstrapContext.getWorkManager();
      }
    });
  }
View Full Code Here

  static void registerPortletApplicationScopes(ConfigurableListableBeanFactory beanFactory) {
    beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope());
    beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(false));
    beanFactory.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, new SessionScope(true));

    beanFactory.registerResolvableDependency(PortletRequest.class, new ObjectFactory() {
      public Object getObject() {
        RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes();
        if (!(requestAttr instanceof PortletRequestAttributes)) {
          throw new IllegalStateException("Current request is not a portlet request");
        }
        return ((PortletRequestAttributes) requestAttr).getRequest();
      }
    });
    beanFactory.registerResolvableDependency(PortletSession.class, new ObjectFactory() {
      public Object getObject() {
        RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes();
        if (!(requestAttr instanceof PortletRequestAttributes)) {
          throw new IllegalStateException("Current request is not a portlet request");
        }
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

        }
      }

      // 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

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.