Package org.springframework.beans.factory.support

Examples of org.springframework.beans.factory.support.GenericBeanDefinition


    // We need to override just this bean definition, as it may reference other beans
    // and we're happy to take the parent's definition for those.
    // Always use prototype scope if demanded.
    BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName);
    GenericBeanDefinition bdCopy = new GenericBeanDefinition(bd);
    if (isPrototypeBased()) {
      bdCopy.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    }
    this.internalBeanFactory.registerBeanDefinition(beanName, bdCopy);

    // Complete configuring the PrototypeTargetSource.
    targetSource.setTargetBeanName(beanName);
View Full Code Here


   * Register a singleton bean with the underlying bean factory.
   * <p>For more advanced needs, register with the underlying BeanFactory directly.
   * @see #getDefaultListableBeanFactory
   */
  public void registerSingleton(String name, Class clazz) throws BeansException {
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClass(clazz);
    getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
  }
View Full Code Here

   * Register a singleton bean with the underlying bean factory.
   * <p>For more advanced needs, register with the underlying BeanFactory directly.
   * @see #getDefaultListableBeanFactory
   */
  public void registerSingleton(String name, Class clazz, MutablePropertyValues pvs) throws BeansException {
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClass(clazz);
    bd.setPropertyValues(pvs);
    getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
  }
View Full Code Here

   * Register a prototype bean with the underlying bean factory.
   * <p>For more advanced needs, register with the underlying BeanFactory directly.
   * @see #getDefaultListableBeanFactory
   */
  public void registerPrototype(String name, Class clazz) throws BeansException {
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setScope(GenericBeanDefinition.SCOPE_PROTOTYPE);
    bd.setBeanClass(clazz);
    getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
  }
View Full Code Here

   * Register a prototype bean with the underlying bean factory.
   * <p>For more advanced needs, register with the underlying BeanFactory directly.
   * @see #getDefaultListableBeanFactory
   */
  public void registerPrototype(String name, Class clazz, MutablePropertyValues pvs) throws BeansException {
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setScope(GenericBeanDefinition.SCOPE_PROTOTYPE);
    bd.setBeanClass(clazz);
    bd.setPropertyValues(pvs);
    getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
  }
View Full Code Here

    // Set up infrastructure.
    LangNamespaceUtils.registerScriptFactoryPostProcessorIfNecessary(parserContext.getRegistry());

    // Create script factory bean definition.
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClassName(this.scriptFactoryClassName);
    bd.setSource(parserContext.extractSource(element));

    // Determine bean scope.
    String scope = element.getAttribute(SCOPE_ATTRIBUTE);
    if (StringUtils.hasLength(scope)) {
      bd.setScope(scope);
    }

    // Determine autowire mode.
    String autowire = element.getAttribute(AUTOWIRE_ATTRIBUTE);
    int autowireMode = parserContext.getDelegate().getAutowireMode(autowire);
    // Only "byType" and "byName" supported, but maybe other default inherited...
    if (autowireMode == GenericBeanDefinition.AUTOWIRE_AUTODETECT) {
      autowireMode = GenericBeanDefinition.AUTOWIRE_BY_TYPE;
    }
    else if (autowireMode == GenericBeanDefinition.AUTOWIRE_CONSTRUCTOR) {
      autowireMode = GenericBeanDefinition.AUTOWIRE_NO;
    }
    bd.setAutowireMode(autowireMode);

    // Determine dependency check setting.
    String dependencyCheck = element.getAttribute(DEPENDENCY_CHECK_ATTRIBUTE);
    bd.setDependencyCheck(parserContext.getDelegate().getDependencyCheck(dependencyCheck));

    // Retrieve the defaults for bean definitions within this parser context
    BeanDefinitionDefaults beanDefinitionDefaults =
        parserContext.getDelegate().getBeanDefinitionDefaults();

    // Determine init method and destroy method.
    String initMethod = element.getAttribute(INIT_METHOD_ATTRIBUTE);
    if (StringUtils.hasLength(initMethod)) {
      bd.setInitMethodName(initMethod);
    }
    else if (beanDefinitionDefaults.getInitMethodName() != null) {
      bd.setInitMethodName(beanDefinitionDefaults.getInitMethodName());
    }

    String destroyMethod = element.getAttribute(DESTROY_METHOD_ATTRIBUTE);
    if (StringUtils.hasLength(destroyMethod)) {
      bd.setDestroyMethodName(destroyMethod);
    }
    else if (beanDefinitionDefaults.getDestroyMethodName() != null) {
      bd.setDestroyMethodName(beanDefinitionDefaults.getDestroyMethodName());
    }

    // Attach any refresh metadata.
    String refreshCheckDelay = element.getAttribute(REFRESH_CHECK_DELAY_ATTRIBUTE);
    if (StringUtils.hasText(refreshCheckDelay)) {
      bd.setAttribute(
          ScriptFactoryPostProcessor.REFRESH_CHECK_DELAY_ATTRIBUTE, new Long(refreshCheckDelay));
    }

    // Add constructor arguments.
    ConstructorArgumentValues cav = bd.getConstructorArgumentValues();
    int constructorArgNum = 0;
    cav.addIndexedArgumentValue(constructorArgNum++, value);
    if (element.hasAttribute(SCRIPT_INTERFACES_ATTRIBUTE)) {
      cav.addIndexedArgumentValue(constructorArgNum++, element.getAttribute(SCRIPT_INTERFACES_ATTRIBUTE));
    }
