You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by lu...@apache.org on 2002/08/17 02:14:24 UTC
cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler ScriptingVariabler.java Compiler.java Generator.java JspDocumentParser.java Node.java Parser.java
luehe 2002/08/16 17:14:24
Modified: jasper2/src/share/org/apache/jasper/compiler Tag:
tomcat_4_branch Compiler.java Generator.java
JspDocumentParser.java Node.java Parser.java
Added: jasper2/src/share/org/apache/jasper/compiler Tag:
tomcat_4_branch ScriptingVariabler.java
Log:
Added compilation step which determines, for every custom tag, the
scripting variables that need to be declared. For example, if a custom
action is nested, it must not redeclare the AT_BEGIN variables of its
encapsulating action, etc.
Scripting variables are now generated at the appropriate places,
according to their scope.
Revision Changes Path
No revision
No revision
1.18.2.3 +6 -3 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java
Index: Compiler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v
retrieving revision 1.18.2.2
retrieving revision 1.18.2.3
diff -u -r1.18.2.2 -r1.18.2.3
--- Compiler.java 20 Jul 2002 02:44:49 -0000 1.18.2.2
+++ Compiler.java 17 Aug 2002 00:14:23 -0000 1.18.2.3
@@ -237,6 +237,9 @@
// Collect page info
Collector.collect(this, pageNodes);
+ // Determine which custom tag needs to declare which scripting vars
+ ScriptingVariabler.set(pageNodes);
+
// generate servlet .java file
Generator.generate(writer, this, pageNodes);
writer.close();
1.35.2.3 +102 -126 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.35.2.2
retrieving revision 1.35.2.3
diff -u -r1.35.2.2 -r1.35.2.3
--- Generator.java 8 Aug 2002 11:00:39 -0000 1.35.2.2
+++ Generator.java 17 Aug 2002 00:14:23 -0000 1.35.2.3
@@ -235,70 +235,57 @@
page.visit(new TagHandlerPoolVisitor(tagHandlerPoolNames));
}
-
- /*
- * For every custom tag, declares its scripting variables with AT_BEGIN
- * and AT_END scopes.
- */
- private void declareAtBeginAtEndScriptingVariables(Node.Nodes page)
+
+ private void declareTemporaryScriptingVars(Node.Nodes page)
throws JasperException {
- class ScriptingVariableDeclarationVisitor extends Node.Visitor {
+ class ScriptingVarVisitor extends Node.Visitor {
- /*
- * Vector keeping track of which scripting variables have already
- * been declared
- */
- private Vector scriptVars;
+ private Vector vars;
- /*
- * Constructor.
- */
- public ScriptingVariableDeclarationVisitor() {
- scriptVars = new Vector();
+ ScriptingVarVisitor() {
+ vars = new Vector();
}
public void visit(Node.CustomTag n) throws JasperException {
- TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
- VariableInfo[] varInfos = n.getVariableInfos();
-
- if ((varInfos == null) && (tagVarInfos == null)) {
- visitBody(n);
- }
-
- if (varInfos != null) {
- for (int i=0; i<varInfos.length; i++) {
- int scope = varInfos[i].getScope();
- String varName = varInfos[i].getVarName();
- if (((scope == VariableInfo.AT_BEGIN)
- || (scope == VariableInfo.AT_END))
- && varInfos[i].getDeclare()
- && !scriptVars.contains(varName)) {
- out.printin(varInfos[i].getClassName());
- out.print(" ");
- out.print(varName);
- out.println(" = null;");
- scriptVars.add(varName);
+ if (n.getCustomNestingLevel() > 0) {
+ TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
+ VariableInfo[] varInfos = n.getVariableInfos();
+
+ if (varInfos != null) {
+ for (int i=0; i<varInfos.length; i++) {
+ String varName = varInfos[i].getVarName();
+ String tmpVarName = "_jspx_" + varName + "_"
+ + n.getCustomNestingLevel();
+ if (!vars.contains(tmpVarName)) {
+ vars.add(tmpVarName);
+ out.printin(varInfos[i].getClassName());
+ out.print(" ");
+ out.print(tmpVarName);
+ out.print(" = ");
+ out.print(null);
+ out.println(";");
+ }
}
- }
- } else {
- for (int i=0; i<tagVarInfos.length; i++) {
- int scope = tagVarInfos[i].getScope();
- String varName = tagVarInfos[i].getNameGiven();
- if (varName == null) {
- varName = n.getTagData().getAttributeString(
- tagVarInfos[i].getNameFromAttribute());
- }
- if (((scope == VariableInfo.AT_BEGIN)
- || (scope == VariableInfo.AT_END))
- && tagVarInfos[i].getDeclare()
- && !scriptVars.contains(varName)) {
- out.printin(tagVarInfos[i].getClassName());
- out.print(" ");
- out.print(varName);
- out.println(" = null;");
- scriptVars.add(varName);
+ } else if (tagVarInfos != null) {
+ for (int i=0; i<tagVarInfos.length; i++) {
+ String varName = tagVarInfos[i].getNameGiven();
+ if (varName == null) {
+ varName = n.getTagData().getAttributeString(
+ tagVarInfos[i].getNameFromAttribute());
+ }
+ String tmpVarName = "_jspx_" + varName + "_"
+ + n.getCustomNestingLevel();
+ if (!vars.contains(tmpVarName)) {
+ vars.add(tmpVarName);
+ out.printin(tagVarInfos[i].getClassName());
+ out.print(" ");
+ out.print(tmpVarName);
+ out.print(" = ");
+ out.print(null);
+ out.println(";");
+ }
}
}
}
@@ -307,7 +294,7 @@
}
}
- page.visit(new ScriptingVariableDeclarationVisitor());
+ page.visit(new ScriptingVarVisitor());
}
/**
@@ -462,7 +449,7 @@
out.printil("JspWriter _jspx_out = null;");
out.println();
- declareAtBeginAtEndScriptingVariables(page);
+ declareTemporaryScriptingVars(page);
out.println();
out.printil("try {");
@@ -1083,11 +1070,9 @@
TagHandlerInfo handlerInfo = (TagHandlerInfo)
handlerInfosByShortName.get(n.getShortName());
if (handlerInfo == null) {
- handlerInfo = new TagHandlerInfo(
- n,
- n.getTagInfo().getTagClassName(),
- ctxt.getClassLoader(),
- err);
+ handlerInfo = new TagHandlerInfo(n,
+ n.getTagHandlerClass(),
+ err);
handlerInfosByShortName.put(n.getShortName(), handlerInfo);
}
@@ -1319,15 +1304,15 @@
out.printil("{");
out.pushIndent();
- // Declare scripting variables with NESTED scope
- declareNestedScriptingVariables(n);
+ // Declare AT_BEGIN scripting variables
+ declareScriptingVars(n, VariableInfo.AT_BEGIN);
/*
* Save current values of scripting variables, so that the
* scripting variables may be synchronized without affecting their
* original values
*/
- saveScriptingVariables(n);
+ saveScriptingVars(n);
out.printin(tagHandlerClass.getName());
out.print(" ");
@@ -1359,10 +1344,12 @@
out.print(tagHandlerVar);
out.println(".doStartTag();");
- // Synchronize AT_BEGIN and NESTED scripting variables
if (!implementsBodyTag) {
- syncScriptingVariables(n, VariableInfo.AT_BEGIN);
- syncScriptingVariables(n, VariableInfo.NESTED);
+ // Synchronize AT_BEGIN scripting variables
+ syncScriptingVars(n, VariableInfo.AT_BEGIN);
+ // Declare and synchronize NESTED scripting variables
+ declareScriptingVars(n, VariableInfo.NESTED);
+ syncScriptingVars(n, VariableInfo.NESTED);
}
if (n.getBody() != null) {
@@ -1372,6 +1359,9 @@
out.pushIndent();
if (implementsBodyTag) {
+ // Declare NESTED scripting variables
+ declareScriptingVars(n, VariableInfo.NESTED);
+
out.printin("if (");
out.print(tagEvalVar);
out.println(" != javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE) {");
@@ -1387,8 +1377,8 @@
out.println(".doInitBody();");
// Synchronize AT_BEGIN and NESTED scripting variables
- syncScriptingVariables(n, VariableInfo.AT_BEGIN);
- syncScriptingVariables(n, VariableInfo.NESTED);
+ syncScriptingVars(n, VariableInfo.AT_BEGIN);
+ syncScriptingVars(n, VariableInfo.NESTED);
out.popIndent();
out.printil("}");
@@ -1418,8 +1408,8 @@
// Synchronize AT_BEGIN and NESTED scripting variables
if (implementsBodyTag) {
- syncScriptingVariables(n, VariableInfo.AT_BEGIN);
- syncScriptingVariables(n, VariableInfo.NESTED);
+ syncScriptingVars(n, VariableInfo.AT_BEGIN);
+ syncScriptingVars(n, VariableInfo.NESTED);
}
out.printil("if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)");
@@ -1452,9 +1442,12 @@
out.printil((methodNesting > 0)? "return true;": "return;");
out.popIndent();
- // Synchronize AT_BEGIN and AT_END scripting variables
- syncScriptingVariables(n, VariableInfo.AT_BEGIN);
- syncScriptingVariables(n, VariableInfo.AT_END);
+ // Synchronize AT_BEGIN scripting variables
+ syncScriptingVars(n, VariableInfo.AT_BEGIN);
+
+ // Declare and synchronize AT_END scripting variables
+ declareScriptingVars(n, VariableInfo.AT_END);
+ syncScriptingVars(n, VariableInfo.AT_END);
// TryCatchFinally
if (implementsTryCatchFinally) {
@@ -1482,44 +1475,35 @@
out.println("}");
}
- restoreScriptingVariables(n);
+ restoreScriptingVars(n);
out.popIndent();
out.printil("}");
n.setEndJavaLine(out.getJavaLine());
}
- /*
- * Declares any NESTED scripting variables of the given custom tag.
- */
- private void declareNestedScriptingVariables(Node.CustomTag n) {
-
- TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
- VariableInfo[] nestedVarInfos = n.getNestedVariableInfos();
- if ((nestedVarInfos == null) && (tagVarInfos == null)) {
- return;
- }
-
- if (nestedVarInfos != null) {
- for (int i=0; i<nestedVarInfos.length; i++) {
- String name = nestedVarInfos[i].getVarName();
- out.printin(nestedVarInfos[i].getClassName());
- out.print(" ");
- out.print(name);
- out.println(" = null;");
- }
- } else {
- for (int i=0; i<tagVarInfos.length; i++) {
- if ((tagVarInfos[i].getScope() == VariableInfo.NESTED)
- && tagVarInfos[i].getDeclare()) {
- String name = tagVarInfos[i].getNameGiven();
- if (name == null) {
- name = n.getTagData().getAttributeString(
- tagVarInfos[i].getNameFromAttribute());
+ private void declareScriptingVars(Node.CustomTag n, int scope) {
+
+ Vector vec = n.getScriptingVars(scope);
+ if (vec != null) {
+ for (int i=0; i<vec.size(); i++) {
+ Object elem = vec.elementAt(i);
+ if (elem instanceof VariableInfo) {
+ VariableInfo varInfo = (VariableInfo) elem;
+ out.printin(varInfo.getClassName());
+ out.print(" ");
+ out.print(varInfo.getVarName());
+ out.println(" = null;");
+ } else {
+ TagVariableInfo tagVarInfo = (TagVariableInfo) elem;
+ String varName = tagVarInfo.getNameGiven();
+ if (varName == null) {
+ varName = n.getTagData().getAttributeString(
+ tagVarInfo.getNameFromAttribute());
}
- out.printin(tagVarInfos[i].getClassName());
+ out.printin(tagVarInfo.getClassName());
out.print(" ");
- out.print(name);
+ out.print(varName);
out.println(" = null;");
}
}
@@ -1535,7 +1519,7 @@
* end element. This way, the scripting variables may be synchronized
* by the given tag without affecting their original values.
*/
- private void saveScriptingVariables(Node.CustomTag n) {
+ private void saveScriptingVars(Node.CustomTag n) {
if (n.getCustomNestingLevel() == 0) {
return;
}
@@ -1584,7 +1568,7 @@
* restore its scripting variables to their original values that were
* saved in the tag's start element.
*/
- private void restoreScriptingVariables(Node.CustomTag n) {
+ private void restoreScriptingVars(Node.CustomTag n) {
if (n.getCustomNestingLevel() == 0) {
return;
}
@@ -1626,7 +1610,7 @@
* Synchronizes the scripting variables of the given custom tag for
* the given scope.
*/
- private void syncScriptingVariables(Node.CustomTag n, int scope) {
+ private void syncScriptingVars(Node.CustomTag n, int scope) {
TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
VariableInfo[] varInfos = n.getVariableInfos();
@@ -1897,23 +1881,15 @@
/**
* Constructor.
*
- * @param n The custom tag whose tag handler is to be loaded and
+ * @param n The custom tag whose tag handler class is to be
* introspected
- * @param tagClassName Name of tag handler class to load
- * @param loader Class loader to use
+ * @param tagHandlerClass Tag handler class
* @param err Error dispatcher
*/
- TagHandlerInfo(Node n, String tagClassName, ClassLoader loader,
- ErrorDispatcher err) throws JasperException {
-
- // Load the tag handler class with the given name
- tagHandlerClass = null;
- try {
- tagHandlerClass = loader.loadClass(tagClassName);
- } catch (Exception e) {
- err.jspError(n, "jsp.error.unable.loadclass", tagClassName, e);
- }
-
+ TagHandlerInfo(Node n, Class tagHandlerClass, ErrorDispatcher err)
+ throws JasperException
+ {
+ this.tagHandlerClass = tagHandlerClass;
this.methodMaps = new Hashtable();
this.propertyEditorMaps = new Hashtable();
@@ -1937,7 +1913,7 @@
}
} catch (IntrospectionException ie) {
err.jspError(n, "jsp.error.introspect.taghandler",
- tagClassName, ie);
+ tagHandlerClass.getName(), ie);
}
}
1.4.2.2 +13 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java
Index: JspDocumentParser.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java,v
retrieving revision 1.4.2.1
retrieving revision 1.4.2.2
diff -u -r1.4.2.1 -r1.4.2.2
--- JspDocumentParser.java 18 Jul 2002 23:25:05 -0000 1.4.2.1
+++ JspDocumentParser.java 17 Aug 2002 00:14:23 -0000 1.4.2.2
@@ -406,9 +406,18 @@
throw new SAXException(err.getString("jsp.error.bad_tag",
shortName, prefix));
}
+ Class tagHandlerClass = null;
+ try {
+ tagHandlerClass
+ = ctxt.getClassLoader().loadClass(tagInfo.getTagClassName());
+ } catch (Exception e) {
+ throw new SAXException(err.getString(
+ "jsp.error.unable.loadclass",
+ shortName, prefix));
+ }
return new Node.CustomTag(attrs, start, qName, prefix, shortName,
- tagInfo, parent);
+ tagInfo, tagHandlerClass, parent);
}
/*
1.15.2.2 +75 -67 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java
Index: Node.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java,v
retrieving revision 1.15.2.1
retrieving revision 1.15.2.2
diff -u -r1.15.2.1 -r1.15.2.2
--- Node.java 18 Jul 2002 21:34:08 -0000 1.15.2.1
+++ Node.java 17 Aug 2002 00:14:23 -0000 1.15.2.2
@@ -672,19 +672,29 @@
private boolean hasScriptingVars;
private String tagHandlerPoolName;
private TagInfo tagInfo;
+ private Class tagHandlerClass;
private VariableInfo[] varInfos;
- private VariableInfo[] nestedVarInfos;
private int customNestingLevel;
+ private boolean implementsBodyTag;
+ private Vector atBeginScriptingVars;
+ private Vector atEndScriptingVars;
+ private Vector nestedScriptingVars;
+ private Node.CustomTag customTagParent;
+ private Integer numCount;
public CustomTag(Attributes attrs, Mark start, String name,
String prefix, String shortName,
- TagInfo tagInfo, Node parent) {
+ TagInfo tagInfo, Class tagHandlerClass, Node parent) {
super(attrs, start, parent);
this.name = name;
this.prefix = prefix;
this.shortName = shortName;
this.tagInfo = tagInfo;
- this.customNestingLevel = computeCustomNestingLevel();
+ this.customNestingLevel = makeCustomNestingLevel();
+
+ this.tagHandlerClass = tagHandlerClass;
+ this.implementsBodyTag =
+ BodyTag.class.isAssignableFrom(tagHandlerClass);
}
public void accept(Visitor v) throws JasperException {
@@ -723,7 +733,6 @@
public void setTagData(TagData tagData) {
this.tagData = tagData;
this.varInfos = tagInfo.getVariableInfo(tagData);
- determineNestedVarInfos();
}
public TagData getTagData() {
@@ -782,6 +791,14 @@
return tagInfo;
}
+ public Class getTagHandlerClass() {
+ return tagHandlerClass;
+ }
+
+ public boolean implementsBodyTag() {
+ return implementsBodyTag;
+ }
+
public TagVariableInfo[] getTagVariableInfos() {
return tagInfo.getTagVariableInfos();
}
@@ -790,8 +807,56 @@
return varInfos;
}
- public VariableInfo[] getNestedVariableInfos() {
- return nestedVarInfos;
+ public void setCustomTagParent(Node.CustomTag n) {
+ this.customTagParent = n;
+ }
+
+ public Node.CustomTag getCustomTagParent() {
+ return this.customTagParent;
+ }
+
+ public void setNumCount(Integer count) {
+ this.numCount = count;
+ }
+
+ public Integer getNumCount() {
+ return this.numCount;
+ }
+
+ public void setScriptingVars(Vector vec, int scope) {
+ switch (scope) {
+ case VariableInfo.AT_BEGIN:
+ this.atBeginScriptingVars = vec;
+ break;
+ case VariableInfo.AT_END:
+ this.atEndScriptingVars = vec;
+ break;
+ case VariableInfo.NESTED:
+ this.nestedScriptingVars = vec;
+ break;
+ }
+ }
+
+ /*
+ * Gets the scripting variables for the given scope that need to be
+ * declared.
+ */
+ public Vector getScriptingVars(int scope) {
+ Vector vec = null;
+
+ switch (scope) {
+ case VariableInfo.AT_BEGIN:
+ vec = this.atBeginScriptingVars;
+ break;
+ case VariableInfo.AT_END:
+ vec = this.atEndScriptingVars;
+ break;
+ case VariableInfo.NESTED:
+ vec = this.nestedScriptingVars;
+ break;
+ }
+
+ return vec;
}
/*
@@ -825,7 +890,7 @@
*
* @return Custom tag's nesting level
*/
- private int computeCustomNestingLevel() {
+ private int makeCustomNestingLevel() {
int n = 0;
Node p = parent;
while (p != null) {
@@ -836,63 +901,6 @@
p = p.parent;
}
return n;
- }
-
- /*
- * Determines all the scripting variables with NESTED scope contained
- * in this custom action's VariableInfo[] that are not already
- * contained in the VariableInfo[] of a custom action of the same type
- * in the parent chain.
- */
- private void determineNestedVarInfos() {
-
- if (varInfos == null) {
- return;
- }
-
- Vector vec = new Vector();
-
- if (customNestingLevel == 0) {
- // tag not nested inside itself
- for (int i=0; i<varInfos.length; i++) {
- if (varInfos[i].getScope() == VariableInfo.NESTED
- && varInfos[i].getDeclare()) {
- vec.add(varInfos[i]);
- }
- }
- } else {
- for (int i=0; i<varInfos.length; i++) {
- if (varInfos[i].getScope() != VariableInfo.NESTED
- || !varInfos[i].getDeclare()) {
- continue;
- }
- Node p = parent;
- boolean found = false;
- while ((p != null) && !found) {
- if ((p instanceof Node.CustomTag)
- && name.equals(((Node.CustomTag) p).name)) {
- VariableInfo[] parentVarInfos
- = ((Node.CustomTag) p).getVariableInfos();
- for (int j=0; j<parentVarInfos.length; j++) {
- if (varInfos[i].getVarName().equals(
- parentVarInfos[j].getVarName())) {
- found = true;
- break;
- }
- }
- }
- p = p.parent;
- }
- if (p == null) {
- vec.add(varInfos[i]);
- }
- }
- }
-
- if (vec.size() > 0) {
- nestedVarInfos =
- (VariableInfo[]) vec.toArray(new VariableInfo[vec.size()]);
- }
}
}
1.7.2.2 +14 -5 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.2
diff -u -r1.7.2.1 -r1.7.2.2
--- Parser.java 18 Jul 2002 20:18:56 -0000 1.7.2.1
+++ Parser.java 17 Aug 2002 00:14:23 -0000 1.7.2.2
@@ -709,6 +709,14 @@
if (tagInfo == null) {
err.jspError(start, "jsp.error.bad_tag", shortTagName, prefix);
}
+ Class tagHandlerClass = null;
+ try {
+ tagHandlerClass
+ = ctxt.getClassLoader().loadClass(tagInfo.getTagClassName());
+ } catch (Exception e) {
+ err.jspError(start, "jsp.error.unable.loadclass", shortTagName,
+ prefix);
+ }
// EmptyElemTag ::= '<' Name ( #S Attribute )* S? '/>'
// or Stag ::= '<' Name ( #S Attribute)* S? '>'
@@ -718,7 +726,7 @@
if (reader.matches("/>")) {
// EmptyElemTag ::= '<' Name ( S Attribute )* S? '/>'#
new Node.CustomTag(attrs, start, tagName, prefix, shortTagName,
- tagInfo, parent);
+ tagInfo, tagHandlerClass, parent);
return true;
}
@@ -734,7 +742,8 @@
String bc = tagInfo.getBodyContent();
Node tagNode = new Node.CustomTag(attrs, start, tagName, prefix,
- shortTagName, tagInfo, parent);
+ shortTagName, tagInfo,
+ tagHandlerClass, parent);
// There are 3 body content types: empty, jsp, or tag-dependent.
if (bc.equalsIgnoreCase(TagInfo.BODY_CONTENT_EMPTY)) {
if (!reader.matchesETag(tagName)) {
No revision
No revision
1.1.2.1 +0 -0 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ScriptingVariabler.java
Index: ScriptingVariabler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ScriptingVariabler.java,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -r1.1 -r1.1.2.1
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>