Package org.springframework.expression

Examples of org.springframework.expression.TypeConverter


        if (object == null) {
            return null;
        }
        final TypeDescriptor objectTypeDescriptor = TypeDescriptor.forObject(object);
        final TypeConverter typeConverter = getSpringConversionService(processingContext);
        if (typeConverter == null || !typeConverter.canConvert(objectTypeDescriptor, TYPE_STRING)) {
            return super.convertToString(configuration, processingContext, object);
        }
        return (String) typeConverter.convertValue(object, objectTypeDescriptor, TYPE_STRING);

    }
View Full Code Here


        if (object == null) {
            return null;
        }
        final TypeDescriptor objectTypeDescriptor = TypeDescriptor.forObject(object);
        final TypeDescriptor targetTypeDescriptor = TypeDescriptor.valueOf(targetClass);
        final TypeConverter typeConverter = getSpringConversionService(processingContext);
        if (typeConverter == null || !typeConverter.canConvert(objectTypeDescriptor, targetTypeDescriptor)) {
            return super.convertOther(configuration, processingContext, object, targetClass);
        }
        return (T) typeConverter.convertValue(object, objectTypeDescriptor, targetTypeDescriptor);

    }
View Full Code Here

        if (object == null) {
            return null;
        }
        final TypeDescriptor objectTypeDescriptor = TypeDescriptor.forObject(object);
        final TypeConverter typeConverter = getSpringConversionService(processingContext);
        if (typeConverter == null || !typeConverter.canConvert(objectTypeDescriptor, TYPE_STRING)) {
            return super.convertToString(configuration, processingContext, object);
        }
        return (String) typeConverter.convertValue(object, objectTypeDescriptor, TYPE_STRING);

    }
View Full Code Here

        if (object == null) {
            return null;
        }
        final TypeDescriptor objectTypeDescriptor = TypeDescriptor.forObject(object);
        final TypeDescriptor targetTypeDescriptor = TypeDescriptor.valueOf(targetClass);
        final TypeConverter typeConverter = getSpringConversionService(processingContext);
        if (typeConverter == null || !typeConverter.canConvert(objectTypeDescriptor, targetTypeDescriptor)) {
            return super.convertOther(configuration, processingContext, object, targetClass);
        }
        return (T) typeConverter.convertValue(object, objectTypeDescriptor, targetTypeDescriptor);

    }
View Full Code Here

      for (SpelNodeImpl dimension : this.dimensions) {
        if (dimension == null) {
          throw new SpelEvaluationException(getStartPosition(), SpelMessage.MISSING_ARRAY_DIMENSION);
        }
      }
      TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter();

      // Shortcut for 1 dimensional
      if (this.dimensions.length == 1) {
        TypedValue o = this.dimensions[0].getTypedValue(state);
        int arraySize = ExpressionUtils.toInt(typeConverter, o);
        newArray = Array.newInstance(componentType, arraySize);
      }
      else {
        // Multi-dimensional - hold onto your hat!
        int[] dims = new int[this.dimensions.length];
        for (int d = 0; d < this.dimensions.length; d++) {
          TypedValue o = this.dimensions[d].getTypedValue(state);
          dims[d] = ExpressionUtils.toInt(typeConverter, o);
        }
        newArray = Array.newInstance(componentType, dims);
      }
    }
    else {
      // There is an initializer
      if (this.dimensions.length > 1) {
        // There is an initializer but this is a multi-dimensional array (e.g. new int[][]{{1,2},{3,4}}) - this
        // is not currently supported
        throw new SpelEvaluationException(getStartPosition(),
            SpelMessage.MULTIDIM_ARRAY_INITIALIZER_NOT_SUPPORTED);
      }
      TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter();
      InlineList initializer = (InlineList) getChild(1);
      // If a dimension was specified, check it matches the initializer length
      if (this.dimensions[0] != null) {
        TypedValue dValue = this.dimensions[0].getTypedValue(state);
        int i = ExpressionUtils.toInt(typeConverter, dValue);
View Full Code Here

   * @param value typed value to be converted
   * @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 {
      return String.valueOf(value.getValue());
    }
  }
View Full Code Here

   */
  public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name,
      List<TypeDescriptor> argumentTypes) throws AccessException {

    try {
      TypeConverter typeConverter = context.getTypeConverter();
      Class<?> type = (targetObject instanceof Class ? (Class<?>) targetObject : targetObject.getClass());
      Method[] methods = getMethods(type, targetObject);

      // If a filter is registered for this type, call it
      MethodFilter filter = (this.filters != null ? this.filters.get(type) : null);
View Full Code Here

          + "." + method.getName(), name);
    }

    // Convert arguments if necessary and remap them for varargs if required
    if (functionArgs != null) {
      TypeConverter converter = state.getEvaluationContext().getTypeConverter();
      ReflectionHelper.convertAllArguments(converter, functionArgs, method);
    }
    if (method.isVarArgs()) {
      functionArgs = ReflectionHelper.setupArgumentsForVarargsInvocation(method.getParameterTypes(), functionArgs);
    }
View Full Code Here

   */
  public ConstructorExecutor resolve(EvaluationContext context, String typename, List<TypeDescriptor> argumentTypes)
      throws AccessException {

    try {
      TypeConverter typeConverter = context.getTypeConverter();
      Class<?> type = context.getTypeLocator().findType(typename);
      Constructor[] ctors = type.getConstructors();

      Arrays.sort(ctors, new Comparator<Constructor>() {
        public int compare(Constructor c1, Constructor c2) {
View Full Code Here

   */
  public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name,
      List<TypeDescriptor> argumentTypes) throws AccessException {

    try {
      TypeConverter typeConverter = context.getTypeConverter();
      Class<?> type = (targetObject instanceof Class ? (Class<?>) targetObject : targetObject.getClass());
      Method[] methods = type.getMethods();
     
      // If a filter is registered for this type, call it
      MethodFilter filter = (this.filters != null ? this.filters.get(type) : null);
View Full Code Here

TOP

Related Classes of org.springframework.expression.TypeConverter

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.