Package org.springframework.core.convert

Examples of org.springframework.core.convert.TypeDescriptor


   * @param state expression state
   * @return {@code TypedValue} instance converted to {@code String}
   */
  private static String convertTypedValueToString(TypedValue value, ExpressionState state) {
    final TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter();
    final TypeDescriptor typeDescriptor = TypeDescriptor.valueOf(String.class);

    if (typeConverter.canConvert(value.getTypeDescriptor(), typeDescriptor)) {
      final Object obj = typeConverter.convertValue(value.getValue(), value.getTypeDescriptor(), typeDescriptor);
      return String.valueOf(obj);
    } else {
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

    Method method = findGetterForProperty(name, type, target);
    if (method != null) {
      // Treat it like a property
      // The readerCache will only contain gettable properties (let's not worry about setters for now)
      Property property = new Property(type, method, null);
      TypeDescriptor typeDescriptor = new TypeDescriptor(property);
      this.readerCache.put(cacheKey, new InvokerPair(method, typeDescriptor));
      this.typeDescriptorCache.put(cacheKey, typeDescriptor);
      return true;
    }
    else {
      Field field = findField(name, type, target);
      if (field != null) {
        TypeDescriptor typeDescriptor = new TypeDescriptor(field);
        this.readerCache.put(cacheKey, new InvokerPair(field, typeDescriptor));
        this.typeDescriptorCache.put(cacheKey, typeDescriptor);
        return true;
      }
    }
View Full Code Here

        if (method != null) {
          // TODO remove the duplication here between canRead and read
          // Treat it like a property
          // The readerCache will only contain gettable properties (let's not worry about setters for now)
          Property property = new Property(type, method, null);
          TypeDescriptor typeDescriptor = new TypeDescriptor(property);
          invoker = new InvokerPair(method, typeDescriptor);
          this.readerCache.put(cacheKey, invoker);
        }
      }
      if (method != null) {
        try {
          ReflectionUtils.makeAccessible(method);
          Object value = method.invoke(target);
          return new TypedValue(value, invoker.typeDescriptor.narrow(value));
        }
        catch (Exception ex) {
          throw new AccessException("Unable to access property '" + name + "' through getter", ex);
        }
      }
    }

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

    }
    Method method = findSetterForProperty(name, type, target);
    if (method != null) {
      // Treat it like a property
      Property property = new Property(type, null, method);
      TypeDescriptor typeDescriptor = new TypeDescriptor(property);
      this.writerCache.put(cacheKey, method);
      this.typeDescriptorCache.put(cacheKey, typeDescriptor);
      return true;
    }
    else {
      Field field = findField(name, type, target);
      if (field != null) {
        this.writerCache.put(cacheKey, field);
        this.typeDescriptorCache.put(cacheKey, new TypeDescriptor(field));
        return true;
      }
    }
    return false;
  }
View Full Code Here

      throw new AccessException("Cannot write property on null target");
    }
    Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass());

    Object possiblyConvertedNewValue = newValue;
    TypeDescriptor typeDescriptor = getTypeDescriptor(context, target, name);
    if (typeDescriptor != null) {
      try {
        possiblyConvertedNewValue = context.getTypeConverter().convertValue(
            newValue, TypeDescriptor.forObject(newValue), typeDescriptor);
      }
View Full Code Here

    if (type.isArray() && name.equals("length")) {
      return TypeDescriptor.valueOf(Integer.TYPE);
    }
    CacheKey cacheKey = new CacheKey(type, name);
    TypeDescriptor typeDescriptor = this.typeDescriptorCache.get(cacheKey);
    if (typeDescriptor == null) {
      // attempt to populate the cache entry
      try {
        if (canRead(context, target, name)) {
          typeDescriptor = this.typeDescriptorCache.get(cacheKey);
View Full Code Here

    if (invocationTarget == null || invocationTarget.member instanceof Method) {
      Method method = (Method) (invocationTarget==null?null:invocationTarget.member);
      if (method == null) {
        method = findGetterForProperty(name, type, target);
        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

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.