You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dk...@apache.org on 2011/11/14 20:17:57 UTC
svn commit: r1201829 - in /camel/branches/camel-2.8.x: ./
camel-core/src/main/java/org/apache/camel/component/bean/
camel-core/src/test/java/org/apache/camel/component/bean/
camel-core/src/test/java/org/apache/camel/component/bean/issues/
Author: dkulp
Date: Mon Nov 14 19:17:57 2011
New Revision: 1201829
URL: http://svn.apache.org/viewvc?rev=1201829&view=rev
Log:
Merged revisions 1183614 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r1183614 | davsclaus | 2011-10-15 06:13:26 -0400 (Sat, 15 Oct 2011) | 1 line
CAMEL-4541: Bean component supports binding to private class beans by fallback to use interfaces. Thanks to Mathieu for the patch.
........
Added:
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/component/bean/BeanPrivateClassWithInterfaceMethodTest.java
- copied unchanged from r1183614, camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanPrivateClassWithInterfaceMethodTest.java
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/component/bean/issues/PrivateClasses.java
- copied unchanged from r1183614, camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/PrivateClasses.java
Modified:
camel/branches/camel-2.8.x/ (props changed)
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
Propchange: camel/branches/camel-2.8.x/
('svn:mergeinfo' removed)
Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=1201829&r1=1201828&r2=1201829&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Mon Nov 14 19:17:57 2011
@@ -220,7 +220,18 @@ public class BeanInfo {
LOG.trace("Introspecting class: {}", clazz);
- Method[] methods = clazz.getDeclaredMethods();
+ // if the class is not public then fallback and use interface methods if possible
+ // this allow Camel to invoke private beans which implements interfaces
+ List<Method> methods = Arrays.asList(clazz.getDeclaredMethods());
+ if (!Modifier.isPublic(clazz.getModifiers())) {
+ LOG.trace("Preferring interface methods as class: {} is not public accessible", clazz);
+ List<Method> interfaceMethods = getInterfaceMethods(clazz);
+
+ // still keep non-accessible class methods to provide more specific Exception if method is non-accessible
+ interfaceMethods.addAll(methods);
+ methods = interfaceMethods;
+ }
+
for (Method method : methods) {
boolean valid = isValidMethod(clazz, method);
LOG.trace("Method: {} is valid: {}", method, valid);
@@ -307,9 +318,8 @@ public class BeanInfo {
return answer;
}
- @SuppressWarnings("unchecked")
- protected MethodInfo createMethodInfo(Class clazz, Method method) {
- Class[] parameterTypes = method.getParameterTypes();
+ protected MethodInfo createMethodInfo(Class<?> clazz, Method method) {
+ Class<?>[] parameterTypes = method.getParameterTypes();
List<Annotation>[] parametersAnnotations = collectParameterAnnotations(clazz, method);
List<ParameterInfo> parameters = new ArrayList<ParameterInfo>();
@@ -324,7 +334,7 @@ public class BeanInfo {
}
for (int i = 0; i < size; i++) {
- Class parameterType = parameterTypes[i];
+ Class<?> parameterType = parameterTypes[i];
Annotation[] parameterAnnotations = parametersAnnotations[i].toArray(new Annotation[parametersAnnotations[i].size()]);
Expression expression = createParameterUnmarshalExpression(clazz, method, parameterType, parameterAnnotations);
hasCustomAnnotation |= expression != null;
@@ -464,7 +474,7 @@ public class BeanInfo {
Message in = exchange.getIn();
Object body = in.getBody();
if (body != null) {
- Class bodyType = body.getClass();
+ Class<?> bodyType = body.getClass();
if (LOG.isTraceEnabled()) {
LOG.trace("Matching for method with a single parameter that matches type: {}", bodyType.getCanonicalName());
}
@@ -685,6 +695,17 @@ public class BeanInfo {
return null;
}
+
+ private static List<Method> getInterfaceMethods(Class<?> clazz) {
+ final List<Method> answer = new ArrayList<Method>();
+ for (Class<?> interfaceClazz : clazz.getInterfaces()) {
+ for (Method interfaceMethod : interfaceClazz.getDeclaredMethods()) {
+ answer.add(interfaceMethod);
+ }
+ }
+
+ return answer;
+ }
private static void removeAllSetterOrGetterMethods(List<MethodInfo> methods) {
Iterator<MethodInfo> it = methods.iterator();
@@ -735,7 +756,7 @@ public class BeanInfo {
String types = ObjectHelper.between(methodName, "(", ")");
if (types != null) {
// we must qualify based on types to match method
- Iterator it = ObjectHelper.createIterator(types);
+ Iterator<?> it = ObjectHelper.createIterator(types);
for (int i = 0; i < method.getParameterTypes().length; i++) {
if (it.hasNext()) {
String qualifyType = (String) it.next();
@@ -820,10 +841,9 @@ public class BeanInfo {
*
* @return the methods.
*/
- @SuppressWarnings("unchecked")
public List<MethodInfo> getMethods() {
if (operations.isEmpty()) {
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
List<MethodInfo> methods = new ArrayList<MethodInfo>();