Author: markt
Date: Tue May 11 15:48:36 2010
New Revision: 943151
URL: http://svn.apache.org/viewvc?rev=943151&view=rev
Log:
https://issues.apache.org/bugzilla/show_bug.cgi?id=49235
Fix handlesTypes with annotations. The annotated class should be reported, not
the annotation class.
Modified:
tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=943151&r1=943150&r2=943151&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Tue May 11
15:48:36 2010
@@ -27,6 +27,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import java.lang.annotation.Annotation;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
@@ -1857,7 +1858,8 @@ public class ContextConfig
/**
* For classes packaged with the web application, the class and each
- * super class needs to be checked for a match with {...@link
HandlesTypes}.
+ * super class needs to be checked for a match with {...@link
HandlesTypes} or
+ * for an annotation that matches {...@link HandlesTypes}.
* @param javaClass
*/
protected void checkHandlesTypes(JavaClass javaClass) {
@@ -1882,9 +1884,28 @@ public class ContextConfig
return;
}
+ if (clazz.isAnnotation()) {
+ // Skip
+ return;
+ }
+
+ boolean match = false;
+
for (Map.Entry<Class<?>, Set<ServletContainerInitializer>> entry :
typeInitializerMap.entrySet()) {
- if (entry.getKey().isAssignableFrom(clazz)) {
+ if (entry.getKey().isAnnotation()) {
+ AnnotationEntry[] annotationEntries =
javaClass.getAnnotationEntries();
+ for (AnnotationEntry annotationEntry : annotationEntries) {
+ if (entry.getKey().getName().equals(
+ getClassName(annotationEntry.getAnnotationType()))) {
+ match = true;
+ break;
+ }
+ }
+ } else if (entry.getKey().isAssignableFrom(clazz)) {
+ match = true;
+ }
+ if (match) {
for (ServletContainerInitializer sci : entry.getValue()) {
initializerClassMap.get(sci).add(clazz);
}
@@ -1892,6 +1913,16 @@ public class ContextConfig
}
}
+ private static final String getClassName(String internalForm) {
+ if (!internalForm.startsWith("L")) {
+ return internalForm;
+ }
+
+ // Assume starts with L, ends with ; and uses / rather than .
+ return internalForm.substring(1,
+ internalForm.length() - 1).replace('/', '.');
+ }
+
protected void processAnnotationWebServlet(String className,
AnnotationEntry ae, WebXml fragment) {
String servletName = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]