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);
}
}
}
Aggregations