From 49ef972ec55b57a58249d59e126f96df745f23e0 Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 11 May 2010 15:48:36 +0000 Subject: [PATCH] https://issues.apache.org/bugzilla/show_bug.cgi?id=49235 Fix handlesTypes with annotations. The annotated class should be reported, not the annotation class. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@943151 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/catalina/startup/ContextConfig.java | 35 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/java/org/apache/catalina/startup/ContextConfig.java b/java/org/apache/catalina/startup/ContextConfig.java index 912825c17..f6858163e 100644 --- a/java/org/apache/catalina/startup/ContextConfig.java +++ b/java/org/apache/catalina/startup/ContextConfig.java @@ -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, Set> 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; -- 2.11.0