Package org.springframework.beans.factory.config

Examples of org.springframework.beans.factory.config.ConfigurableBeanFactory


      resource = factory.getBean(name, element.lookupType);
      autowiredBeanNames = Collections.singleton(name);
    }

    if (factory instanceof ConfigurableBeanFactory) {
      ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) factory;
      for (String autowiredBeanName : autowiredBeanNames) {
        beanFactory.registerDependentBean(autowiredBeanName, requestingBeanName);
      }
    }

    return resource;
  }
View Full Code Here


  public void setBeanFactory(BeanFactory beanFactory) {
    if (!(beanFactory instanceof ConfigurableBeanFactory)) {
      throw new IllegalStateException("Not running in a ConfigurableBeanFactory: " + beanFactory);
    }
    ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory;

    this.scopedTargetSource.setBeanFactory(beanFactory);

    ProxyFactory pf = new ProxyFactory();
    pf.copyFrom(this);
    pf.setTargetSource(this.scopedTargetSource);

    Class beanType = beanFactory.getType(this.targetBeanName);
    if (beanType == null) {
      throw new IllegalStateException("Cannot create scoped proxy for bean '" + this.targetBeanName +
          "': Target type could not be determined at the time of proxy creation.");
    }
    if (!isProxyTargetClass() || beanType.isInterface() || Modifier.isPrivate(beanType.getModifiers())) {
      pf.setInterfaces(ClassUtils.getAllInterfacesForClass(beanType, cbf.getBeanClassLoader()));
    }

    // Add an introduction that implements only the methods on ScopedObject.
    ScopedObject scopedObject = new DefaultScopedObject(cbf, this.scopedTargetSource.getTargetBeanName());
    pf.addAdvice(new DelegatingIntroductionInterceptor(scopedObject));

    // Add the AopInfrastructureBean marker to indicate that the scoped proxy
    // itself is not subject to auto-proxying! Only its target bean is.
    pf.addInterface(AopInfrastructureBean.class);

    this.proxy = pf.getProxy(cbf.getBeanClassLoader());
  }
View Full Code Here

  /**
   * Resolves the specified interceptor names to Advisor objects.
   * @see #setInterceptorNames
   */
  private Advisor[] resolveInterceptorNames() {
    ConfigurableBeanFactory cbf = (this.beanFactory instanceof ConfigurableBeanFactory) ?
        (ConfigurableBeanFactory) this.beanFactory : null;
    List<Advisor> advisors = new ArrayList<Advisor>();
    for (String beanName : this.interceptorNames) {
      if (cbf == null || !cbf.isCurrentlyInCreation(beanName)) {
        Object next = this.beanFactory.getBean(beanName);
        advisors.add(this.advisorAdapterRegistry.wrap(next));
      }
    }
    return advisors.toArray(new Advisor[advisors.size()]);
View Full Code Here

  /**
   * Resolves the specified interceptor names to Advisor objects.
   * @see #setInterceptorNames
   */
  private Advisor[] resolveInterceptorNames() {
    ConfigurableBeanFactory cbf =
        (this.beanFactory instanceof ConfigurableBeanFactory ? (ConfigurableBeanFactory) this.beanFactory : null);
    List advisors = new ArrayList();
    for (int i = 0; i < this.interceptorNames.length; i++) {
      String beanName = this.interceptorNames[i];
      if (cbf == null || !cbf.isCurrentlyInCreation(beanName)) {
        Object next = this.beanFactory.getBean(beanName);
        advisors.add(this.advisorAdapterRegistry.wrap(next));
      }
    }
    return (Advisor[]) advisors.toArray(new Advisor[advisors.size()]);
View Full Code Here

      resource = factory.getBean(name, element.lookupType);
      autowiredBeanNames = Collections.singleton(name);
    }

    if (factory instanceof ConfigurableBeanFactory) {
      ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) factory;
      for (String autowiredBeanName : autowiredBeanNames) {
        beanFactory.registerDependentBean(autowiredBeanName, requestingBeanName);
      }
    }

    return resource;
  }
