Search in sources :

Example 71 with Converter

use of org.apache.camel.Converter in project camel by apache.

the class AnnotationTypeConverterLoader method loadConverterMethods.

/**
     * Loads all of the converter methods for the given type
     */
protected void loadConverterMethods(TypeConverterRegistry registry, Class<?> type) {
    if (visitedClasses.contains(type)) {
        return;
    }
    visitedClasses.add(type);
    try {
        Method[] methods = type.getDeclaredMethods();
        CachingInjector<?> injector = null;
        for (Method method : methods) {
            // in two different jars (as is the case sometimes with specs).
            if (ObjectHelper.hasAnnotation(method, Converter.class, true)) {
                boolean allowNull = false;
                if (method.getAnnotation(Converter.class) != null) {
                    allowNull = method.getAnnotation(Converter.class).allowNull();
                }
                injector = handleHasConverterAnnotation(registry, type, injector, method, allowNull);
            } else if (ObjectHelper.hasAnnotation(method, FallbackConverter.class, true)) {
                boolean allowNull = false;
                if (method.getAnnotation(FallbackConverter.class) != null) {
                    allowNull = method.getAnnotation(FallbackConverter.class).allowNull();
                }
                injector = handleHasFallbackConverterAnnotation(registry, type, injector, method, allowNull);
            }
        }
        Class<?> superclass = type.getSuperclass();
        if (superclass != null && !superclass.equals(Object.class)) {
            loadConverterMethods(registry, superclass);
        }
    } catch (NoClassDefFoundError e) {
        boolean ignore = false;
        // does the class allow to ignore the type converter when having load errors
        if (ObjectHelper.hasAnnotation(type, Converter.class, true)) {
            if (type.getAnnotation(Converter.class) != null) {
                ignore = type.getAnnotation(Converter.class).ignoreOnLoadError();
            }
        }
        // if we should ignore then only log at debug level
        if (ignore) {
            LOG.debug("Ignoring converter type: " + type.getCanonicalName() + " as a dependent class could not be found: " + e, e);
        } else {
            LOG.warn("Ignoring converter type: " + type.getCanonicalName() + " as a dependent class could not be found: " + e, e);
        }
    }
}
Also used : FallbackConverter(org.apache.camel.FallbackConverter) FallbackConverter(org.apache.camel.FallbackConverter) Converter(org.apache.camel.Converter) TypeConverter(org.apache.camel.TypeConverter) Method(java.lang.reflect.Method)

Aggregations

Converter (org.apache.camel.Converter)71 TypeConverter (org.apache.camel.TypeConverter)11 FallbackConverter (org.apache.camel.FallbackConverter)10 InputStream (java.io.InputStream)8 ByteBuffer (java.nio.ByteBuffer)7 IOConverter (org.apache.camel.converter.IOConverter)7 InputSource (org.xml.sax.InputSource)6 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 List (java.util.List)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 StringReader (java.io.StringReader)4 ArrayList (java.util.ArrayList)4 FileInputStream (java.io.FileInputStream)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 SAXSource (javax.xml.transform.sax.SAXSource)3 MultiSearchRequest (org.elasticsearch.action.search.MultiSearchRequest)3 SearchRequest (org.elasticsearch.action.search.SearchRequest)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3