tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r428729 - in /tomcat/tc6.0.x/trunk/java/org/apache: catalina/ catalina/core/ jasper/ jasper/compiler/ jasper/runtime/
Date Fri, 04 Aug 2006 14:04:42 GMT
Author: remm
Date: Fri Aug  4 07:04:42 2006
New Revision: 428729

URL: http://svn.apache.org/viewvc?rev=428729&view=rev
Log:
- Use the classname as the servlet context attribute name for the annotation processor.
- Fix init of the naming context used by the annotation processor.
- Jasper will now use the annotation processor from the servlet context.
- Remove the ignore annotation compile time parameter for Jasper, which was a temporary hack.

Added:
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/AnnotationHelper.java   (with props)
Removed:
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/AnnotationProcessor.java
Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/Globals.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/Options.java
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Generator.java
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/TagHandlerPool.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/Globals.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/Globals.java?rev=428729&r1=428728&r2=428729&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/Globals.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/Globals.java Fri Aug  4 07:04:42 2006
@@ -88,14 +88,6 @@
 
 
     /**
-     * The servlet context attribute under which we store the annotation
-     * processor that is used by the JSP engine.
-     */
-    public static final String ANNOTATION_PROCESSOR_ATTR =
-        "org.apache.catalina.annotation_processor";
-
-
-    /**
      * The request attribute under which we forward a Java exception
      * (as an object of type Throwable) to an error page.
      */

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java?rev=428729&r1=428728&r2=428729&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java Fri Aug  4 07:04:42
2006
@@ -4168,20 +4168,6 @@
             }
         }
         
-        // Initialize annotation processor
-        if (ok && !getIgnoreAnnotations()) {
-            if (annotationProcessor == null) {
-                if (isUseNaming() && namingContextListener != null) {
-                    annotationProcessor = 
-                        new DefaultAnnotationProcessor(namingContextListener.getEnvContext());
-                } else {
-                    annotationProcessor = new DefaultAnnotationProcessor(null);
-                }
-            }
-            getServletContext().setAttribute
-                (Globals.ANNOTATION_PROCESSOR_ATTR, annotationProcessor);
-        }
-
         // Standard container startup
         if (log.isDebugEnabled())
             log.debug("Processing standard container startup");
@@ -4303,11 +4289,20 @@
         // Set annotation processing parameter for Jasper (unfortunately, since
         // this can be configured in many places and not just in /WEB-INF/web.xml,
         // there are not many solutions)
