Package org.springframework.beans

Examples of org.springframework.beans.TypeConverter.convertIfNecessary()


            }
            if (autowiredBeanNames != null) {
                autowiredBeanNames.addAll(matchingBeans.keySet());
            }
            TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
            Object result = converter.convertIfNecessary(matchingBeans.values(), type);
            if (this.dependencyComparator != null && result instanceof Object[]) {
                Arrays.sort((Object[]) result, this.dependencyComparator);
            }
            return result;
        } else if (Collection.class.isAssignableFrom(type) && type.isInterface()) {
View Full Code Here


            }
            if (autowiredBeanNames != null) {
                autowiredBeanNames.addAll(matchingBeans.keySet());
            }
            TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
            Object result = converter.convertIfNecessary(matchingBeans.values(), type);
            if (this.dependencyComparator != null && result instanceof List) {
                Collections.sort((List<?>) result, this.dependencyComparator);
            }
            return result;
        } else if (Map.class.isAssignableFrom(type) && type.isInterface()) {
View Full Code Here

            Object[] convertedArguments = new Object[argCount];
            boolean match = true;
            for (int j = 0; j < argCount && match; j++) {
              // Verify that the supplied argument is assignable to the method parameter.
              try {
                convertedArguments[j] = converter.convertIfNecessary(arguments[j], paramTypes[j]);
              }
              catch (TypeMismatchException ex) {
                // Ignore -> simply doesn't match.
                match = false;
              }
View Full Code Here

      valueType = GenericCollectionTypeResolver.getCollectionType(this.targetSetClass);
    }
    if (valueType != null) {
      TypeConverter converter = getBeanTypeConverter();
      for (Object elem : this.sourceSet) {
        result.add(converter.convertIfNecessary(elem, valueType));
      }
    }
    else {
      result.addAll(this.sourceSet);
    }
View Full Code Here

      valueType = GenericCollectionTypeResolver.getCollectionType(this.targetListClass);
    }
    if (valueType != null) {
      TypeConverter converter = getBeanTypeConverter();
      for (Object elem : this.sourceList) {
        result.add(converter.convertIfNecessary(elem, valueType));
      }
    }
    else {
      result.addAll(this.sourceList);
    }
View Full Code Here

        else {
          ConstructorArgumentValues.ValueHolder sourceHolder =
              (ConstructorArgumentValues.ValueHolder) valueHolder.getSource();
          Object sourceValue = sourceHolder.getValue();
          try {
            convertedValue = converter.convertIfNecessary(originalValue, paramType,
                MethodParameter.forMethodOrConstructor(methodOrCtor, paramIndex));
            // TODO re-enable once race condition has been found (SPR-7423)
            /*
            if (originalValue == sourceValue || sourceValue instanceof TypedStringValue) {
              // Either a converted value or still the original one: store converted value.
View Full Code Here

      else if (argValue instanceof String) {
        argValue = this.beanFactory.evaluateBeanDefinitionString((String) argValue, mbd);
      }
      Class<?> paramType = paramTypes[argIndex];
      try {
        resolvedArgs[argIndex] = converter.convertIfNecessary(argValue, paramType, methodParam);
      }
      catch (TypeMismatchException ex) {
        String methodType = (methodOrCtor instanceof Constructor ? "constructor" : "factory method");
        throw new UnsatisfiedDependencyException(
            mbd.getResourceDescription(), beanName, argIndex, paramType,
View Full Code Here

      valueType = GenericCollectionTypeResolver.getMapValueType(this.targetMapClass);
    }
    if (keyType != null || valueType != null) {
      TypeConverter converter = getBeanTypeConverter();
      for (Map.Entry<?, ?> entry : this.sourceMap.entrySet()) {
        Object convertedKey = converter.convertIfNecessary(entry.getKey(), keyType);
        Object convertedValue = converter.convertIfNecessary(entry.getValue(), valueType);
        result.put(convertedKey, convertedValue);
      }
    }
    else {
View Full Code Here

    }
    if (keyType != null || valueType != null) {
      TypeConverter converter = getBeanTypeConverter();
      for (Map.Entry<?, ?> entry : this.sourceMap.entrySet()) {
        Object convertedKey = converter.convertIfNecessary(entry.getKey(), keyType);
        Object convertedValue = converter.convertIfNecessary(entry.getValue(), valueType);
        result.put(convertedKey, convertedValue);
      }
    }
    else {
      result.putAll(this.sourceMap);
View Full Code Here

      if (this.defaultObject != null && getExpectedType() != null &&
          !getExpectedType().isInstance(this.defaultObject)) {
        TypeConverter converter = (this.beanFactory != null ?
            this.beanFactory.getTypeConverter() : new SimpleTypeConverter());
        try {
          this.defaultObject = converter.convertIfNecessary(this.defaultObject, getExpectedType());
        }
        catch (TypeMismatchException ex) {
          throw new IllegalArgumentException("Default object [" + this.defaultObject + "] of type [" +
              this.defaultObject.getClass().getName() + "] is not of expected type [" +
              getExpectedType().getName() + "] and cannot be converted either", ex);
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.