- Patch submitted by Bill Burke (who thinks annotations should occur for JSPs) to...
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 1 Sep 2006 14:17:58 +0000 (14:17 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 1 Sep 2006 14:17:58 +0000 (14:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@439330 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/servlet/JspServletWrapper.java

index 942e854..d1f98dd 100644 (file)
@@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.tagext.TagInfo;
 
+import org.apache.AnnotationProcessor;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jasper.JasperException;
@@ -146,10 +147,17 @@ public class JspServletWrapper {
                     try {
                         servletClass = ctxt.load();
                         theServlet = (Servlet) servletClass.newInstance();
-                    } catch( IllegalAccessException ex1 ) {
-                        throw new JasperException( ex1 );
-                    } catch( InstantiationException ex ) {
-                        throw new JasperException( ex );
+                        AnnotationProcessor annotationProcessor = (AnnotationProcessor) config.getServletContext().getAttribute(AnnotationProcessor.class.getName());
+                        if (annotationProcessor != null) {
+                           annotationProcessor.processAnnotations(theServlet);
+                           annotationProcessor.postConstruct(theServlet);
+                        }
+                    } catch (IllegalAccessException e) {
+                        throw new JasperException(e);
+                    } catch (InstantiationException e) {
+                        throw new JasperException(e);
+                    } catch (Exception e) {
+                        throw new JasperException(e);
                     }
                     
                     theServlet.init(config);
@@ -402,6 +410,16 @@ public class JspServletWrapper {
     public void destroy() {
         if (theServlet != null) {
             theServlet.destroy();
+            AnnotationProcessor annotationProcessor = (AnnotationProcessor) config.getServletContext().getAttribute(AnnotationProcessor.class.getName());
+            if (annotationProcessor != null) {
+                try {
+                    annotationProcessor.preDestroy(theServlet);
+                } catch (Exception e) {
+                    // Log any exception, since it can't be passed along
+                    log.error(Localizer.getMessage("jsp.error.file.not.found",
+                           e.getMessage()), e);
+                }
+            }
         }
     }