You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2009/11/18 21:28:37 UTC
svn commit: r881923 - in
/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans:
event/ObserverMethodImpl.java util/AnnotationUtil.java
Author: struberg
Date: Wed Nov 18 20:28:36 2009
New Revision: 881923
URL: http://svn.apache.org/viewvc?rev=881923&view=rev
Log:
OWB-140 finally implement getObservedType()
Modified:
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=881923&r1=881922&r2=881923&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java Wed Nov 18 20:28:36 2009
@@ -116,7 +116,7 @@
observedQualifiers.add(qualifier);
}
- this.observedEventType = null; //X TODO
+ this.observedEventType = AnnotationUtil.getTypeOfParameterWithGivenAnnotation(observerMethod, Observes.class);
this.phase = EventUtil.getObserverMethodTransactionType(observerMethod);
}
@@ -140,7 +140,7 @@
{
observedQualifiers.add(qualifier);
}
- this.observedEventType = null; //X TODO
+ this.observedEventType = observedEventType;
this.phase = EventUtil.getObserverMethodTransactionType(observerMethod); //X TODO might be overriden via XML?
}
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java?rev=881923&r1=881922&r2=881923&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java Wed Nov 18 20:28:36 2009
@@ -275,7 +275,7 @@
return (Class<?>) type;
}
}
-
+
/**
* Gets the method first found parameter qualifiers.
*
@@ -325,7 +325,47 @@
result = new Annotation[0];
return result;
}
-
+
+ /**
+ * Get the Type of the method parameter which has the given annotation
+ * @param method which need to be scanned
+ * @param clazz the annotation to scan the method parameters for
+ * @return the Type of the method parameter which has the given annotation, or <code>null</code> if not found.
+ */
+ public static Type getTypeOfParameterWithGivenAnnotation(Method method, Class<? extends Annotation> clazz)
+ {
+ Asserts.assertNotNull(method, "Method argument can not be null");
+ Asserts.assertNotNull(clazz, "Clazz argument can not be null");
+
+ Annotation[][] parameterAnns = method.getParameterAnnotations();
+ Type result = null;
+
+ int index = 0;
+ for (Annotation[] parameters : parameterAnns)
+ {
+ boolean found = false;
+ for (Annotation param : parameters)
+ {
+ Class<? extends Annotation> btype = param.annotationType();
+ if (btype.equals(clazz))
+ {
+ found = true;
+ continue;
+ }
+ }
+
+ if (found)
+ {
+ result = method.getParameterTypes()[index];
+ break;
+ }
+
+ index++;
+
+ }
+ return result;
+ }
+
/**
* Gets the method first found parameter annotation with given type.
*