You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@locus.apache.org on 2000/12/28 01:27:09 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/digester Digester.java
craigmcc 00/12/27 16:27:09
Modified: src/share/org/apache/struts/digester Digester.java
Log:
Switch to unsynchronized collection classes for most cases. A new Stack
implementation (based on ArrayList) will be needed before the final
changes can be made.
TODO: Evaluate the deprecation warnings on things like
org.xml.sax.AttributeList.
Revision Changes Path
1.11 +42 -35 jakarta-struts/src/share/org/apache/struts/digester/Digester.java
Index: Digester.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/digester/Digester.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Digester.java 2000/11/29 06:47:15 1.10
+++ Digester.java 2000/12/28 00:27:09 1.11
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/digester/Digester.java,v 1.10 2000/11/29 06:47:15 craigmcc Exp $
- * $Revision: 1.10 $
- * $Date: 2000/11/29 06:47:15 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/digester/Digester.java,v 1.11 2000/12/28 00:27:09 craigmcc Exp $
+ * $Revision: 1.11 $
+ * $Date: 2000/12/28 00:27:09 $
*
* ====================================================================
*
@@ -68,9 +68,11 @@
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
+import java.util.ArrayList;
import java.util.EmptyStackException;
-import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
import java.util.Stack;
import java.util.Vector;
import javax.xml.parsers.SAXParser;
@@ -86,17 +88,22 @@
/**
- * A <strong>Digester</strong> processes an XML input stream by matching a
+ * <p>A <strong>Digester</strong> processes an XML input stream by matching a
* series of element nesting patterns to execute Rules that have been added
* prior to the start of parsing. This package was inspired by the
* <code>XmlMapper</code> class that was part of Tomcat 3.0 and 3.1,
- * but is organized somewhat differently.
- * <p>
- * See the <a href="package-summary.html#package_description">Digester
- * Developer Guide</a> for more information.
+ * but is organized somewhat differently.</p>
*
+ * <p>See the <a href="package-summary.html#package_description">Digester
+ * Developer Guide</a> for more information.</p>
+ *
+ * <p><strong>IMPLEMENTATION NOTE</strong> - A single Digester instance may
+ * only be used within the context of a single thread at a time, and a call
+ * to <code>parse()</code> must be completed before another can be initiated
+ * even from the same thread.</p>
+ *
* @author Craig McClanahan
- * @version $Revision: 1.10 $ $Date: 2000/11/29 06:47:15 $
+ * @version $Revision: 1.11 $ $Date: 2000/12/28 00:27:09 $
*/
public final class Digester extends HandlerBase {
@@ -140,7 +147,7 @@
* The URLs of DTDs that have been registered, keyed by the public
* identifier that corresponds.
*/
- private Hashtable dtds = new Hashtable();
+ private HashMap dtds = new HashMap();
/**
@@ -171,10 +178,10 @@
/**
* The set of Rules that have been registered with this Digester. The
* key is the matching pattern against the current element stack, and
- * the value is a Vector containing the Rules for that pattern, in the
+ * the value is a List containing the Rules for that pattern, in the
* order that they were registered.
*/
- private Hashtable rules = new Hashtable();
+ private HashMap rules = new HashMap();
/**
@@ -312,13 +319,13 @@
pop();
// Fire "finish" events for all defined rules
- Enumeration keys = this.rules.keys();
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- Vector rules = (Vector) this.rules.get(key);
+ Iterator keys = this.rules.keySet().iterator();
+ while (keys.hasNext()) {
+ String key = (String) keys.next();
+ List rules = (List) this.rules.get(key);
for (int i = 0; i < rules.size(); i++) {
try {
- ((Rule) rules.elementAt(i)).finish();
+ ((Rule) rules.get(i)).finish();
} catch (Exception e) {
log("Finish event threw exception", e);
throw new SAXException(e);
@@ -343,7 +350,7 @@
// if (debug >= 3)
// log("endElement(" + match + ")");
- Vector rules = getRules(match);
+ List rules = getRules(match);
// Fire "body" events for all relevant rules
if (rules != null) {
@@ -352,7 +359,7 @@
String bodyText = this.bodyText.toString();
for (int i = 0; i < rules.size(); i++) {
try {
- ((Rule) rules.elementAt(i)).body(bodyText);
+ ((Rule) rules.get(i)).body(bodyText);
} catch (Exception e) {
log("Body event threw exception", e);
throw new SAXException(e);
@@ -370,7 +377,7 @@
for (int i = 0; i < rules.size(); i++) {
int j = (rules.size() - i) - 1;
try {
- ((Rule) rules.elementAt(j)).end();
+ ((Rule) rules.get(j)).end();
} catch (Exception e) {
log("End event threw exception", e);
throw new SAXException(e);
@@ -482,14 +489,14 @@
// Fire "begin" events for all relevant rules
- Vector rules = getRules(match);
+ List rules = getRules(match);
if (rules != null) {
// if (debug >= 3)
// log(" Firing 'begin' events for " + rules.size() + " rules");
String bodyText = this.bodyText.toString();
for (int i = 0; i < rules.size(); i++) {
try {
- ((Rule) rules.elementAt(i)).begin(list);
+ ((Rule) rules.get(i)).begin(list);
} catch (Exception e) {
log("Begin event threw exception", e);
throw new SAXException(e);
@@ -755,12 +762,12 @@
*/
public void addRule(String pattern, Rule rule) {
- Vector list = (Vector) rules.get(pattern);
+ List list = (List) rules.get(pattern);
if (list == null) {
- list = new Vector();
+ list = new ArrayList();
rules.put(pattern, list);
}
- list.addElement(rule);
+ list.add(rule);
}
@@ -1048,22 +1055,22 @@
*
* @param match The current match position
*/
- private Vector getRules(String match) {
+ private List getRules(String match) {
- Vector rulesVector = (Vector) this.rules.get(match);
- if (rulesVector == null) {
- Enumeration keys = this.rules.keys();
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
+ List rulesList = (List) this.rules.get(match);
+ if (rulesList == null) {
+ Iterator keys = this.rules.keySet().iterator();
+ while (keys.hasNext()) {
+ String key = (String) keys.next();
if (key.startsWith("*/")) {
if (match.endsWith(key.substring(1))) {
- rulesVector = (Vector) this.rules.get(key);
+ rulesList = (List) this.rules.get(key);
break;
}
}
}
}
- return (rulesVector);
+ return (rulesList);
}