Package org.springframework.beans

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


      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


        String strVal = resolveEmbeddedValue((String) value);
        BeanDefinition bd = (containsBean(beanName) ? getMergedBeanDefinition(beanName) : null);
        value = evaluateBeanDefinitionString(strVal, bd);
      }
      TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
      return converter.convertIfNecessary(value, type);
    }

    if (type.isArray()) {
      Class componentType = type.getComponentType();
      Map<String, Object> matchingBeans = findAutowireCandidates(beanName, componentType, descriptor);
View Full Code Here

      }
      if (autowiredBeanNames != null) {
        autowiredBeanNames.addAll(matchingBeans.keySet());
      }
      TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
      return converter.convertIfNecessary(matchingBeans.values(), type);
    }
    else if (Collection.class.isAssignableFrom(type) && type.isInterface()) {
      Class elementType = descriptor.getCollectionType();
      if (elementType == null) {
        if (descriptor.isRequired()) {
View Full Code Here

      }
      if (autowiredBeanNames != null) {
        autowiredBeanNames.addAll(matchingBeans.keySet());
      }
      TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
      return converter.convertIfNecessary(matchingBeans.values(), type);
    }
    else if (Map.class.isAssignableFrom(type) && type.isInterface()) {
      Class keyType = descriptor.getMapKeyType();
      if (keyType == null || !String.class.isAssignableFrom(keyType)) {
        if (descriptor.isRequired()) {
View Full Code Here

        TypeConverter tc = form.getTypeConverter();

        assertNotNull(tc);
        assertSame(tc, form.getTypeConverter()); // 两次返回相同的

        assertEquals(new Integer(123), tc.convertIfNecessary("any", Integer.class));
    }

    @Test
    public void isForcePostOnly() throws Exception {
        invokeGet(null);
View Full Code Here

          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

              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

              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

      }
      if (autowiredBeanNames != null) {
        autowiredBeanNames.addAll(matchingBeans.keySet());
      }
      TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
      return converter.convertIfNecessary(matchingBeans.values(), type);
    }
    else if (Collection.class.isAssignableFrom(type) && type.isInterface()) {
      Class elementType = descriptor.getCollectionType();
      if (elementType == null) {
        if (descriptor.isRequired()) {
View Full Code Here

      }
      if (autowiredBeanNames != null) {
        autowiredBeanNames.addAll(matchingBeans.keySet());
      }
      TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
      return converter.convertIfNecessary(matchingBeans.values(), type);
    }
    else if (Map.class.isAssignableFrom(type) && type.isInterface()) {
      Class keyType = descriptor.getMapKeyType();
      if (keyType == null || !String.class.isAssignableFrom(keyType)) {
        if (descriptor.isRequired()) {
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.