Package org.springframework.beans

Examples of org.springframework.beans.TypeConverter


    protected String encodeValue(Object value) throws Exception {
        assertTrue(value instanceof Map, "wrong session attribute type: " + value.getClass());

        Map<?, ?> map = (Map<?, ?>) value;
        Map<String, String> encodedMap = createLinkedHashMap();
        TypeConverter converter = getTypeConverter();

        for (Map.Entry<?, ?> entry : map.entrySet()) {
            String key = String.valueOf(entry.getKey());
            String encodedValue = convertToString(valueType, entry.getValue(), converter);
View Full Code Here


    }

    @Override
    protected Object decodeValue(String encodedValue) throws Exception {
        final Map<String, Object> map = createLinkedHashMap();
        final TypeConverter converter = getTypeConverter();

        new QueryStringParser(getCharset()) {
            @Override
            protected void add(String key, String encodedValue) {
                map.put(key, convertToType(valueType, encodedValue, converter));
View Full Code Here

        // Found a cached constructor...
        argsToUse = mbd.resolvedConstructorArguments;
        if (argsToUse == null) {
          Class[] paramTypes = constructorToUse.getParameterTypes();
          Object[] argsToResolve = mbd.preparedConstructorArguments;
          TypeConverter converter = (this.typeConverter != null ? this.typeConverter : bw);
          BeanDefinitionValueResolver valueResolver =
              new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
          argsToUse = new Object[argsToResolve.length];
          for (int i = 0; i < argsToResolve.length; i++) {
            Object argValue = argsToResolve[i];
            MethodParameter methodParam = new MethodParameter(constructorToUse, i);
            if (JdkVersion.isAtLeastJava15()) {
              GenericTypeResolver.resolveParameterType(methodParam, constructorToUse.getDeclaringClass());
            }
            if (argValue instanceof AutowiredArgumentMarker) {
              argValue = resolveAutowiredArgument(methodParam, beanName, null, converter);
            }
            else if (argValue instanceof BeanMetadataElement) {
              argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);
            }
            argsToUse[i] = converter.convertIfNecessary(argValue, paramTypes[i], methodParam);
          }
        }
      }
    }
View Full Code Here

        // Found a cached factory method...
        argsToUse = mbd.resolvedConstructorArguments;
        if (argsToUse == null) {
          Class[] paramTypes = factoryMethodToUse.getParameterTypes();
          Object[] argsToResolve = mbd.preparedConstructorArguments;
          TypeConverter converter = (this.typeConverter != null ? this.typeConverter : bw);
          BeanDefinitionValueResolver valueResolver =
              new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
          argsToUse = new Object[argsToResolve.length];
          for (int i = 0; i < argsToResolve.length; i++) {
            Object argValue = argsToResolve[i];
            MethodParameter methodParam = new MethodParameter(factoryMethodToUse, i);
            if (JdkVersion.isAtLeastJava15()) {
              GenericTypeResolver.resolveParameterType(methodParam, factoryClass);
            }
            if (argValue instanceof AutowiredArgumentMarker) {
              argValue = resolveAutowiredArgument(methodParam, beanName, null, converter);
            }
            else if (argValue instanceof BeanMetadataElement) {
              argValue = valueResolver.resolveValueIfNecessary("factory method argument", argValue);
            }
            argsToUse[i] = converter.convertIfNecessary(argValue, paramTypes[i], methodParam);
          }
        }
      }
    }
View Full Code Here

   */
  private int resolveConstructorArguments(
      String beanName, RootBeanDefinition mbd, BeanWrapper bw,
      ConstructorArgumentValues cargs, ConstructorArgumentValues resolvedValues) {

    TypeConverter converterToUse = (this.typeConverter != null ? this.typeConverter : bw);
    BeanDefinitionValueResolver valueResolver =
        new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converterToUse);

    int minNrOfArgs = cargs.getArgumentCount();

