Examples of GenericConverter


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

      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

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

   * @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

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

      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

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

      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

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

      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

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

      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

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

    @SuppressWarnings("unchecked")
    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

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

    @SuppressWarnings("unchecked")
    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

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

      throw new IllegalArgumentException("The targetType to convert to cannot be null");
    }
    if (sourceType == null) {
      return true;
    }
    GenericConverter converter = getConverter(sourceType, targetType);
    return (converter != null);
  }
View Full Code Here

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

    }
    if (source != null && !sourceType.getObjectType().isInstance(source)) {
      throw new IllegalArgumentException("The source to convert from must be an instance of " +
          sourceType + "; instead it was a " + source.getClass().getName());
    }
    GenericConverter converter = getConverter(sourceType, targetType);
    if (converter != null) {
      Object result = ConversionUtils.invokeConverter(converter, source, sourceType, targetType);
      return handleResult(sourceType, targetType, result);
    }
    else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.