View Full Code Here

   * @param bd the full script bean definition
   * @return the extracted ScriptFactory bean definition
   * @see org.springframework.scripting.ScriptFactory
   */
  protected BeanDefinition createScriptFactoryBeanDefinition(BeanDefinition bd) {
    GenericBeanDefinition scriptBd = new GenericBeanDefinition();
    scriptBd.setBeanClassName(bd.getBeanClassName());
    scriptBd.getConstructorArgumentValues().addArgumentValues(bd.getConstructorArgumentValues());
    return scriptBd;
  }
View Full Code Here

   * @see org.springframework.scripting.ScriptFactory#getScriptedObject
   */
  protected BeanDefinition createScriptedObjectBeanDefinition(
      BeanDefinition bd, String scriptFactoryBeanName, ScriptSource scriptSource, Class[] interfaces) {

    GenericBeanDefinition objectBd = new GenericBeanDefinition(bd);
    objectBd.setFactoryBeanName(scriptFactoryBeanName);
    objectBd.setFactoryMethodName("getScriptedObject");
    objectBd.getConstructorArgumentValues().clear();
    objectBd.getConstructorArgumentValues().addIndexedArgumentValue(0, scriptSource);
    objectBd.getConstructorArgumentValues().addIndexedArgumentValue(1, interfaces);
    return objectBd;
  }
