Package org.springframework.core.convert.support

Examples of org.springframework.core.convert.support.PropertyTypeDescriptor


      String actualPropertyName = PropertyAccessorUtils.getPropertyName(propertyName);
      PropertyDescriptor pd = getPropertyDescriptorInternal(actualPropertyName);
      if (pd != null) {
        Class type = getPropertyType(propertyName);
        if (pd.getReadMethod() != null) {
          return new PropertyTypeDescriptor(pd, new MethodParameter(pd.getReadMethod(), -1), type);
        }
        else if (pd.getWriteMethod() != null) {
          return new PropertyTypeDescriptor(pd, BeanUtils.getWriteMethodParameter(pd), type);
        }
      }
    }
    catch (InvalidPropertyException ex) {
      // Consider as not determinable.
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 PropertyTypeDescriptor(pd, BeanUtils.getWriteMethodParameter(pd)));
  }
View Full Code Here

            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.
            Object convertedMapKey = convertIfNecessary(null, null, key, mapKeyType,
                new PropertyTypeDescriptor(pd, new MethodParameter(pd.getReadMethod(), -1), mapKeyType));
            // Pass full property name and old value in here, since we want full
            // conversion ability for map values.
            growMapIfNecessary(map, convertedMapKey, indexedPropertyName, pd, i + 1);
            value = map.get(convertedMapKey);
          }
View Full Code Here

        try {
          if (isExtractOldValueForEditor()) {
            oldValue = Array.get(propValue, arrayIndex);
          }
          Object convertedValue = convertIfNecessary(propertyName, oldValue, pv.getValue(), requiredType,
              new PropertyTypeDescriptor(pd, new MethodParameter(pd.getReadMethod(), -1), requiredType));
          Array.set(propValue, arrayIndex, convertedValue);
        }
        catch (IndexOutOfBoundsException ex) {
          throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
              "Invalid array index in property path '" + propertyName + "'", ex);
        }
      }
      else if (propValue instanceof List) {
        PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
        Class requiredType = GenericCollectionTypeResolver.getCollectionReturnType(
            pd.getReadMethod(), tokens.keys.length);
        List list = (List) propValue;
        int index = Integer.parseInt(key);
        Object oldValue = null;
        if (isExtractOldValueForEditor() && index < list.size()) {
          oldValue = list.get(index);
        }
        Object convertedValue = convertIfNecessary(propertyName, oldValue, pv.getValue(), requiredType,
            new PropertyTypeDescriptor(pd, new MethodParameter(pd.getReadMethod(), -1), requiredType));
        if (index < list.size()) {
          list.set(index, convertedValue);
        }
        else if (index >= list.size()) {
          for (int i = list.size(); i < index; i++) {
            try {
              list.add(null);
            }
            catch (NullPointerException ex) {
              throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
                  "Cannot set element with index " + index + " in List of size " +
                  list.size() + ", accessed using property path '" + propertyName +
                  "': List does not support filling up gaps with null elements");
            }
          }
          list.add(convertedValue);
        }
      }
      else if (propValue instanceof Map) {
        PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
        Class mapKeyType = GenericCollectionTypeResolver.getMapKeyReturnType(
            pd.getReadMethod(), tokens.keys.length);
        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.
        Object convertedMapKey = convertIfNecessary(null, null, key, mapKeyType,
            new PropertyTypeDescriptor(pd, new MethodParameter(pd.getReadMethod(), -1), mapKeyType));
        Object oldValue = null;
        if (isExtractOldValueForEditor()) {
          oldValue = map.get(convertedMapKey);
        }
        // Pass full property name and old value in here, since we want full
View Full Code Here

      // Treat it like a property
      try {
        // The readerCache will only contain gettable properties (let's not worry about setters for now)
        PropertyDescriptor propertyDescriptor = new PropertyDescriptor(name, method, null);
        TypeDescriptor typeDescriptor =
            new PropertyTypeDescriptor(propertyDescriptor, new MethodParameter(method, -1));
        this.readerCache.put(cacheKey, new InvokerPair(method, typeDescriptor));
        this.typeDescriptorCache.put(cacheKey, typeDescriptor);
        return true;
      }
      catch (IntrospectionException ex) {
View Full Code Here

          // Treat it like a property
          try {
            // The readerCache will only contain gettable properties (let's not worry about setters for now)
            PropertyDescriptor propertyDescriptor = new PropertyDescriptor(name, method, null);
            TypeDescriptor typeDescriptor =
                new PropertyTypeDescriptor(propertyDescriptor, new MethodParameter(method, -1));
            invoker = new InvokerPair(method, typeDescriptor);
            this.readerCache.put(cacheKey, invoker);
          }
          catch (IntrospectionException ex) {
            throw new AccessException(
View Full Code Here

        propertyDescriptor = new PropertyDescriptor(name,null,method);
      } catch (IntrospectionException ex) {
        throw new AccessException("Unable to access property '" + name + "' through setter "+method, ex);
      }
      MethodParameter mp = new MethodParameter(method,0);
      TypeDescriptor typeDescriptor = new PropertyTypeDescriptor(propertyDescriptor, mp);
      this.writerCache.put(cacheKey, method);
      this.typeDescriptorCache.put(cacheKey, typeDescriptor);
      return true;
    }
    else {
View Full Code Here

TOP

Related Classes of org.springframework.core.convert.support.PropertyTypeDescriptor

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.