Examples of ConstructorArgumentValues


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

    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
    lbf.setTypeConverter(new CustomTypeConverter(nf));
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("myFloat", new RuntimeBeanReference("myFloat"));
    ConstructorArgumentValues cav = new ConstructorArgumentValues();
    cav.addIndexedArgumentValue(0, "myName");
    cav.addIndexedArgumentValue(1, "myAge");
    lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, cav, pvs));
    lbf.registerSingleton("myFloat", "1,1");
    TestBean testBean = (TestBean) lbf.getBean("testBean");
    assertEquals("myName", testBean.getName());
    assertEquals(5, testBean.getAge());
View Full Code Here

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

    lbf.registerBeanDefinition("fmGeneric", factoryMethodDefinitionGeneric);

    RootBeanDefinition factoryMethodDefinitionWithArgs = new RootBeanDefinition();
    factoryMethodDefinitionWithArgs.setFactoryBeanName("factoryBeanInstance");
    factoryMethodDefinitionWithArgs.setFactoryMethodName("createWithArgs");
    ConstructorArgumentValues cvals = new ConstructorArgumentValues();
    cvals.addGenericArgumentValue(expectedNameFromArgs);
    factoryMethodDefinitionWithArgs.setConstructorArgumentValues(cvals);
    if (!singleton) {
      factoryMethodDefinitionWithArgs.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    }
    lbf.registerBeanDefinition("fmWithArgs", factoryMethodDefinitionWithArgs);
View Full Code Here

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

            beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE);
            if (BusWiringType.PROPERTY == type) {
                beanDefinition.getPropertyValues()
                    .addPropertyValue("bus", inj);
            } else if (BusWiringType.CONSTRUCTOR == type) {
                ConstructorArgumentValues constructorArgs = beanDefinition.getConstructorArgumentValues();
                insertConstructorArg(constructorArgs, inj);
            }
        }
    }
View Full Code Here

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

    if (adviceElement.hasAttribute(ARG_NAMES)) {
      adviceDefinition.getPropertyValues().addPropertyValue(
          ARG_NAMES_PROPERTY, adviceElement.getAttribute(ARG_NAMES));
    }

    ConstructorArgumentValues cav = adviceDefinition.getConstructorArgumentValues();
    cav.addIndexedArgumentValue(METHOD_INDEX, methodDef);

    Object pointcut = parsePointcutProperty(adviceElement, parserContext);
    if (pointcut instanceof BeanDefinition) {
      cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcut);
      beanDefinitions.add(pointcut);
    }
    else if (pointcut instanceof String) {
      RuntimeBeanReference pointcutRef = new RuntimeBeanReference((String) pointcut);
      cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcutRef);
      beanReferences.add(pointcutRef);
    }

    cav.addIndexedArgumentValue(ASPECT_INSTANCE_FACTORY_INDEX, aspectFactoryDef);

    return adviceDefinition;
  }
View Full Code Here

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

    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()));
    setResourceDescription(original.getResourceDescription());
    setSource(original.getSource());
    setRole(original.getRole());
    copyAttributesFrom(original);
View Full Code Here

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

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

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

    String parent = null;
    boolean isAbstract = false;
    boolean singleton = true;
    boolean lazyInit = false;

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

    for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
      Map.Entry entry = (Map.Entry) it.next();
      String key = StringUtils.trimWhitespace((String) entry.getKey());
      if (key.startsWith(prefix + SEPARATOR)) {
        String property = key.substring(prefix.length() + SEPARATOR.length());
        if (isClassKey(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 (SINGLETON_KEY.equals(property)) {
          String val = StringUtils.trimWhitespace((String) entry.getValue());
          singleton = (val == null) || TRUE_VALUE.equals(val);
        }
        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

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

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

      int minNrOfArgs = 0;
      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 =
View Full Code Here

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

      // 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

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

    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
TOP
Copyright © 2018 www.massapi.com. 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.