Package org.springframework.core.convert

Examples of org.springframework.core.convert.TypeDescriptor


    if (sourceCollection.size() == 0) {
      return null;
    }
    else {
      Object firstElement = sourceCollection.iterator().next();
      TypeDescriptor sourceElementType = sourceType.getElementTypeDescriptor();
      if (sourceElementType == TypeDescriptor.NULL && firstElement != null) {
        sourceElementType = TypeDescriptor.valueOf(firstElement.getClass());
      }
      if (sourceElementType == TypeDescriptor.NULL || sourceElementType.isAssignableTo(targetType)) {
        return firstElement;
      }
      else {
        GenericConverter converter = this.conversionService.getConverter(sourceElementType, targetType);
        if (converter == null) {
View Full Code Here


  public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
    if (source == null) {
      return this.conversionService.convertNullSource(sourceType, targetType);
    }
    Map<?, ?> sourceMap = (Map<?, ?>) source;
    TypeDescriptor targetKeyType = targetType.getMapKeyTypeDescriptor();
    TypeDescriptor targetValueType = targetType.getMapValueTypeDescriptor();
    if (targetKeyType == TypeDescriptor.NULL && targetValueType == TypeDescriptor.NULL) {
      return compatibleMapWithoutEntryConversion(sourceMap, targetType);
    }
    TypeDescriptor sourceKeyType = sourceType.getMapKeyTypeDescriptor();
    TypeDescriptor sourceValueType = sourceType.getMapValueTypeDescriptor();
    if (sourceKeyType == TypeDescriptor.NULL || sourceValueType == TypeDescriptor.NULL) {
      TypeDescriptor[] sourceEntryTypes = ConversionUtils.getMapEntryTypes(sourceMap);
      sourceKeyType = sourceEntryTypes[0];
      sourceValueType = sourceEntryTypes[1];
    }
    if (sourceKeyType == TypeDescriptor.NULL && sourceValueType == TypeDescriptor.NULL) {
      return compatibleMapWithoutEntryConversion(sourceMap, targetType);
    }
    boolean keysCompatible = false;
    if (sourceKeyType != TypeDescriptor.NULL && sourceKeyType.isAssignableTo(targetKeyType)) {
      keysCompatible = true;
    }
    boolean valuesCompatible = false;
    if (sourceValueType != TypeDescriptor.NULL && sourceValueType.isAssignableTo(targetValueType)) {
      valuesCompatible = true;
    }
    if (keysCompatible && valuesCompatible) {
      return compatibleMapWithoutEntryConversion(sourceMap, targetType);
    }
View Full Code Here

  }

  public TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException {
    Field field = this.fieldMap.get(propertyName);
    if (field != null) {
      return new TypeDescriptor(field);
    }
    return null;
  }
View Full Code Here

        throw new IllegalArgumentException("Unable to parse '" + text + "'", ex);
      }
      if (result == null) {
        throw new IllegalStateException("Parsers are not allowed to return null");
      }
      TypeDescriptor resultType = TypeDescriptor.valueOf(result.getClass());
      if (!resultType.isAssignableTo(targetType)) {
        result = this.conversionService.convert(result, resultType, targetType);
      }
      return result;
    }
View Full Code Here

          if (pd.getReadMethod() != null || pd.getWriteMethod() != null) {
            return TypeDescriptor.nested(property(pd), tokens.keys.length);
          }
        } else {
          if (pd.getReadMethod() != null || pd.getWriteMethod() != null) {
            return new TypeDescriptor(property(pd));
          }
        }
      }
    }
    catch (InvalidPropertyException ex) {
View Full Code Here

  }

  private Object convertForProperty(String propertyName, Object oldValue, Object newValue, PropertyDescriptor pd)
      throws TypeMismatchException {

    return convertIfNecessary(propertyName, oldValue, newValue, pd.getPropertyType(), new TypeDescriptor(property(pd)));
  }
View Full Code Here

          else if (value instanceof Map) {
            Map map = (Map) value;
            Class<?> mapKeyType = GenericCollectionTypeResolver.getMapKeyReturnType(pd.getReadMethod(), i + 1);
            // IMPORTANT: Do not pass full property name in here - property editors
            // must not kick in for map keys but rather only for map values.
            TypeDescriptor typeDescriptor = mapKeyType != null ? TypeDescriptor.valueOf(mapKeyType) : TypeDescriptor.valueOf(Object.class);
            Object convertedMapKey = convertIfNecessary(null, null, key, mapKeyType, typeDescriptor);
            value = map.get(convertedMapKey);
          }
          else {
            throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
View Full Code Here

        Class mapValueType = GenericCollectionTypeResolver.getMapValueReturnType(
            pd.getReadMethod(), tokens.keys.length);
        Map map = (Map) propValue;
        // IMPORTANT: Do not pass full property name in here - property editors
        // must not kick in for map keys but rather only for map values.
        TypeDescriptor typeDescriptor = (mapKeyType != null ?
            TypeDescriptor.valueOf(mapKeyType) : TypeDescriptor.valueOf(Object.class));
        Object convertedMapKey = convertIfNecessary(null, null, key, mapKeyType, typeDescriptor);
        Object oldValue = null;
        if (isExtractOldValueForEditor()) {
          oldValue = map.get(convertedMapKey);
View Full Code Here

  }

  public TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException {
    Field field = this.fieldMap.get(propertyName);
    if (field != null) {
      return new TypeDescriptor(field);
    }
    return null;
  }
View Full Code Here

    Object oldValue = null;
    try {
      ReflectionUtils.makeAccessible(field);
      oldValue = field.get(this.target);
      Object convertedValue = this.typeConverterDelegate.convertIfNecessary(
          field.getName(), oldValue, newValue, field.getType(), new TypeDescriptor(field));
      field.set(this.target, convertedValue);
    }
    catch (ConverterNotFoundException ex) {
      PropertyChangeEvent pce = new PropertyChangeEvent(this.target, propertyName, oldValue, newValue);
      throw new ConversionNotSupportedException(pce, field.getType(), ex);
View Full Code Here

TOP

Related Classes of org.springframework.core.convert.TypeDescriptor

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.