View Full Code Here

  /**
   * Resolves the specified interceptor names to Advisor objects.
   * @see #setInterceptorNames
   */
  private Advisor[] resolveInterceptorNames() {
    ConfigurableBeanFactory cbf =
        (this.beanFactory instanceof ConfigurableBeanFactory ? (ConfigurableBeanFactory) this.beanFactory : null);
    List advisors = new ArrayList();
    for (int i = 0; i < this.interceptorNames.length; i++) {
      String beanName = this.interceptorNames[i];
      if (cbf == null || !cbf.isCurrentlyInCreation(beanName)) {
        Object next = this.beanFactory.getBean(beanName);
        advisors.add(this.advisorAdapterRegistry.wrap(next));
      }
    }
    return (Advisor[]) advisors.toArray(new Advisor[advisors.size()]);
View Full Code Here

  public void setBeanFactory(BeanFactory beanFactory) {
    if (!(beanFactory instanceof ConfigurableBeanFactory)) {
      throw new IllegalStateException("Not running in a ConfigurableBeanFactory: " + beanFactory);
    }
    ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory;

    this.scopedTargetSource.setBeanFactory(beanFactory);

    ProxyFactory pf = new ProxyFactory();
    pf.copyFrom(this);
    pf.setTargetSource(this.scopedTargetSource);

    Class beanType = beanFactory.getType(this.targetBeanName);
    if (beanType == null) {
      throw new IllegalStateException("Cannot create scoped proxy for bean '" + this.targetBeanName +
          "': Target type could not be determined at the time of proxy creation.");
    }
    if (!isProxyTargetClass() || beanType.isInterface() || Modifier.isPrivate(beanType.getModifiers())) {
      pf.setInterfaces(ClassUtils.getAllInterfacesForClass(beanType));
    }

    // Add an introduction that implements only the methods on ScopedObject.
    ScopedObject scopedObject = new DefaultScopedObject(cbf, this.scopedTargetSource.getTargetBeanName());
    pf.addAdvice(new DelegatingIntroductionInterceptor(scopedObject));

    // Add the AopInfrastructureBean marker to indicate that the scoped proxy
    // itself is not subject to auto-proxying! Only its target bean is.
    pf.addInterface(AopInfrastructureBean.class);

    this.proxy = pf.getProxy(cbf.getBeanClassLoader());
  }
View Full Code Here

  private void bindComponent(Component comp) {
    if (!Objects.equals(comp.getId(), comp.getUuid())) { //with user specified id
      final Execution exec = Executions.getCurrent();
      if (exec != null) {
        final ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) SpringUtil.getApplicationContext();
        final ConfigurableBeanFactory factory = ctx.getBeanFactory();
        final String fid = "&"+comp.getId();
        if (factory.containsBean(fid)) {
          final Page page = ((ExecutionCtrl)exec).getCurrentPage();
          final Object self = page.hasAttribute("self") ?
              page.getAttribute("self", false) : null;
          try {
            page.setAttribute("self", comp);
            //trigger component binding
            final Object proxy = SpringUtil.getBean(comp.getId(), Component.class);
            if (proxy != null) {
              final BeanDefinition bd = factory.getMergedBeanDefinition(fid);
              final MutablePropertyValues mpv = bd.getPropertyValues();
              final PropertyValue pv = mpv.getPropertyValue("controllerIds");
              final Set controllerIds = (pv != null) ? (Set) pv.getValue() : null;
              if (controllerIds != null) {
                bindControllers(comp, controllerIds, fid);
View Full Code Here

  }


  private static void testBadTargetBeanName(final String badTargetBeanName) {
    MockControl mock = MockControl.createControl(ConfigurableBeanFactory.class);
    final ConfigurableBeanFactory factory = (ConfigurableBeanFactory) mock.getMock();
    mock.replay();

    new AssertThrows(IllegalArgumentException.class) {
      public void test() throws Exception {
        new DefaultScopedObject(factory, badTargetBeanName);
View Full Code Here

        if (!(beanFactory instanceof ConfigurableBeanFactory))
        {
            throw new IllegalStateException("Not running in a ConfigurableBeanFactory: " + beanFactory);
        }
        ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory;

        ScopedBeanTargetSource scopedTargetSource = new ScopedBeanTargetSource(
                scope, conversationName, targetBeanName, objectFactory, beanFactory);

        ProxyFactory pf = new ProxyFactory();
        pf.setProxyTargetClass(true);
        pf.setTargetSource(scopedTargetSource);

        Class beanType = beanFactory.getType(targetBeanName);
        if (beanType == null) {
            throw new IllegalStateException("Cannot create scoped proxy for bean '" + targetBeanName +
                    "': Target type could not be determined at the time of proxy creation.");
        }

        // Add an introduction that implements only the methods on ScopedObject.
        // Not sure if this is useful...
        ScopedObject scopedObject = new DefaultScopedObject(cbf, scopedTargetSource.getTargetBeanName());
        pf.addAdvice(new DelegatingIntroductionInterceptor(scopedObject));

        // Add the AopInfrastructureBean marker to indicate that the scoped proxy
        // itself is not subject to auto-proxying! Only its target bean is.
        // Not sure if this is needed....
        pf.addInterface(AopInfrastructureBean.class);

        return pf.getProxy(cbf.getBeanClassLoader());
    }
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.config.ConfigurableBeanFactory

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.