Author: rmannibucau
Date: Mon Dec 29 13:41:11 2014
New Revision: 1648339
URL: http://svn.apache.org/r1648339
Log:
handling inheritance of interfaces for decoration
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java?rev=1648339&r1=1648338&r2=1648339&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
Mon Dec 29 13:41:11 2014
@@ -27,6 +27,7 @@ import org.apache.webbeans.config.OpenWe
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.portable.AnnotatedElementFactory;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.Asserts;
import org.apache.webbeans.util.ClassUtil;
@@ -684,11 +685,41 @@ public class InterceptorResolutionServic
*/
private List<AnnotatedMethod>
getInterceptableBusinessMethods(AnnotatedType annotatedType)
{
- List<Method> interceptableMethods =
ClassUtil.getNonPrivateMethods(annotatedType.getJavaClass(), false);
+ Class<?> javaClass = annotatedType.getJavaClass();
+ List<Method> interceptableMethods =
ClassUtil.getNonPrivateMethods(javaClass, false);
List<AnnotatedMethod> interceptableAnnotatedMethods = new
ArrayList<AnnotatedMethod>();
- Set<AnnotatedMethod> annotatedMethods =
(Set<AnnotatedMethod>)webBeansContext.getAnnotatedElementFactory().getFilteredAnnotatedMethods(annotatedType);
+ AnnotatedElementFactory annotatedElementFactory =
webBeansContext.getAnnotatedElementFactory();
+ Set<AnnotatedMethod> annotatedMethods = (Set<AnnotatedMethod>)
annotatedElementFactory.getFilteredAnnotatedMethods(annotatedType);
+ if (!javaClass.isAnnotation() && javaClass.isInterface())
+ {
+ Set<Type> types = new
HashSet<Type>(annotatedType.getTypeClosure());
+ types.remove(javaClass);
+ types.remove(Object.class);
+
+ if (!types.isEmpty()) // AT only supports 1 parent and ignores
interface inheritance so add it manually here
+ {
+ annotatedMethods = new
HashSet<AnnotatedMethod>(annotatedMethods); // otherwise it is not mutable by
default
+ for (Type c : types)
+ {
+ if (!Class.class.isInstance(c))
+ {
+ continue;
+ }
+ Class parent = Class.class.cast(c);
+ AnnotatedType at =
annotatedElementFactory.getAnnotatedType(parent);
+ if (at == null)
+ {
+ at = annotatedElementFactory.newAnnotatedType(parent);
+ }
+ if (at != null)
+ {
+ annotatedMethods.addAll((Set<AnnotatedMethod>)
annotatedElementFactory.getFilteredAnnotatedMethods(at));
+ }
+ }
+ }
+ }
for (Method interceptableMethod : interceptableMethods)
{
for (AnnotatedMethod<?> annotatedMethod : annotatedMethods)
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1648339&r1=1648338&r2=1648339&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Mon Dec 29 13:41:11 2014
@@ -281,72 +281,89 @@ public final class ClassUtil
Class<?> clazz = topClass;
- while (clazz != null)
+ if (!clazz.isAnnotation() && clazz.isInterface())
{
- for (Method method : clazz.getDeclaredMethods())
+ addNonPrivateMethods(topClass, excludeFinalMethods, methodMap,
allMethods, clazz);
+ for (final Class<?> parent : clazz.getInterfaces())
{
- if (method.isBridge())
- {
- // we have no interest in generics bridge methods
- continue;
- }
+ addNonPrivateMethods(topClass, excludeFinalMethods, methodMap,
allMethods, parent);
+ }
+ }
+ else
+ {
+ while (clazz != null)
+ {
+ addNonPrivateMethods(topClass, excludeFinalMethods, methodMap,
allMethods, clazz);
+ clazz = clazz.getSuperclass();
+ }
+ }
+
+ return allMethods;
+ }
- final int modifiers = method.getModifiers();
+ private static void addNonPrivateMethods(Class<?> topClass, boolean
excludeFinalMethods,
+ Map<String, List<Method>>
methodMap, List<Method> allMethods,
+ Class<?> clazz)
+ {
+ for (Method method : clazz.getDeclaredMethods())
+ {
+ if (method.isBridge())
+ {
+ // we have no interest in generics bridge methods
+ continue;
+ }
- if (Modifier.isPrivate(modifiers) ||
Modifier.isStatic(modifiers))
- {
- continue;
- }
- if (excludeFinalMethods && Modifier.isFinal(modifiers))
- {
- continue;
- }
+ final int modifiers = method.getModifiers();
+
+ if (Modifier.isPrivate(modifiers) || Modifier.isStatic(modifiers))
+ {
+ continue;
+ }
+ if (excludeFinalMethods && Modifier.isFinal(modifiers))
+ {
+ continue;
+ }
- if ("finalize".equals(method.getName()))
+ if ("finalize".equals(method.getName()))
+ {
+ // we do not proxy finalize()
+ continue;
+ }
+
+ // check for package-private methods from a different package
+ if (!Modifier.isPublic(modifiers) &&
!Modifier.isProtected(modifiers))
+ {
+ // private already got handled above, so we only had to check
for not public nor protected
+ // we cannot see those methods if they are not in the same
package as the rootClazz
+ if
(!clazz.getPackage().getName().equals(topClass.getPackage().getName()))
{
- // we do not proxy finalize()
continue;
}
- // check for package-private methods from a different package
- if (!Modifier.isPublic(modifiers) &&
!Modifier.isProtected(modifiers))
- {
- // private already got handled above, so we only had to
check for not public nor protected
- // we cannot see those methods if they are not in the same
package as the rootClazz
- if
(!clazz.getPackage().getName().equals(topClass.getPackage().getName()))
- {
- continue;
- }
-
- }
+ }
- List<Method> methods = methodMap.get(method.getName());
- if (methods == null)
+ List<Method> methods = methodMap.get(method.getName());
+ if (methods == null)
+ {
+ methods = new ArrayList<Method>();
+ methods.add(method);
+ allMethods.add(method);
+ methodMap.put(method.getName(), methods);
+ }
+ else
+ {
+ if (isOverridden(methods, method))
{
- methods = new ArrayList<Method>();
- methods.add(method);
- allMethods.add(method);
- methodMap.put(method.getName(), methods);
+ // method is overridden in superclass, so do nothing
}
else
{
- if (isOverridden(methods, method))
- {
- // method is overridden in superclass, so do nothing
- }
- else
- {
- // method is not overridden, so add it
- methods.add(method);
- allMethods.add(method);
- }
+ // method is not overridden, so add it
+ methods.add(method);
+ allMethods.add(method);
}
}
-
- clazz = clazz.getSuperclass();
}
-
- return allMethods;
}
/**