View Full Code Here

      String beanName, RootBeanDefinition mbd, ConstructorArgumentValues resolvedValues,
      BeanWrapper bw, Class[] paramTypes, Object methodOrCtor, boolean autowiring)
      throws UnsatisfiedDependencyException {

    String methodType = (methodOrCtor instanceof Constructor ? "constructor" : "factory method");
    TypeConverter converter = (this.typeConverter != null ? this.typeConverter : bw);

    ArgumentsHolder args = new ArgumentsHolder(paramTypes.length);
    Set usedValueHolders = new HashSet(paramTypes.length);
    Set autowiredBeanNames = new LinkedHashSet(4);
    boolean resolveNecessary = false;

    for (int paramIndex = 0; paramIndex < paramTypes.length; paramIndex++) {
      Class paramType = paramTypes[paramIndex];
      // Try to find matching constructor argument value, either indexed or generic.
      ConstructorArgumentValues.ValueHolder valueHolder =
          resolvedValues.getArgumentValue(paramIndex, paramType, usedValueHolders);
      // If we couldn't find a direct match and are not supposed to autowire,
      // let's try the next generic, untyped argument value as fallback:
      // it could match after type conversion (for example, String -> int).
      if (valueHolder == null && !autowiring) {
        valueHolder = resolvedValues.getGenericArgumentValue(null, usedValueHolders);
      }
      if (valueHolder != null) {
        // We found a potential match - let's give it a try.
        // Do not consider the same value definition multiple times!
        usedValueHolders.add(valueHolder);
        args.rawArguments[paramIndex] = valueHolder.getValue();
        if (valueHolder.isConverted()) {
          Object convertedValue = valueHolder.getConvertedValue();
          args.arguments[paramIndex] = convertedValue;
          args.preparedArguments[paramIndex] = convertedValue;
        }
        else {
          try {
            Object originalValue = valueHolder.getValue();
            Object convertedValue = converter.convertIfNecessary(originalValue, paramType,
                MethodParameter.forMethodOrConstructor(methodOrCtor, paramIndex));
            args.arguments[paramIndex] = convertedValue;
            ConstructorArgumentValues.ValueHolder sourceHolder =
                (ConstructorArgumentValues.ValueHolder) valueHolder.getSource();
            Object sourceValue = sourceHolder.getValue();
View Full Code Here

    Class valueType = null;
    if (this.targetListClass != null && JdkVersion.isAtLeastJava15()) {
      valueType = GenericCollectionTypeResolver.getCollectionType(this.targetListClass);
    }
    if (valueType != null) {
      TypeConverter converter = getBeanTypeConverter();
      for (Iterator it = this.sourceList.iterator(); it.hasNext();) {
        result.add(converter.convertIfNecessary(it.next(), valueType));
      }
    }
    else {
      result.addAll(this.sourceList);
    }
View Full Code Here

   * @param pvs the PropertyValues to register wired objects with
   */
  protected void autowireByType(
      String beanName, AbstractBeanDefinition mbd, BeanWrapper bw, MutablePropertyValues pvs) {

    TypeConverter converter = getCustomTypeConverter();
    if (converter == null) {
      converter = bw;
    }

    Set autowiredBeanNames = new LinkedHashSet(4);
View Full Code Here

    }
    else {
      original = Arrays.asList(pvs.getPropertyValues());
    }

    TypeConverter converter = getCustomTypeConverter();
    if (converter == null) {
      converter = bw;
    }
    BeanDefinitionValueResolver valueResolver = new BeanDefinitionValueResolver(this, beanName, mbd, converter);
View Full Code Here

    Class valueType = null;
    if (this.targetSetClass != null && JdkVersion.isAtLeastJava15()) {
      valueType = GenericCollectionTypeResolver.getCollectionType(this.targetSetClass);
    }
    if (valueType != null) {
      TypeConverter converter = getBeanTypeConverter();
      for (Iterator it = this.sourceSet.iterator(); it.hasNext();) {
        result.add(converter.convertIfNecessary(it.next(), valueType));
      }
    }
    else {
      result.addAll(this.sourceSet);
    }
View Full Code Here

TOP

Related Classes of org.springframework.beans.TypeConverter

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.