You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ki...@apache.org on 2004/02/18 22:22:22 UTC
cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources messages.properties messages_es.properties messages_fr.properties messages_ja.properties
kinman 2004/02/18 13:22:22
Modified: jasper2/src/share/org/apache/jasper
EmbeddedServletOptions.java JspC.java Options.java
jasper2/src/share/org/apache/jasper/compiler Generator.java
jasper2/src/share/org/apache/jasper/resources
messages.properties messages_es.properties
messages_fr.properties messages_ja.properties
Log:
- Add some intellignece to the compiler for generating code for useBean action.
Generate direct instantiation (use new) when possible, use bean.instantiate
when bean name is specified, and for the case of invalid bean class, either
issue a translation time error (instead of javac error), or generate codes
to throw InstantiationException at runtime, depending on a new compiler
switch, errorOnUseBeanInvalidClassAttribute(defaulted to true). ;_)
Revision Changes Path
1.9 +26 -3 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/EmbeddedServletOptions.java
Index: EmbeddedServletOptions.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/EmbeddedServletOptions.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- EmbeddedServletOptions.java 19 Dec 2003 18:15:51 -0000 1.8
+++ EmbeddedServletOptions.java 18 Feb 2004 21:22:21 -0000 1.9
@@ -158,6 +158,8 @@
*/
private boolean genStringAsCharArray = false;
+ private boolean errorOnUseBeanInvalidClassAttribute = true;
+
/**
* I want to see my generated servlets. Which directory are they
* in?
@@ -334,6 +336,13 @@
return compiler;
}
+ public boolean getErrorOnUseBeanInvalidClassAttribute() {
+ return errorOnUseBeanInvalidClassAttribute;
+ }
+
+ public void setErrorOnUseBeanInvalidClassAttribute(boolean b) {
+ errorOnUseBeanInvalidClassAttribute = b;
+ }
public TldLocationsCache getTldLocationsCache() {
return tldLocationsCache;
@@ -535,6 +544,20 @@
} else {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.genchararray"));
+ }
+ }
+ }
+
+ String errBeanClass =
+ config.getInitParameter("errorOnUseBeanInvalidClassAttribute");
+ if (errBeanClass != null) {
+ if (errBeanClass.equalsIgnoreCase("true")) {
+ errorOnUseBeanInvalidClassAttribute = true;
+ } else if (errBeanClass.equalsIgnoreCase("false")) {
+ errorOnUseBeanInvalidClassAttribute = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.errBean"));
}
}
}
1.65 +12 -3 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java
Index: JspC.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -r1.64 -r1.65
--- JspC.java 21 Jan 2004 15:45:31 -0000 1.64
+++ JspC.java 18 Feb 2004 21:22:21 -0000 1.65
@@ -186,6 +186,7 @@
private boolean classDebugInfo = true;
private Vector extensions;
private Vector pages = new Vector();
+ private boolean errorOnUseBeanInvalidClassAttribute = true;
/**
* The java file encoding. Default
@@ -342,6 +343,14 @@
public boolean isXpoweredBy() {
return xpoweredBy;
+ }
+
+ public boolean getErrorOnUseBeanInvalidClassAttribute() {
+ return errorOnUseBeanInvalidClassAttribute;
+ }
+
+ public void setErrorOnUseBeanInvalidClassAttribute(boolean b) {
+ errorOnUseBeanInvalidClassAttribute = b;
}
public int getTagPoolSize() {
1.22 +10 -3 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/Options.java
Index: Options.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/Options.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Options.java 5 Feb 2004 23:02:18 -0000 1.21
+++ Options.java 18 Feb 2004 21:22:21 -0000 1.22
@@ -77,6 +77,13 @@
public interface Options {
/**
+ * Returns true if Jasper issues a compilation error instead of a runtime
+ * Instantiation error if the class attribute specified in useBean action
+ * is invalid.
+ */
+ public boolean getErrorOnUseBeanInvalidClassAttribute();
+
+ /**
* Are we keeping generated code around?
*/
public boolean getKeepGenerated();
1.219 +38 -15 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java
Index: Generator.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v
retrieving revision 1.218
retrieving revision 1.219
diff -u -r1.218 -r1.219
--- Generator.java 3 Feb 2004 08:27:43 -0000 1.218
+++ Generator.java 18 Feb 2004 21:22:21 -0000 1.219
@@ -1,4 +1,9 @@
/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+/*
* $Header$
* $Revision$
* $Date$
@@ -1246,20 +1251,38 @@
out.println(" not found within scope\");");
} else {
/*
- * Instantiate bean if not there
+ * Instantiate the bean if it is not in the specified scope.
*/
- String className;
- if (beanName != null) {
- if (beanName.isNamedAttribute()) {
- // If the value for beanName was specified via
- // jsp:attribute, first generate code to evaluate
- // that body.
- className =
- generateNamedAttributeValue(
- beanName.getNamedAttributeNode());
+ boolean generateNew = false;
+ if (beanName == null) {
+ try {
+ Class bean = ctxt.getClassLoader().loadClass(klass);
+ bean.newInstance();
+ generateNew = true;
+ } catch (Exception e) {
+ // Cannot instantiate the specified class
+ if (ctxt.getOptions().getErrorOnUseBeanInvalidClassAttribute()) {
+ err.jspError(n, "jsp.error.invalid.bean", klass);
+ }
+ }
+ }
+ if (!generateNew) {
+ String className;
+ if (beanName != null) {
+ if (beanName.isNamedAttribute()) {
+ // If the value for beanName was specified via
+ // jsp:attribute, first generate code to evaluate
+ // that body.
+ className =
+ generateNamedAttributeValue(
+ beanName.getNamedAttributeNode());
+ } else {
+ className =
+ attributeValue(beanName, false, String.class);
+ }
} else {
- className =
- attributeValue(beanName, false, String.class);
+ // Implies klass is not null
+ className = quote(klass);
}
out.printil("try {");
out.pushIndent();
1.140 +2 -1 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties
Index: messages.properties
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties,v
retrieving revision 1.139
retrieving revision 1.140
diff -u -r1.139 -r1.140
--- messages.properties 7 Jan 2004 00:37:47 -0000 1.139
+++ messages.properties 18 Feb 2004 21:22:21 -0000 1.140
@@ -404,3 +404,4 @@
jsp.error.prefix.refined=Attempt to redefine the prefix {0} to {1}, when it was already defined as {2} in the current scope.
jsp.error.nested_jsproot=Nested <jsp:root>
jsp.error.unbalanced.endtag=The end tag \"</{0}\" is unbalanced
+jsp.error.invalid.bean=The value for the useBean class attribute {0} is invalid.
1.47 +2 -1 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_es.properties
Index: messages_es.properties
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_es.properties,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- messages_es.properties 17 Jan 2004 02:38:32 -0000 1.46
+++ messages_es.properties 18 Feb 2004 21:22:21 -0000 1.47
@@ -405,3 +405,4 @@
jsp.error.prefix.refined=Intento de redefinir el prefijo {0} por {1}, cuando ya estaba definido como {2} en el �mbito en curso.
jsp.error.nested_jsproot=<jsp:root> anidado
jsp.error.unbalanced.endtag=El tgag final \"</{0}\" est� desequilibrado
+jsp.error.invalid.bean=
1.31 +2 -2 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_fr.properties
Index: messages_fr.properties
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_fr.properties,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- messages_fr.properties 4 Dec 2003 19:37:58 -0000 1.30
+++ messages_fr.properties 18 Feb 2004 21:22:21 -0000 1.31
@@ -298,4 +298,4 @@
jsp.error.jspoutput.doctypepulicsystem=
jsp.error.jspoutput.nonemptybody=
jsp.error.jspoutput.invalidUse=
-
+jsp.error.invalid.bean=
1.50 +2 -1 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_ja.properties
Index: messages_ja.properties
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_ja.properties,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- messages_ja.properties 14 Jan 2004 13:01:00 -0000 1.49
+++ messages_ja.properties 18 Feb 2004 21:22:21 -0000 1.50
@@ -401,3 +401,4 @@
jsp.error.prefix.refined=\u30d7\u30ea\u30d5\u30a3\u30c3\u30af\u30b9 {0} \u304c\u73fe\u5728\u306e\u30b9\u30b3\u30fc\u30d7\u4e2d\u3067\u65e2\u306b {2} \u3068\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u306e\u3067 {1} \u306b\u518d\u5b9a\u7fa9\u3057\u307e\u3057\u305f
jsp.error.nested_jsproot=\u5165\u308c\u5b50\u306b\u306a\u3063\u305f <jsp:root> \u3067\u3059
jsp.error.unbalanced.endtag=\u7d42\u4e86\u30bf\u30b0 \"</{0}\" \u306e\u5bfe\u5fdc\u304c\u53d6\u308c\u3066\u3044\u307e\u305b\u3093
+jsp.error.invalid.bean=
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org