View Full Code Here

  public void testIncompleteBeanDefinition() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    bf.registerBeanDefinition("testBean", new GenericBeanDefinition());
    try {
      bf.getBean("testBean");
    }
    catch (BeanCreationException ex) {
      assertTrue(ex.getRootCause() instanceof IllegalStateException);
View Full Code Here

              .getChildren();

          for (int k = 0; k < beanElements.length; k++) {
            IConfigurationElement beanElement = beanElements[k];

            GenericBeanDefinition beanDefinition = new GenericBeanDefinition();

            // bean id
            String beanId = beanElement.getAttribute("id");

            // bean class
            String beanClassName = beanElement
                .getAttribute("class");
            beanDefinition.setBeanClass(resolveBeanClass(
                beanElement, beanClassName));

            if (log.isDebugEnabled()) {
              log.debug("found bean for context [" + contextId
                  + "]: [id=" + beanId + ";class="
                  + beanClassName + "]");
            }

            // scope
            String scope = beanElement.getAttribute("scope");
            if (scope != null) {
              beanDefinition.setScope(scope);
            }

            if (log.isDebugEnabled()) {
              log.debug("scope: [" + scope + "]");
            }

            // abstract
            String isAbstract = beanElement
                .getAttribute("abstract");
            if (isAbstract != null) {
              beanDefinition.setAbstract(Boolean
                  .parseBoolean(isAbstract));
            }

            if (log.isDebugEnabled()) {
              log.debug("abstract: [" + isAbstract + "]");
            }

            // parent
            String parentName = beanElement.getAttribute("parent");
            if (parentName != null) {
              beanDefinition.setParentName(parentName);
            }

            if (log.isDebugEnabled()) {
              log.debug("parent: [" + parentName + "]");
            }

            // lazy-init
            String isLazyInit = beanElement
                .getAttribute("lazy-init");
            if (isLazyInit != null) {
              beanDefinition.setLazyInit(Boolean
                  .parseBoolean(isLazyInit));
            }

            if (log.isDebugEnabled()) {
              log.debug("lazy-init: [" + isLazyInit + "]");
            }

            // autowire
            String autowireModeString = beanElement
                .getAttribute("autowire");
            if (autowireModeString != null) {
              beanDefinition
                  .setAutowireMode(resolveAutowireMode(autowireModeString));
            }

            if (log.isDebugEnabled()) {
              log.debug("autowire: [" + autowireModeString + "]");
            }

            // autowire candidate
            String autowireCandidate = beanElement
                .getAttribute("autowire-candidate");
            if (autowireCandidate != null) {
              beanDefinition.setAutowireCandidate(Boolean
                  .parseBoolean(autowireCandidate));
            }

            if (log.isDebugEnabled()) {
              log.debug("autowire-candidate: ["
                  + autowireCandidate + "]");
            }

            // primary
            String isPrimary = beanElement.getAttribute("primary");
            if (isPrimary != null) {
              beanDefinition.setPrimary(Boolean
                  .parseBoolean(isPrimary));
            }

            if (log.isDebugEnabled()) {
              log.debug("primary: [" + isPrimary + "]");
            }

            // init-method
            String initMethod = beanElement
                .getAttribute("init-method");
            if (initMethod != null) {
              beanDefinition.setInitMethodName(initMethod);
            }

            if (log.isDebugEnabled()) {
              log.debug("init-method: [" + initMethod + "]");
            }

            // destroy-method
            String destroyMethod = beanElement
                .getAttribute("destroy-method");
            if (destroyMethod != null) {
              beanDefinition.setDestroyMethodName(destroyMethod);
            }

            if (log.isDebugEnabled()) {
              log
                  .debug("destroy-method: [" + destroyMethod
                      + "]");
            }

            // factory-method
            String factoryMethod = beanElement
                .getAttribute("factory-method");
            if (factoryMethod != null) {
              beanDefinition
                  .setFactoryMethodName("factory-method");
            }

            if (log.isDebugEnabled()) {
              log
                  .debug("factory-method: [" + factoryMethod
                      + "]");
            }

            // factory-bean
            String factoryBean = beanElement
                .getAttribute("factory-bean");
            if (factoryBean != null) {
              beanDefinition.setFactoryBeanName(factoryBean);
            }

            if (log.isDebugEnabled()) {
              log.debug("factory-bean: [" + factoryBean + "]");
            }

            // constructor values
            if (log.isDebugEnabled()) {
              log.debug("resolving constructor values");
            }

            ConstructorArgumentValues constructorArgumentValues = resolveConstructorValues(beanElement);
            if (!constructorArgumentValues.isEmpty()) {
              beanDefinition
                  .setConstructorArgumentValues(constructorArgumentValues);
            } else if (log.isDebugEnabled()) {
              log.debug("no constructor values found");
            }

            // property values
            if (log.isDebugEnabled()) {
              log.debug("resolving property values");
            }

            MutablePropertyValues propertyValues = resolvePropertyValues(beanElement);
            if (propertyValues.size() > 0) {
              beanDefinition.setPropertyValues(propertyValues);
            } else if (log.isDebugEnabled()) {
              log.debug("no property values found");
            }

            if (beanDefinition.getBeanClass() == null) {
              if (log.isWarnEnabled()) {
                log
                    .warn("bean class of bean ["
                        + beanId
                        + "] could not be resolved; it will be ignored");
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.support.GenericBeanDefinition

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.