You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/06/27 19:16:26 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/jasper/servlet JspServlet.java
costin 00/06/27 10:16:26
Modified: src/share/org/apache/jasper/compiler Compiler.java
src/share/org/apache/jasper/servlet JspServlet.java
Log:
Few more cosmetic changes. The goal is to simplify jasper and clarify the interfaces.
- Compiler is now a normal class instead of abstract. The only abstract method is
isOutDated, and it can be overrident if needed - but the outdated check can be made outside
compiler. That will also allow to have the mangler as a separate class( simpler) .
- in JspServlet, there is no need to keep 2 hashtable keyed by JspURI, one containing
the classes and one containing a struct. We can just keep the class in the struct.
- in JspServlet, copied the isOutDated check - it will be invoked early, before the
compiler is created - thus avoid a lot of allocation if the class is not outdated.
None of the changes should have negative impact - if it does then probably it's better
to fix ( and understand what happens - I think it's better to have a bug we can fix than
code that works but we don't know why )
Revision Changes Path
1.18 +7 -5 jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java
Index: Compiler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Compiler.java 2000/06/15 00:26:43 1.17
+++ Compiler.java 2000/06/27 17:16:22 1.18
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v 1.17 2000/06/15 00:26:43 costin Exp $
- * $Revision: 1.17 $
- * $Date: 2000/06/15 00:26:43 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v 1.18 2000/06/27 17:16:22 costin Exp $
+ * $Revision: 1.18 $
+ * $Date: 2000/06/27 17:16:22 $
*
* ====================================================================
*
@@ -85,7 +85,7 @@
* @author Anil K. Vijendran
* @author Mandar Raje
*/
-public abstract class Compiler {
+public class Compiler {
protected JavaCompiler javac;
protected Mangler mangler;
protected JspCompilationContext ctxt;
@@ -286,7 +286,9 @@
* subclasses of Compiler. This is used by the compile method
* to do all the compilation.
*/
- public abstract boolean isOutDated();
+ public boolean isOutDated() {
+ return true;
+ }
/**
* Set java compiler info
1.2 +43 -61 jakarta-tomcat/src/share/org/apache/jasper/servlet/JspServlet.java
Index: JspServlet.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/servlet/JspServlet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JspServlet.java 2000/06/23 21:37:32 1.1
+++ JspServlet.java 2000/06/27 17:16:25 1.2
@@ -97,6 +97,8 @@
Servlet theServlet;
String jspUri;
boolean isErrorPage;
+ // ServletWrapper will set this
+ Class servletClass;
JspServletWrapper(String jspUri, boolean isErrorPage) {
this.jspUri = jspUri;
@@ -105,9 +107,8 @@
}
private void load() throws JasperException, ServletException {
- try {
- Class servletClass = (Class) loadedJSPs.get(jspUri);
-
+ try {
+ // Class servletClass = (Class) loadedJSPs.get(jspUri);
// This is to maintain the original protocol.
destroy();
@@ -204,7 +205,7 @@
protected ServletContext context = null;
protected Hashtable jsps = new Hashtable();
- protected Hashtable loadedJSPs = new Hashtable();
+ // protected Hashtable loadedJSPs = new Hashtable();
protected ServletConfig config;
protected JasperLoader loader;
protected Options options;
@@ -295,52 +296,6 @@
}
-// final void unknownException(HttpServletResponse response,
-// Throwable t)
-// {
-// PrintWriter writer = new PrintWriter(System.err, true);
-// if (options.getSendErrorToClient()) {
-// try {
-// response.setContentType ("text/html");
-// writer = response.getWriter ();
-// } catch (IOException ioex) {
-// writer = new PrintWriter(System.err, true);
-// }
-// }
-// writer.println(Constants.getString("jsp.error.unknownException"));
-
-// if (options.getSendErrorToClient()) {
-// writer.println("<pre>");
-// }
-
-// if (t instanceof JasperException) {
-// Throwable x = ((JasperException) t).getRootCause();
-// (x != null ? x : t).printStackTrace (writer);
-// } else {
-// t.printStackTrace (writer);
-// }
-
-// if (options.getSendErrorToClient()) {
-// writer.println("</pre>");
-// }
-
-// if (!options.getSendErrorToClient()) {
-// try {
-// String message = t.getMessage ();
-// if (message == null)
-// message = "No detailed message";
-// try {
-// response.sendError(HttpServletResponse.
-// SC_INTERNAL_SERVER_ERROR,
-// message);
-// } catch (IllegalStateException ise) {
-// Constants.jasperLog.log(message, t, Logger.ERROR);
-// }
-// } catch (IOException ex) {
-// }
-// }
-// }
-
boolean preCompile(HttpServletRequest request)
throws ServletException
{
@@ -446,13 +401,13 @@
* @param classpath explicitly set the JSP compilation path.
* @return true if JSP files is newer
*/
- boolean loadJSP(String name, String classpath,
+ boolean loadJSP(String jspUri, String classpath,
boolean isErrorPage, HttpServletRequest req, HttpServletResponse res)
throws JasperException, FileNotFoundException
{
// Loader knows how to set the right priviledges, and call
// doLoadeJsp
- return loader.loadJSP( this, name, classpath, isErrorPage, req, res );
+ return loader.loadJSP( this,jspUri, classpath, isErrorPage, req, res );
}
/* Check if we need to reload a JSP page.
@@ -462,14 +417,18 @@
* @param classpath explicitly set the JSP compilation path.
* @return true if JSP files is newer
*/
- protected boolean doLoadJSP(String name, String classpath,
+ protected boolean doLoadJSP(String jspUri, String classpath,
boolean isErrorPage, HttpServletRequest req, HttpServletResponse res)
throws JasperException, FileNotFoundException
{
- Class jspClass = (Class) loadedJSPs.get(name);
- boolean firstTime = jspClass == null;
+ JspServletWrapper jsw=(JspServletWrapper) jsps.get(jspUri);
+ if( jsw==null ) {
+ throw new JasperException("Can't happen - JspServletWrapper=null");
+ }
+ // Class jspClass = (Class) loadedJSPs.get(jspUri);
+ boolean firstTime = jsw.servletClass == null;
JspCompilationContext ctxt = new JspEngineContext(loader, classpath,
- context, name,
+ context, jspUri,
isErrorPage, options,
req, res);
boolean outDated = false;
@@ -478,9 +437,10 @@
try {
outDated = compiler.compile();
- if ( (jspClass == null) || (compiler.isOutDated()) ) {
+ if ( (jsw.servletClass == null) || (compiler.isOutDated()) ) {
synchronized ( this ) {
- if ((jspClass == null) || (compiler.isOutDated() )) {
+ if ((jsw.servletClass == null) ||
+ (compiler.isOutDated() )) {
outDated = compiler.compile();
}
}
@@ -495,21 +455,43 @@
}
// Reload only if it's outdated
- if((jspClass == null) || outDated) {
+ if((jsw.servletClass == null) || outDated) {
try {
if( null ==ctxt.getServletClassName() ) {
compiler.computeServletClassName();
}
- jspClass = loader.loadClass(ctxt.getFullClassName());
+ jsw.servletClass = loader.loadClass(ctxt.getFullClassName());
//loadClass(ctxt.getFullClassName(), true);
} catch (ClassNotFoundException cex) {
throw new JasperException(Constants.getString("jsp.error.unable.load"),
cex);
}
- loadedJSPs.put(name, jspClass);
+
+ // loadedJSPs.put(jspUri, jspClass);
}
return outDated;
+ }
+
+ /**
+ * Determines whether the current JSP class is older than the JSP file
+ * from whence it came
+ */
+ public boolean isOutDated(File jsp, JspCompilationContext ctxt,
+ JspMangler mangler ) {
+ File jspReal = null;
+ boolean outDated;
+
+ jspReal = new File(ctxt.getRealPath(jsp.getPath()));
+
+ File classFile = new File(mangler.getClassFileName());
+ if (classFile.exists()) {
+ outDated = classFile.lastModified() < jspReal.lastModified();
+ } else {
+ outDated = true;
+ }
+
+ return outDated;
}
}