-        if (ignoreAnnotations) {
-            Wrapper jspServlet = (Wrapper) findChild(Constants.JSP_SERVLET_NAME);
-            jspServlet.addInitParameter("org.apache.jasper.IGNORE_ANNOTATIONS", "true");
+        // Initialize annotation processor
+        if (ok && !getIgnoreAnnotations()) {
+            if (annotationProcessor == null) {
+                if (isUseNaming() && namingContextListener != null) {
+                    annotationProcessor = 
+                        new DefaultAnnotationProcessor(namingContextListener.getEnvContext());
+                } else {
+                    annotationProcessor = new DefaultAnnotationProcessor(null);
+                }
+            }
+            getServletContext().setAttribute
+                (AnnotationProcessor.class.getName(), annotationProcessor);
         }
-        
+
         try {
             
             // Create context attributes that will be required

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java?rev=428729&r1=428728&r2=428729&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java Fri Aug  4 07:04:42
2006
@@ -174,11 +174,6 @@
      */
     private boolean xpoweredBy;
     
-    /**
-     * Should annotations be ignored?
-     */
-    private boolean ignoreAnnotations = false;
-    
     public String getProperty(String name ) {
         return settings.getProperty( name );
     }
@@ -250,13 +245,6 @@
     }
     
     /**
-     * Should annotations on tags be ignored?
-     */
-    public boolean getIgnoreAnnotations() {
-        return ignoreAnnotations;
-    }
-
-    /**
      * Is the generation of SMAP info for JSR45 debuggin suppressed?
      */
     public boolean isSmapSuppressed() {
@@ -396,11 +384,6 @@
         String validating=config.getInitParameter( "validating");
         if( "false".equals( validating )) ParserUtils.validating=false;
         
-        String annotations = config.getInitParameter("org.apache.jasper.IGNORE_ANNOTATIONS");
-        if ("true".equals(annotations)) {
-            ignoreAnnotations = true;
-        }
-
         String keepgen = config.getInitParameter("keepgenerated");
         if (keepgen != null) {
             if (keepgen.equalsIgnoreCase("true")) {

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java?rev=428729&r1=428728&r2=428729&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java Fri Aug  4 07:04:42 2006
@@ -159,7 +159,6 @@
     private boolean smapSuppressed = true;
     private boolean smapDumped = false;
     private boolean caching = true;
-    private boolean ignoreAnnotations = false;
     private Map cache = new HashMap();
 
     private String compiler = null;
@@ -589,20 +588,6 @@
      */
     public void setCompilerSourceVM(String vm) {
         compilerSourceVM = vm;
-    }
-
-    /**
-     * Should annotations on tags be ignored?
-     */
-    public boolean getIgnoreAnnotations() {
-        return ignoreAnnotations;
-    }
-
-    /**
-     * Should annotations on tags be ignored?
-     */
-    public void setIgnoreAnnotations(boolean ignoreAnnotations) {
-        this.ignoreAnnotations = ignoreAnnotations;
     }
 
     public TldLocationsCache getTldLocationsCache() {

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/Options.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/Options.java?rev=428729&r1=428728&r2=428729&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/Options.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/Options.java Fri Aug  4 07:04:42 2006
@@ -92,11 +92,6 @@
     public boolean getTrimSpaces();
 
     /**
-     * Should annotations on tags be ignored?
-     */
-    public boolean getIgnoreAnnotations();
-
-    /**
      * Class ID for use in the plugin tag when the browser is IE. 
      */
     public String getIeClassId();

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Generator.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Generator.java?rev=428729&r1=428728&r2=428729&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Generator.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Generator.java Fri Aug  4 07:04:42
2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2004-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -63,6 +63,7 @@
  * 
  * Tomcat 6.x
  * @author Jacob Hookom
+ * @author Remy Maucherat
  */
 
 class Generator {
@@ -70,6 +71,7 @@
     private static final Class[] OBJECT_CLASS = { Object.class };
 
     private static final String VAR_EXPRESSIONFACTORY = "_el_expressionfactory";
+    private static final String VAR_ANNOTATIONPROCESSOR = "_jsp_annotationprocessor";
 
     private ServletWriter out;
 
@@ -405,7 +407,16 @@
             out.print("getServletConfig()");
         }
         out.println(".getServletContext()).getExpressionFactory();");
-        
+
+        out.printin(VAR_ANNOTATIONPROCESSOR);
+        out.print(" = (org.apache.AnnotationProcessor) ");
+        if (ctxt.isTagFile()) {
+            out.print("config");
+        } else {
+            out.print("getServletConfig()");
+        }
+        out.println(".getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());");
+
         out.popIndent();
         out.printil("}");
         out.println();
@@ -505,6 +516,9 @@
         out.printin("private javax.el.ExpressionFactory ");
         out.print(VAR_EXPRESSIONFACTORY);
         out.println(";");
+        out.printin("private org.apache.AnnotationProcessor ");
+        out.print(VAR_ANNOTATIONPROCESSOR);
+        out.println(";");
         out.println();
     }
 
@@ -2143,11 +2157,11 @@
                 out.print("new ");
                 out.print(tagHandlerClassName);
                 out.println("();");
-                if (!ctxt.getOptions().getIgnoreAnnotations()) {
-                    out.printin("org.apache.jasper.runtime.AnnotationProcessor.postConstruct(");
-                    out.print(tagHandlerVar);
-                    out.println(");");
-                }
+                out.printin("org.apache.jasper.runtime.AnnotationHelper.postConstruct(");
+                out.print(VAR_ANNOTATIONPROCESSOR);
+                out.print(", ");
+                out.print(tagHandlerVar);
+                out.println(");");
             }
 
             // includes setting the context
@@ -2293,21 +2307,21 @@
                 } else {
                     out.printin(tagHandlerVar);
                     out.println(".release();");
-                    if (!ctxt.getOptions().getIgnoreAnnotations()) {
-                        out.printil("try {");
-                        out.pushIndent();
-                        out.printin("org.apache.jasper.runtime.AnnotationProcessor.preDestroy(");
-                        out.print(tagHandlerVar);
-                        out.println(");");
-                        out.popIndent();
-                        out.printil("} catch (Exception e) {");
-                        out.pushIndent();
-                        out.printin("log(\"Error processing preDestroy on tag instance of
\" +");
-                        out.print(tagHandlerVar);
-                        out.println(".getClass().getName());");
-                        out.popIndent();
-                        out.printil("}");
-                    }
+                    out.printil("try {");
+                    out.pushIndent();
+                    out.printin("org.apache.jasper.runtime.AnnotationHelper.preDestroy(");
+                    out.print(VAR_ANNOTATIONPROCESSOR);
+                    out.print(", ");
+                    out.print(tagHandlerVar);
+                    out.println(");");
+                    out.popIndent();
+                    out.printil("} catch (Exception e) {");
+                    out.pushIndent();
+                    out.printin("log(\"Error processing preDestroy on tag instance of \"
+");
+                    out.print(tagHandlerVar);
+                    out.println(".getClass().getName());");
+                    out.popIndent();
+                    out.printil("}");
                 }
             }
             if (isTagFile || isFragment) {
@@ -2350,21 +2364,21 @@
             } else {
                 out.printin(tagHandlerVar);
                 out.println(".release();");
-                if (!ctxt.getOptions().getIgnoreAnnotations()) {
-                    out.printil("try {");
-                    out.pushIndent();
-                    out.printin("org.apache.jasper.runtime.AnnotationProcessor.preDestroy(");
-                    out.print(tagHandlerVar);
-                    out.println(");");
-                    out.popIndent();
-                    out.printil("} catch (Exception e) {");
-                    out.pushIndent();
-                    out.printin("log(\"Error processing preDestroy on tag instance of \"
+");
-                    out.print(tagHandlerVar);
-                    out.println(".getClass().getName());");
-                    out.popIndent();
-                    out.printil("}");
-                }
+                out.printil("try {");
+                out.pushIndent();
+                out.printin("org.apache.jasper.runtime.AnnotationHelper.preDestroy(");
+                out.print(VAR_ANNOTATIONPROCESSOR);
+                out.print(", ");
+                out.print(tagHandlerVar);
+                out.println(");");
+                out.popIndent();
+                out.printil("} catch (Exception e) {");
+                out.pushIndent();
+                out.printin("log(\"Error processing preDestroy on tag instance of \" +");
+                out.print(tagHandlerVar);
+                out.println(".getClass().getName());");
+                out.popIndent();
+                out.printil("}");
             }
 
             if (n.implementsTryCatchFinally()) {
@@ -2405,11 +2419,11 @@
             out.println("();");
 
             // Resource injection
-            if (!ctxt.getOptions().getIgnoreAnnotations()) {
-                out.printin("org.apache.jasper.runtime.AnnotationProcessor.postConstruct(");
-                out.print(tagHandlerVar);
-                out.println(");");
-            }
+            out.printin("org.apache.jasper.runtime.AnnotationHelper.postConstruct(");
+            out.print(VAR_ANNOTATIONPROCESSOR);
+            out.print(", ");
+            out.print(tagHandlerVar);
+            out.println(");");
             
             generateSetters(n, tagHandlerVar, handlerInfo, true);
 
@@ -2455,11 +2469,11 @@
             syncScriptingVars(n, VariableInfo.AT_END);
 
             // Resource injection
-            if (!ctxt.getOptions().getIgnoreAnnotations()) {
-                out.printin("org.apache.jasper.runtime.AnnotationProcessor.preDestroy(");
-                out.print(tagHandlerVar);
-                out.println(");");
-            }
+            out.printin("org.apache.jasper.runtime.AnnotationHelper.preDestroy(");
+            out.print(VAR_ANNOTATIONPROCESSOR);
+            out.print(", ");
+            out.print(tagHandlerVar);
+            out.println(");");
 
             n.setEndJavaLine(out.getJavaLine());
         }

Added: tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/AnnotationHelper.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/AnnotationHelper.java?rev=428729&view=auto
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/AnnotationHelper.java (added)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/AnnotationHelper.java Fri Aug  4 07:04:42
2006
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jasper.runtime;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.naming.NamingException;
+
+import org.apache.AnnotationProcessor;
+
+
+/**
+ * Verify the annotation and Process it.
+ *
+ * @author Fabien Carrion
+ * @author Remy Maucherat
+ * @version $Revision: 303236 $, $Date: 2006-03-09 16:46:52 -0600 (Thu, 09 Mar 2006) $
+ */
+public class AnnotationHelper {
+
+    
+    /**
+     * Call postConstruct method on the specified instance. Note: In Jasper, this
+     * calls naming resources injection as well.
+     */
+    public static void postConstruct(AnnotationProcessor processor, Object instance)
+        throws IllegalAccessException, InvocationTargetException, NamingException {
+        if (processor != null) {
+            processor.processAnnotations(instance);
+            processor.postConstruct(instance);
+        }
+    }
+    
+    
+    /**
+     * Call preDestroy method on the specified instance.
+     */
+    public static void preDestroy(AnnotationProcessor processor, Object instance)
+        throws IllegalAccessException, InvocationTargetException {
+        if (processor != null) {
+            processor.preDestroy(instance);
+        }
+    }
+    
+
+}

Propchange: tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/AnnotationHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/TagHandlerPool.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/TagHandlerPool.java?rev=428729&r1=428728&r2=428729&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/TagHandlerPool.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/TagHandlerPool.java Fri Aug  4 07:04:42
2006
@@ -16,10 +16,11 @@
 
 package org.apache.jasper.runtime;
 
+import javax.servlet.ServletConfig;
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.tagext.Tag;
-import javax.servlet.ServletConfig;
 
+import org.apache.AnnotationProcessor;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jasper.Constants;
@@ -40,7 +41,7 @@
     
     // index of next available tag handler
     private int current;
-    private boolean ignoreAnnotations = false;
+    protected AnnotationProcessor annotationProcessor = null;
 
     public static TagHandlerPool getTagHandlerPool( ServletConfig config) {
         TagHandlerPool result=null;
@@ -76,10 +77,8 @@
         }
         this.handlers = new Tag[maxSize];
         this.current = -1;
-        String annotations = getOption(config, "org.apache.jasper.IGNORE_ANNOTATIONS", null);
-        if ("true".equals(annotations)) {
-            ignoreAnnotations = true;
-        }
+        this.annotationProcessor = 
+            (AnnotationProcessor) config.getServletContext().getAttribute(AnnotationProcessor.class.getName());
     }
 
     /**
@@ -124,9 +123,7 @@
         // wait for us to construct a tag for this thread.
         try {
             Tag instance = (Tag) handlerClass.newInstance();
-            if (!ignoreAnnotations) {
-                AnnotationProcessor.postConstruct(instance);
-            }
+            AnnotationHelper.postConstruct(annotationProcessor, instance);
             return instance;
         } catch (Exception e) {
             throw new JspException(e.getMessage(), e);
@@ -149,9 +146,9 @@
         }
         // There is no need for other threads to wait for us to release
         handler.release();
-        if (!ignoreAnnotations) {
+        if (annotationProcessor != null) {
             try {
-                AnnotationProcessor.preDestroy(handler);
+                AnnotationHelper.preDestroy(annotationProcessor, handler);
             } catch (Exception e) {
                 log.warn("Error processing preDestroy on tag instance of " 
                         + handler.getClass().getName(), e);
@@ -166,9 +163,9 @@
     public synchronized void release() {
         for (int i = current; i >= 0; i--) {
             handlers[i].release();
-            if (!ignoreAnnotations) {
+            if (annotationProcessor != null) {
                 try {
-                    AnnotationProcessor.preDestroy(handlers[i]);
+                    AnnotationHelper.preDestroy(annotationProcessor, handlers[i]);
                 } catch (Exception e) {
                     log.warn("Error processing preDestroy on tag instance of " 
                             + handlers[i].getClass().getName(), e);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message