Package org.springframework.core.convert.converter

Examples of org.springframework.core.convert.converter.GenericConverter


      for (Iterator<?> it = sourceCollection.iterator(); it.hasNext(); i++) {
        Array.set(array, i, it.next());
      }
    }
    else {
      GenericConverter converter = this.conversionService.getConverter(sourceElementType, targetElementType);
      if (converter == null) {
        throw new ConverterNotFoundException(sourceElementType, targetElementType);
      }
      for (Iterator<?> it = sourceCollection.iterator(); it.hasNext(); i++) {
        Object sourceElement = it.next();
View Full Code Here


      for (int i = 0; i < length; i++) {
        collection.add(Array.get(source, i));
      }
    }
    else {
      GenericConverter converter = this.conversionService.getConverter(sourceElementType, targetElementType);
      if (converter == null) {
        throw new ConverterNotFoundException(sourceElementType, targetElementType);
      }
      for (int i = 0; i < length; i++) {
        Object sourceElement = Array.get(source, i);
View Full Code Here

      for (String field : fields) {
        target.add(field);
      }
    }
    else {
      GenericConverter converter = this.conversionService.getConverter(sourceType, targetElementType);
      if (converter == null) {
        throw new ConverterNotFoundException(sourceType, targetElementType);
      }
      for (String sourceElement : fields) {
        Object targetElement = ConversionUtils.invokeConverter(
View Full Code Here

      }
      if (sourceElementType == TypeDescriptor.NULL || sourceElementType.isAssignableTo(targetType)) {
        return firstElement;
      }
      else {
        GenericConverter converter = this.conversionService.getConverter(sourceElementType, targetType);
        if (converter == null) {
          throw new ConverterNotFoundException(sourceElementType, targetType);
        }
        return ConversionUtils.invokeConverter(converter, firstElement, sourceElementType, targetType);
      }
View Full Code Here

      return convertNullSource(sourceType, targetType);
    }
    if (targetType == TypeDescriptor.NULL) {
      return null;
    }
    GenericConverter converter = getConverter(sourceType, targetType);
    if (converter == null) {
      throw new ConverterNotFoundException(sourceType, targetType);
    }
    return ConversionUtils.invokeConverter(converter, source, sourceType, targetType);
  }
View Full Code Here

   * @param sourceType the source type to convert from
   * @param targetType the target type to convert to
   * @return the generic converter that will perform the conversion, or <code>null</code> if no suitable converter was found
   */
  protected GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) {
    GenericConverter converter = findConverterForClassPair(sourceType, targetType);
    if (converter != null) {
      return converter;
    }
    else {
      return getDefaultConverter(sourceType, targetType);
View Full Code Here

      LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>();
      classQueue.addFirst(sourceObjectType);
      while (!classQueue.isEmpty()) {
        Class<?> currentClass = classQueue.removeLast();
        Map<Class<?>, MatchableConverters> converters = getTargetConvertersForSource(currentClass);
        GenericConverter converter = getMatchingConverterForTarget(sourceType, targetType, converters);
        if (converter != null) {
          return converter;
        }
        Class<?>[] interfaces = currentClass.getInterfaces();
        for (Class<?> ifc : interfaces) {
          classQueue.addFirst(ifc);
        }
      }
      Map<Class<?>, MatchableConverters> objectConverters = getTargetConvertersForSource(Object.class);
      return getMatchingConverterForTarget(sourceType, targetType, objectConverters);
    }
    else {
      LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>();
      classQueue.addFirst(sourceObjectType);
      while (!classQueue.isEmpty()) {
        Class<?> currentClass = classQueue.removeLast();
        Map<Class<?>, MatchableConverters> converters = getTargetConvertersForSource(currentClass);
        GenericConverter converter = getMatchingConverterForTarget(sourceType, targetType, converters);
        if (converter != null) {
          return converter;
        }
        if (currentClass.isArray()) {
          Class<?> componentType = ClassUtils.resolvePrimitiveIfNecessary(currentClass.getComponentType());
View Full Code Here

      LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>();
      classQueue.addFirst(targetObjectType);
      while (!classQueue.isEmpty()) {
        Class<?> currentClass = classQueue.removeLast();
        MatchableConverters matchable = converters.get(currentClass);
        GenericConverter converter = matchConverter(matchable, sourceType, targetType);
        if (converter != null) {
          return converter;
        }
        Class<?>[] interfaces = currentClass.getInterfaces();
        for (Class<?> ifc : interfaces) {
          classQueue.addFirst(ifc);
        }
      }
      return matchConverter(converters.get(Object.class), sourceType, targetType);
    }
    else {
      LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>();
      classQueue.addFirst(targetObjectType);
      while (!classQueue.isEmpty()) {
        Class<?> currentClass = classQueue.removeLast();
        MatchableConverters matchable = converters.get(currentClass);
        GenericConverter converter = matchConverter(matchable, sourceType, targetType);
        if (converter != null) {
          return converter;
        }
        if (currentClass.isArray()) {
          Class<?> componentType = ClassUtils.resolvePrimitiveIfNecessary(currentClass.getComponentType());
View Full Code Here

      return sourceType.getAnnotation(annotationType) != null;
    }
   
    public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
      AnnotationConverterKey converterKey = new AnnotationConverterKey(sourceType.getAnnotation(annotationType), sourceType.getObjectType());
      GenericConverter converter = cachedPrinters.get(converterKey);
      if (converter == null) {
        Printer<?> printer = annotationFormatterFactory.getPrinter(converterKey.getAnnotation(), converterKey.getFieldType());
        converter = new PrinterConverter(fieldType, printer, FormattingConversionService.this);
        cachedPrinters.put(converterKey, converter);
      }
      return converter.convert(source, sourceType, targetType);
    }
View Full Code Here

      return targetType.getAnnotation(annotationType) != null;
    }
   
    public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
      AnnotationConverterKey converterKey = new AnnotationConverterKey(targetType.getAnnotation(annotationType), targetType.getObjectType());
      GenericConverter converter = cachedParsers.get(converterKey);
      if (converter == null) {
        Parser<?> parser = annotationFormatterFactory.getParser(converterKey.getAnnotation(), converterKey.getFieldType());
        converter = new ParserConverter(fieldType, parser, FormattingConversionService.this);
        cachedParsers.put(converterKey, converter);
      }
      return converter.convert(source, sourceType, targetType);
    }
View Full Code Here

TOP

Related Classes of org.springframework.core.convert.converter.GenericConverter

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.