Package org.springframework.beans.factory

Examples of org.springframework.beans.factory.FactoryBean


      for (Iterator it = this.beanDefinitionNames.iterator(); it.hasNext();) {
        String beanName = (String) it.next();
        RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);
        if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) {
          if (isFactoryBean(beanName)) {
            FactoryBean factory = (FactoryBean) getBean(FACTORY_BEAN_PREFIX + beanName);
            if (factory instanceof SmartFactoryBean && ((SmartFactoryBean) factory).isEagerInit()) {
              getBean(beanName);
            }
          }
          else {
View Full Code Here


      // Is bean a FactoryBean?
      if (beanInstance instanceof FactoryBean && !isFactoryType) {
        if (includeFactoryBeans) {
          // Match object created by FactoryBean.
          FactoryBean factory = (FactoryBean) beanInstance;
          Class objectType = factory.getObjectType();
          if ((includeNonSingletons || factory.isSingleton()) &&
              objectType != null && type.isAssignableFrom(objectType)) {
            matches.put(beanName, getBean(beanName));
          }
        }
      }
View Full Code Here

      if (mbd.isSingleton()) {
        if (isFactoryBean(beanName, mbd)) {
          if (BeanFactoryUtils.isFactoryDereference(name)) {
            return true;
          }
          FactoryBean factoryBean = (FactoryBean) getBean(FACTORY_BEAN_PREFIX + beanName);
          return factoryBean.isSingleton();
        }
        else {
          return !BeanFactoryUtils.isFactoryDereference(name);
        }
      }
View Full Code Here

      // However, FactoryBean may still produce a prototype object...
      if (BeanFactoryUtils.isFactoryDereference(name)) {
        return false;
      }
      if (isFactoryBean(beanName, mbd)) {
        FactoryBean factoryBean = (FactoryBean) getBean(FACTORY_BEAN_PREFIX + beanName);
        return ((factoryBean instanceof SmartFactoryBean && ((SmartFactoryBean) factoryBean).isPrototype()) ||
            !factoryBean.isSingleton());
      }
      else {
        return false;
      }
    }
View Full Code Here

  protected Class getTypeForFactoryBean(String beanName, RootBeanDefinition mbd) {
    if (!mbd.isSingleton()) {
      return null;
    }
    try {
      FactoryBean factoryBean =
          (FactoryBean) doGetBean(FACTORY_BEAN_PREFIX + beanName, FactoryBean.class, null, true);
      return getTypeForFactoryBean(factoryBean);
    }
    catch (BeanCreationException ex) {
      // Can only happen when getting a FactoryBean.
View Full Code Here

    if (mbd == null) {
      object = getCachedObjectForFactoryBean(beanName);
    }
    if (object == null) {
      // Return bean instance from factory.
      FactoryBean factory = (FactoryBean) beanInstance;
      // Caches object obtained from FactoryBean if it is a singleton.
      if (mbd == null && containsBeanDefinition(beanName)) {
        mbd = getMergedLocalBeanDefinition(beanName);
      }
      boolean synthetic = (mbd != null && mbd.isSynthetic());
View Full Code Here

       
        ClassLoader classLoader = MBeanServerFactoryBean.class.getClassLoader();
        try {
           
            // Try to use the xbean tiger version first...
            FactoryBean fb = (FactoryBean) classLoader.loadClass("org.apache.xbean.tiger.MBeanServerFactoryBean").newInstance();
            return fb.getObject();
           
        } catch (Throwable e) {
           
            // Fallback to using the spring factory bean then
            FactoryBean fb = (FactoryBean) classLoader.loadClass("org.springframework.jmx.support.MBeanServerFactoryBean").newInstance();
            ((InitializingBean)fb).afterPropertiesSet();
            return fb.getObject();
           
        }
    }
View Full Code Here

      ServiceReference s = hasServiceProperty(pd);
      if (s != null && !pvs.contains(pd.getName())) {
        try {
          if (logger.isDebugEnabled())
            logger.debug("Processing annotation [" + s + "] for [" + beanName + "." + pd.getName() + "]");
          FactoryBean importer = getServiceImporter(s, pd.getWriteMethod(), beanName);
          // BPPs are created in stageOne(), even though they are run in stageTwo(). This check means that
          // the call to getObject() will not fail with ServiceUnavailable. This is safe to do because
          // ServiceReferenceDependencyBeanFactoryPostProcessor will ensure that mandatory services are
          // satisfied before stageTwo() is run.
          if (bean instanceof BeanPostProcessor) {
            ImporterCallAdapter.setCardinality(importer, Cardinality.C_0__1);
          }
          newprops.addPropertyValue(pd.getName(), importer.getObject());
        }
        catch (Exception e) {
          throw new FatalBeanException("Could not create service reference", e);
        }
      }
View Full Code Here

    @Inject Environment env;

    @Bean
    public FactoryBean testBean() {
      final String name = env.getProperty("testbean.name");
      return new FactoryBean() {
        @Override
        public Object getObject() {
          return new TestBean(name);
        }
        @Override
View Full Code Here

   * FactoryBean. If the FactoryBean instance itself is not kept as singleton,
   * it will be fully created to check the type of its exposed object.
   */
  @Override
  protected Class getTypeForFactoryBean(String beanName, RootBeanDefinition mbd) {
    FactoryBean fb = (mbd.isSingleton() ?
        getSingletonFactoryBeanForTypeCheck(beanName, mbd) :
        getNonSingletonFactoryBeanForTypeCheck(beanName, mbd));

    if (fb != null) {
      // Try to obtain the FactoryBean's object type from this early stage of the instance.
View Full Code Here

TOP

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

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.