Package org.springframework.beans.factory.config

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


    }
  }

  public void testAutowiredFieldResolvesWithBaseQualifierAndDefaultValue() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class));
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
View Full Code Here


    assertEquals(MARK, bean.getPerson().getName());
  }

  public void testAutowiredFieldResolvesWithBaseQualifierAndNonDefaultValue() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue("the real juergen");
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    person1.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue("juergen imposter");
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "not really juergen"));
    context.registerBeanDefinition("juergen1", person1);
    context.registerBeanDefinition("juergen2", person2);
    context.registerBeanDefinition("autowired",
View Full Code Here

    assertEquals("the real juergen", bean.getPerson().getName());
  }

  public void testAutowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue("the real juergen");
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    person1.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue("juergen imposter");
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
    context.registerBeanDefinition("juergen1", person1);
    context.registerBeanDefinition("juergen2", person2);
    context.registerBeanDefinition("autowired",
View Full Code Here

            // 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");
            }
View Full Code Here

    return count;
  }

  private ConstructorArgumentValues resolveConstructorValues(
      IConfigurationElement beanElement) {
    ConstructorArgumentValues constructorValues = new ConstructorArgumentValues();

    IConfigurationElement[] constructorElements = beanElement
        .getChildren("constructor-arg");
    for (int i = 0; i < constructorElements.length; i++) {
      IConfigurationElement constructorElement = constructorElements[i];

      String type = constructorElement.getAttribute("type");
      String indexString = constructorElement.getAttribute("index");

      if (log.isDebugEnabled()) {
        log.debug("found a constructor-arg: [index=" + indexString
            + ";type=" + type + "]");
      }

      IConfigurationElement[] values = constructorElement.getChildren();

      if (values.length > 0) {
        IConfigurationElement value = values[0];

        ValueHolder constructorValue = null;
        if ("ref".equals(value.getName())) {

          String ref = value.getAttribute("bean");

          if (log.isDebugEnabled()) {
            log.debug("constructor-arg references the bean: [name="
                + ref + "]");
          }

          constructorValue = new ValueHolder(
              new RuntimeBeanReference(ref), type);
        } else if ("value".equals(value.getName())) {
          String valueString = value.getValue();

          if (log.isDebugEnabled()) {
            log.debug("constructor-arg has a value: ["
                + valueString + "]");
          }

          constructorValue = new ValueHolder(valueString, type);
        } else if ("null".equals(value.getName())) {
          if (log.isDebugEnabled()) {
            log.debug("constructor-arg has a null value");
          }

          constructorValue = new ValueHolder(null, type);
        }

        if (constructorValue != null) {
          int index = -1;
          try {
            index = Integer.parseInt(indexString);
          } catch (NumberFormatException e) {
            if (log.isWarnEnabled()) {
              log.warn("constructor-arg index is invalid: " + e);
            }
          }
          if (index >= 0) {
            if (log.isDebugEnabled()) {
              log.debug("constructor-arg added to the index: ["
                  + index + "]");
            }

            constructorValues.addIndexedArgumentValue(index,
                constructorValue);
          } else {
            if (log.isDebugEnabled()) {
              log.debug("constructor-arg added without index");
            }

            constructorValues
                .addGenericArgumentValue(constructorValue);
          }
        } else if (log.isWarnEnabled()) {
          log
              .warn("contructor-arg value is null; could not be added");
View Full Code Here

    setFactoryBeanName(original.getFactoryBeanName());
    setFactoryMethodName(original.getFactoryMethodName());
    setScope(original.getScope());
    setAbstract(original.isAbstract());
    setLazyInit(original.isLazyInit());
    setConstructorArgumentValues(new ConstructorArgumentValues(original.getConstructorArgumentValues()));
    setPropertyValues(new MutablePropertyValues(original.getPropertyValues()));
    setSource(original.getSource());
    setRole(original.getRole());
    copyAttributesFrom(original);
View Full Code Here

  /**
   * Specify constructor argument values for this bean.
   */
  public void setConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues) {
    this.constructorArgumentValues =
        (constructorArgumentValues != null ? constructorArgumentValues : new ConstructorArgumentValues());
  }
View Full Code Here

        String name = annotation.name();
        return name == null || name.length() == 0 ? member.getName() : name;
    }

    private AbstractBeanDefinition createBeanDefinition(Object object, Class beanClass) {
        ConstructorArgumentValues args = new ConstructorArgumentValues();
        args.addIndexedArgumentValue(0, object);
        GenericBeanDefinition beanDef = new GenericBeanDefinition();
        beanDef.setBeanClass(beanClass);
        beanDef.setScope(Bean.Scope.SINGLETON.value());
        beanDef.setAutowireCandidate(true);
        beanDef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_AUTODETECT);
View Full Code Here

        beanDef.setConstructorArgumentValues(args);
        return beanDef;
    }

    private AbstractBeanDefinition createBeanDefinition(AccessibleObject access, Class beanClass, Bean.Scope scope) {
        ConstructorArgumentValues args = new ConstructorArgumentValues();
        args.addIndexedArgumentValue(0, mycilaContext.introspector().instance());
        args.addIndexedArgumentValue(1, access);
        GenericBeanDefinition beanDef = new GenericBeanDefinition();
        beanDef.setBeanClass(beanClass);
        beanDef.setScope(scope.value());
        beanDef.setAutowireCandidate(true);
        beanDef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_AUTODETECT);
View Full Code Here

        beandef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_AUTODETECT);
        return beandef;
    }

    protected AbstractBeanDefinition defineInstanceHolderFactoryBean(Class<?> type, Object instance) throws Exception {
        ConstructorArgumentValues args = new ConstructorArgumentValues();
        args.addIndexedArgumentValue(0, type);
        args.addIndexedArgumentValue(1, instance);

        AbstractBeanDefinition beandef = BeanDefinitionReaderUtils.createBeanDefinition(null, InstanceHolderFactoryBean.class.getName(), getClass().getClassLoader());
        beandef.setConstructorArgumentValues(args);
        beandef.setAutowireCandidate(true);
        return beandef;
View Full Code Here

TOP

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

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.