Package org.springframework.beans.factory.config

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


      // Need to determine the factory method...
      // Try all methods with this name to see if they match the given arguments.
      Method[] candidates = ReflectionUtils.getAllDeclaredMethods(factoryClass);
      boolean autowiring = (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
      int minTypeDiffWeight = Integer.MAX_VALUE;
      ConstructorArgumentValues resolvedValues = null;

      int minNrOfArgs = 0;
      if (explicitArgs != null) {
        minNrOfArgs = explicitArgs.length;
      }
      else {
        // We don't have arguments passed in programmatically, so we need to resolve the
        // arguments specified in the constructor arguments held in the bean definition.
        ConstructorArgumentValues cargs = mbd.getConstructorArgumentValues();
        resolvedValues = new ConstructorArgumentValues();
        minNrOfArgs = resolveConstructorArguments(beanName, mbd, bw, cargs, resolvedValues);
      }

      for (int i = 0; i < candidates.length; i++) {
        Method candidate = candidates[i];
View Full Code Here


    if (node instanceof Attr) {
      Attr attr = (Attr) node;
      String argName = StringUtils.trimWhitespace(parserContext.getDelegate().getLocalName(attr));
      String argValue = StringUtils.trimWhitespace(attr.getValue());

      ConstructorArgumentValues cvs = definition.getBeanDefinition().getConstructorArgumentValues();
      boolean ref = false;

      // handle -ref arguments
      if (argName.endsWith(REF_SUFFIX)) {
        ref = true;
        argName = argName.substring(0, argName.length() - REF_SUFFIX.length());
      }

      ValueHolder valueHolder = new ValueHolder(ref ? new RuntimeBeanReference(argValue) : argValue);
      valueHolder.setSource(parserContext.getReaderContext().extractSource(attr));

      // handle "escaped"/"_" arguments
      if (argName.startsWith(DELIMITER_PREFIX)) {
        String arg = argName.substring(1).trim();

        // fast default check
        if (!StringUtils.hasText(arg)) {
          cvs.addGenericArgumentValue(valueHolder);
        }
        // assume an index otherwise
        else {
          int index = -1;
          try {
            index = Integer.parseInt(arg);
          } catch (NumberFormatException ex) {
            parserContext.getReaderContext().error(
                "Constructor argument '" + argName + "' specifies an invalid integer", attr);
          }
          if (index < 0) {
            parserContext.getReaderContext().error(
                "Constructor argument '" + argName + "' specifies a negative index", attr);
          }
         
          if (cvs.hasIndexedArgumentValue(index)){
            parserContext.getReaderContext().error(
                "Constructor argument '" + argName + "' with index "+ index+" already defined using <constructor-arg>." +
                " Only one approach may be used per argument.", attr);
          }
         
          cvs.addIndexedArgumentValue(index, valueHolder);
        }
      }
      // no escaping -> ctr name
      else {
        String name = Conventions.attributeNameToPropertyName(argName);
        if (containsArgWithName(name, cvs)){
          parserContext.getReaderContext().error(
              "Constructor argument '" + argName + "' already defined using <constructor-arg>." +
              " Only one approach may be used per argument.", attr);
        }
        valueHolder.setName(Conventions.attributeNameToPropertyName(argName));
        cvs.addGenericArgumentValue(valueHolder);
      }
    }
    return definition;
  }
View Full Code Here

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

    if (original instanceof AbstractBeanDefinition) {
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

    if (constructorToUse == null) {
      // Need to resolve the constructor.
      boolean autowiring = (chosenCtors != null ||
          mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
      ConstructorArgumentValues resolvedValues = null;

      int minNrOfArgs;
      if (explicitArgs != null) {
        minNrOfArgs = explicitArgs.length;
      }
      else {
        ConstructorArgumentValues cargs = mbd.getConstructorArgumentValues();
        resolvedValues = new ConstructorArgumentValues();
        minNrOfArgs = resolveConstructorArguments(beanName, mbd, bw, cargs, resolvedValues);
      }

      // Take specified constructors, if any.
      Constructor[] candidates = chosenCtors;
View Full Code Here

        }
      }
      Method[] candidates = candidateSet.toArray(new Method[candidateSet.size()]);
      AutowireUtils.sortFactoryMethods(candidates);

      ConstructorArgumentValues resolvedValues = null;
      boolean autowiring = (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
      int minTypeDiffWeight = Integer.MAX_VALUE;
      Set<Method> ambiguousFactoryMethods = null;

      int minNrOfArgs;
      if (explicitArgs != null) {
        minNrOfArgs = explicitArgs.length;
      }
      else {
        // We don't have arguments passed in programmatically, so we need to resolve the
        // arguments specified in the constructor arguments held in the bean definition.
        ConstructorArgumentValues cargs = mbd.getConstructorArgumentValues();
        resolvedValues = new ConstructorArgumentValues();
        minNrOfArgs = resolveConstructorArguments(beanName, mbd, bw, cargs, resolvedValues);
      }

      List<Exception> causes = null;
View Full Code Here

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

    if (original instanceof AbstractBeanDefinition) {
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 parent = null;
    String scope = GenericBeanDefinition.SCOPE_SINGLETON;
    boolean isAbstract = false;
    boolean lazyInit = false;

    ConstructorArgumentValues cas = new ConstructorArgumentValues();
    MutablePropertyValues pvs = new MutablePropertyValues();

    for (Map.Entry entry : map.entrySet()) {
      String key = StringUtils.trimWhitespace((String) entry.getKey());
      if (key.startsWith(prefix + SEPARATOR)) {
        String property = key.substring(prefix.length() + SEPARATOR.length());
        if (CLASS_KEY.equals(property)) {
          className = StringUtils.trimWhitespace((String) entry.getValue());
        }
        else if (PARENT_KEY.equals(property)) {
          parent = StringUtils.trimWhitespace((String) entry.getValue());
        }
        else if (ABSTRACT_KEY.equals(property)) {
          String val = StringUtils.trimWhitespace((String) entry.getValue());
          isAbstract = TRUE_VALUE.equals(val);
        }
        else if (SCOPE_KEY.equals(property)) {
          // Spring 2.0 style
          scope = StringUtils.trimWhitespace((String) entry.getValue());
        }
        else if (SINGLETON_KEY.equals(property)) {
          // Spring 1.2 style
          String val = StringUtils.trimWhitespace((String) entry.getValue());
          scope = ((val == null || TRUE_VALUE.equals(val) ? GenericBeanDefinition.SCOPE_SINGLETON :
              GenericBeanDefinition.SCOPE_PROTOTYPE));
        }
        else if (LAZY_INIT_KEY.equals(property)) {
          String val = StringUtils.trimWhitespace((String) entry.getValue());
          lazyInit = TRUE_VALUE.equals(val);
        }
        else if (property.startsWith(CONSTRUCTOR_ARG_PREFIX)) {
          if (property.endsWith(REF_SUFFIX)) {
            int index = Integer.parseInt(property.substring(1, property.length() - REF_SUFFIX.length()));
            cas.addIndexedArgumentValue(index, new RuntimeBeanReference(entry.getValue().toString()));
          }
          else {
            int index = Integer.parseInt(property.substring(1));
            cas.addIndexedArgumentValue(index, readValue(entry));
          }
        }
        else if (property.endsWith(REF_SUFFIX)) {
          // This isn't a real property, but a reference to another prototype
          // Extract property name: property is of form dog(ref)
View Full Code Here

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

    if (original instanceof AbstractBeanDefinition) {
View Full Code Here

TOP

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

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.