Package org.springframework.core.convert

Examples of org.springframework.core.convert.TypeDescriptor


    if (invocationTarget == null || invocationTarget.member instanceof Method) {
      Method method = (Method) (invocationTarget==null?null:invocationTarget.member);
      if (method == null) {
        method = findGetterForProperty(name, type, target instanceof Class);
        if (method != null) {
          invocationTarget = new InvokerPair(method,new TypeDescriptor(new MethodParameter(method,-1)));
          ReflectionUtils.makeAccessible(method);
          this.readerCache.put(cacheKey, invocationTarget);
        }
      }
      if (method != null) {
        return new OptimalPropertyAccessor(invocationTarget);
      }
    }

    if (invocationTarget == null || invocationTarget.member instanceof Field) {
      Field field = (Field) (invocationTarget==null?null:invocationTarget.member);
      if (field == null) {
        field = findField(name, type, target instanceof Class);
        if (field != null) {
          invocationTarget = new InvokerPair(field, new TypeDescriptor(field));
          ReflectionUtils.makeAccessible(field);
          this.readerCache.put(cacheKey, invocationTarget);
        }
      }
      if (field != null) {
View Full Code Here


  }

  public Class getValueType(EvaluationContext context) throws EvaluationException {
    Assert.notNull(context, "The EvaluationContext is required");
    ExpressionState eState = new ExpressionState(context, configuration);
    TypeDescriptor typeDescriptor = ast.getValueInternal(eState).getTypeDescriptor();
    return typeDescriptor != null ? typeDescriptor.getType() : null;
  }
View Full Code Here

    return typeDescriptor != null ? typeDescriptor.getType() : null;
  }

  public Class getValueType(EvaluationContext context, Object rootObject) throws EvaluationException {
    ExpressionState eState = new ExpressionState(context, toTypedValue(rootObject), configuration);
    TypeDescriptor typeDescriptor = ast.getValueInternal(eState).getTypeDescriptor();
    return typeDescriptor != null ? typeDescriptor.getType() : null;
  }
View Full Code Here

                         WebDataBinderFactory binderFactory,
                         NativeWebRequest request) throws Exception {
    DataBinder binder = binderFactory.createBinder(request, null, attributeName);
    ConversionService conversionService = binder.getConversionService();
    if (conversionService != null) {
      TypeDescriptor source = TypeDescriptor.valueOf(String.class);
      TypeDescriptor target = new TypeDescriptor(parameter);
      if (conversionService.canConvert(source, target)) {
        return binder.convertIfNecessary(sourceValue, parameter.getParameterType(), parameter);
      }
    }
    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

        return textValue;
      }
    }
    if (this.conversionService != null) {
      // Try custom converter...
      TypeDescriptor fieldDesc = getPropertyAccessor().getPropertyTypeDescriptor(fixedField);
      TypeDescriptor strDesc = TypeDescriptor.valueOf(String.class);
      if (fieldDesc != null && this.conversionService.canConvert(fieldDesc, strDesc)) {
        return this.conversionService.convert(value, fieldDesc, strDesc);
      }
    }
    return value;
View Full Code Here

    if (valueTypeForLookup == null) {
      valueTypeForLookup = getFieldType(field);
    }
    PropertyEditor editor = super.findEditor(field, valueTypeForLookup);
    if (editor == null && this.conversionService != null) {
      TypeDescriptor td = null;
      if (field != null) {
        TypeDescriptor ptd = getPropertyAccessor().getPropertyTypeDescriptor(fixedField(field));
        if (valueType == null || valueType.isAssignableFrom(ptd.getType())) {
          td = ptd;
        }
      }
      if (td == null) {
        td = TypeDescriptor.valueOf(valueTypeForLookup);
View Full Code Here

      if (this.method.isVarArgs()) {
        arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(this.method.getParameterTypes(), arguments);
      }
      ReflectionUtils.makeAccessible(this.method);
      Object value = this.method.invoke(target, arguments);
      return new TypedValue(value, new TypeDescriptor(new MethodParameter(this.method, -1)).narrow(value));
    }
    catch (Exception ex) {
      throw new AccessException("Problem invoking method: " + this.method, ex);
    }
  }
View Full Code Here

   */
  public <T> T convertIfNecessary(Object newValue, Class<T> requiredType, MethodParameter methodParam)
      throws IllegalArgumentException {

    return convertIfNecessary(null, null, newValue, requiredType,
        (methodParam != null ? new TypeDescriptor(methodParam) : TypeDescriptor.valueOf(requiredType)));
  }
View Full Code Here

    ConversionFailedException firstAttemptEx = null;

    // No custom editor but custom ConversionService specified?
    ConversionService conversionService = this.propertyEditorRegistry.getConversionService();
    if (editor == null && conversionService != null && convertedValue != null && typeDescriptor != null) {
      TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(newValue);
      TypeDescriptor targetTypeDesc = typeDescriptor;
      if (conversionService.canConvert(sourceTypeDesc, targetTypeDesc)) {
        try {
          return (T) conversionService.convert(convertedValue, sourceTypeDesc, targetTypeDesc);
        }
        catch (ConversionFailedException ex) {
          // fallback to default conversion logic below
          firstAttemptEx = ex;
        }
      }
    }

    // Value not of required type?
    if (editor != null || (requiredType != null && !ClassUtils.isAssignableValue(requiredType, convertedValue))) {
      if (requiredType != null && Collection.class.isAssignableFrom(requiredType) && convertedValue instanceof String) {
        TypeDescriptor elementType = typeDescriptor.getElementTypeDescriptor();
        if (elementType != null && Enum.class.isAssignableFrom(elementType.getType())) {
          convertedValue = StringUtils.commaDelimitedListToStringArray((String) convertedValue);
        }
      }
      if (editor == null) {
        editor = findDefaultEditor(requiredType, typeDescriptor);
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.