commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r729242 - in /commons/proper/digester/trunk: ./ src/java/org/apache/commons/digester/ src/java/org/apache/commons/digester/xmlrules/ src/test/org/apache/commons/digester/xmlrules/
Date Wed, 24 Dec 2008 06:10:08 GMT
Author: rahul
Date: Tue Dec 23 22:10:07 2008
New Revision: 729242

URL: http://svn.apache.org/viewvc?rev=729242&view=rev
Log:
Eliminate [collections] package dependencies -- ArrayStack, and therefore Buffer and BufferUnderflowException:
 - Replace ArrayStack usage with java.util.Stack<E>
 - This will allow BeanUtils to drop these classes in future releases if desired and end a
rather painful tangle we got into with v1.x in this regard
 - Allows usage of generics (unlike ArrayStack)
DIGESTER-115

Modified:
    commons/proper/digester/trunk/RELEASE-NOTES.txt
    commons/proper/digester/trunk/src/java/org/apache/commons/digester/CallParamRule.java
    commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java
    commons/proper/digester/trunk/src/java/org/apache/commons/digester/FactoryCreateRule.java
    commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java
    commons/proper/digester/trunk/src/test/org/apache/commons/digester/xmlrules/DigesterPatternStackTest.java

Modified: commons/proper/digester/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/RELEASE-NOTES.txt?rev=729242&r1=729241&r2=729242&view=diff
==============================================================================
--- commons/proper/digester/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/digester/trunk/RELEASE-NOTES.txt Tue Dec 23 22:10:07 2008
@@ -25,6 +25,17 @@
    work on lower JDKs. The source has been updated to leverage Generics and
    other JDK 1.5 features where possible, and requires JDK 1.5 to compile.
 
+ * This release eliminates all dependencies on Commons Collections classes.
+   Previously, ArrayStack was used in the Digester implementation and was
+   exposed via protected fields in the following classes:
+     org.apache.commons.digester.Digester,
+     org.apache.commons.digester.CallParamRule,
+     org.apache.commons.digester.FactoryCreateRule and
+     org.apache.commons.digester.xmlrules.DigesterRuleParser
+   These classes now use java.util.Stack instead. Any subclasses of the above
+   will require appropriate migration to using java.util.Stack for use with
+   version 2.0.
+
 OTHER IMPORTANT CHANGES:
 
  * The legacy schema support has been deprecated in favor of

Modified: commons/proper/digester/trunk/src/java/org/apache/commons/digester/CallParamRule.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/java/org/apache/commons/digester/CallParamRule.java?rev=729242&r1=729241&r2=729242&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/java/org/apache/commons/digester/CallParamRule.java
(original)
+++ commons/proper/digester/trunk/src/java/org/apache/commons/digester/CallParamRule.java
Tue Dec 23 22:10:07 2008
@@ -20,9 +20,9 @@
 package org.apache.commons.digester;
 
 
-import org.xml.sax.Attributes;
+import java.util.Stack;
 
-import org.apache.commons.collections.ArrayStack;
+import org.xml.sax.Attributes;
 
 
 /**
@@ -181,7 +181,7 @@
      * Stack is used to allow nested body text to be processed.
      * Lazy creation.
      */
-    protected ArrayStack bodyTextStack;
+    protected Stack<String> bodyTextStack;
 
     // --------------------------------------------------------- Public Methods
 
@@ -238,7 +238,7 @@
             // so that we can make sure that the right set of parameters
             // is at the top of the stack
             if (bodyTextStack == null) {
-                bodyTextStack = new ArrayStack();
+                bodyTextStack = new Stack<String>();
             }
             bodyTextStack.push(bodyText.trim());
         }

Modified: commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java?rev=729242&r1=729241&r2=729242&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java (original)
+++ commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java Tue Dec
23 22:10:07 2008
@@ -34,13 +34,13 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Stack;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.validation.Schema;
 
-import org.apache.commons.collections.ArrayStack;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.xml.sax.Attributes;
@@ -151,7 +151,7 @@
     /**
      * The stack of body text string buffers for surrounding elements.
      */
-    protected ArrayStack bodyTexts = new ArrayStack();
+    protected Stack<StringBuffer> bodyTexts = new Stack<StringBuffer>();
 
 
     /**
@@ -164,7 +164,7 @@
      *
      * @since 1.6
      */
-    protected ArrayStack matches = new ArrayStack(10);
+    protected Stack<List<Rule>> matches = new Stack<List<Rule>>();
     
     /**
      * The class loader to use for instantiating application objects.
@@ -233,12 +233,12 @@
     /**
      * Registered namespaces we are currently processing.  The key is the
      * namespace prefix that was declared in the document.  The value is an
-     * ArrayStack of the namespace URIs this prefix has been mapped to --
+     * Stack of the namespace URIs this prefix has been mapped to --
      * the top Stack element is the most current one.  (This architecture
      * is required because documents can declare nested uses of the same
      * prefix for different Namespace URIs).
      */
-    protected HashMap<String, ArrayStack> namespaces = new HashMap<String, ArrayStack>();
+    protected HashMap<String, Stack<String>> namespaces = new HashMap<String,
Stack<String>>();
 
 
     /**
@@ -251,7 +251,7 @@
      * The parameters stack being utilized by CallMethodRule and
      * CallParamRule rules.
      */
-    protected ArrayStack params = new ArrayStack();
+    protected Stack<Object> params = new Stack<Object>();
 
 
     /**
@@ -314,7 +314,7 @@
     /**
      * The object stack being constructed.
      */
-    protected ArrayStack stack = new ArrayStack();
+    protected Stack<Object> stack = new Stack<Object>();
 
 
     /**
@@ -357,7 +357,7 @@
     protected Substitutor substitutor;
     
     /** Stacks used for interrule communication, indexed by name String */
-    private HashMap<String, ArrayStack> stacksByName = new HashMap<String, ArrayStack>();
+    private HashMap<String, Stack<Object>> stacksByName = new HashMap<String,
Stack<Object>>();
     
     /**
      * If not null, then calls by the parser to this object's characters, 
@@ -387,12 +387,12 @@
      */
     public String findNamespaceURI(String prefix) {
         
-        ArrayStack nsStack = namespaces.get(prefix);
+        Stack<String> nsStack = namespaces.get(prefix);
         if (nsStack == null) {
             return null;
         }
         try {
-            return ((String) nsStack.peek());
+            return (nsStack.peek());
         } catch (EmptyStackException e) {
             return null;
         }
@@ -758,9 +758,9 @@
                 // we have to use parser-specific code for this. That code
                 // is hidden behind the ParserFeatureSetterFactory class.
 
-            	// The above has changed in JDK 1.5 and no longer true. The
-            	// functionality used in this block has now been deprecated.
-            	// We now use javax.xml.validation.Schema instead.
+                // The above has changed in JDK 1.5 and no longer true. The
+                // functionality used in this block has now been deprecated.
+                // We now use javax.xml.validation.Schema instead.
 
                 Properties properties = new Properties();
                 properties.put("SAXParserFactory", getFactory());
@@ -1151,10 +1151,10 @@
             log.warn("Digester is not namespace aware");
         }
         Map<String, String> currentNamespaces = new HashMap<String, String>();
-        for (Map.Entry<String, ArrayStack> nsEntry : namespaces.entrySet()) {
+        for (Map.Entry<String, Stack<String>> nsEntry : namespaces.entrySet())
{
              try {
                 currentNamespaces.put(nsEntry.getKey(),
-                    (String) nsEntry.getValue().peek());
+                    nsEntry.getValue().peek());
             } catch (RuntimeException e) {
                 // rethrow, after logging
                 log.error(e.getMessage(), e);
@@ -1270,7 +1270,7 @@
         }
 
         // Fire "body" events for all relevant rules
-        List<Rule> rules = (List<Rule>) matches.pop(); // legacy ArrayStack code
+        List<Rule> rules = matches.pop();
         if ((rules != null) && (rules.size() > 0)) {
             String bodyText = this.bodyText.toString();
             Substitutor substitutor = getSubstitutor();
@@ -1279,7 +1279,7 @@
             }
             for (int i = 0; i < rules.size(); i++) {
                 try {
-                    Rule rule = (Rule) rules.get(i);
+                    Rule rule = rules.get(i);
                     if (debug) {
                         log.debug("  Fire body() for " + rule);
                     }
@@ -1299,7 +1299,7 @@
         }
 
         // Recover the body text from the surrounding element
-        bodyText = (StringBuffer) bodyTexts.pop();
+        bodyText = bodyTexts.pop();
         if (debug) {
             log.debug("  Popping body text '" + bodyText.toString() + "'");
         }
@@ -1309,7 +1309,7 @@
             for (int i = 0; i < rules.size(); i++) {
                 int j = (rules.size() - i) - 1;
                 try {
-                    Rule rule = (Rule) rules.get(j);
+                    Rule rule = rules.get(j);
                     if (debug) {
                         log.debug("  Fire end() for " + rule);
                     }
@@ -1349,7 +1349,7 @@
         }
 
         // Deregister this prefix mapping
-        ArrayStack stack = namespaces.get(prefix);
+        Stack<String> stack = namespaces.get(prefix);
         if (stack == null) {
             return;
         }
@@ -1540,7 +1540,7 @@
             }
             for (int i = 0; i < rules.size(); i++) {
                 try {
-                    Rule rule = (Rule) rules.get(i);
+                    Rule rule = rules.get(i);
                     if (debug) {
                         log.debug("  Fire begin() for " + rule);
                     }
@@ -1578,9 +1578,9 @@
         }
 
         // Register this prefix mapping
-        ArrayStack stack = namespaces.get(prefix);
+        Stack<String> stack = namespaces.get(prefix);
         if (stack == null) {
-            stack = new ArrayStack();
+            stack = new Stack<String>();
             namespaces.put(prefix, stack);
         }
         stack.push(namespaceURI);
@@ -2872,8 +2872,13 @@
      */
     public Object peek(int n) {
 
+        int index = (stack.size() - 1) - n;
+        if (index < 0) {
+            log.warn("Empty stack (returning null)");
+            return (null);
+        }
         try {
-            return (stack.peek(n));
+            return (stack.get(index));
         } catch (EmptyStackException e) {
             log.warn("Empty stack (returning null)");
             return (null);
@@ -2933,9 +2938,9 @@
             value = stackAction.onPush(this, stackName, value);
         }
 
-        ArrayStack namedStack = stacksByName.get(stackName);
+        Stack<Object> namedStack = stacksByName.get(stackName);
         if (namedStack == null) {
-            namedStack = new ArrayStack();
+            namedStack = new Stack<Object>();
             stacksByName.put(stackName, namedStack);
         }
         namedStack.push(value);
@@ -2956,7 +2961,7 @@
      */
     public Object pop(String stackName) {
         Object result = null;
-        ArrayStack namedStack = stacksByName.get(stackName);
+        Stack<Object> namedStack = stacksByName.get(stackName);
         if (namedStack == null) {
             if (log.isDebugEnabled()) {
                 log.debug("Stack '" + stackName + "' is empty");
@@ -3008,7 +3013,7 @@
      */
     public Object peek(String stackName, int n) {
         Object result = null;
-        ArrayStack namedStack = stacksByName.get(stackName);
+        Stack<Object> namedStack = stacksByName.get(stackName);
         if (namedStack == null ) {
             if (log.isDebugEnabled()) {
                 log.debug("Stack '" + stackName + "' is empty");
@@ -3016,8 +3021,11 @@
             throw new EmptyStackException();
         
         } else {
-        
-            result = namedStack.peek(n);
+            int index = (namedStack.size() - 1) - n;
+            if (index < 0) {
+                throw new EmptyStackException();
+            }
+            result = namedStack.get(index);
         }
         return result;
     }
@@ -3034,7 +3042,7 @@
      */
     public boolean isEmpty(String stackName) {
         boolean result = true;
-        ArrayStack namedStack = stacksByName.get(stackName);
+        Stack<Object> namedStack = stacksByName.get(stackName);
         if (namedStack != null ) {
             result = namedStack.isEmpty();
         }
@@ -3235,8 +3243,13 @@
      */
     public Object peekParams(int n) {
 
+        int index = (params.size() - 1) - n;
+        if (index < 0) {
+            log.warn("Empty stack (returning null)");
+            return (null);
+        }
         try {
-            return (params.peek(n));
+            return (params.get(index));
         } catch (EmptyStackException e) {
             log.warn("Empty stack (returning null)");
             return (null);

Modified: commons/proper/digester/trunk/src/java/org/apache/commons/digester/FactoryCreateRule.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/java/org/apache/commons/digester/FactoryCreateRule.java?rev=729242&r1=729241&r2=729242&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/java/org/apache/commons/digester/FactoryCreateRule.java
(original)
+++ commons/proper/digester/trunk/src/java/org/apache/commons/digester/FactoryCreateRule.java
Tue Dec 23 22:10:07 2008
@@ -19,9 +19,9 @@
 
 package org.apache.commons.digester;
 
-import org.xml.sax.Attributes;
+import java.util.Stack;
 
-import org.apache.commons.collections.ArrayStack;
+import org.xml.sax.Attributes;
 
 
 /**
@@ -42,7 +42,7 @@
     /** Should exceptions thrown by the factory be ignored? */
     private boolean ignoreCreateExceptions;
     /** Stock to manage */
-    private ArrayStack exceptionIgnoredStack;
+    private Stack<Boolean> exceptionIgnoredStack;
 
     // ----------------------------------------------------------- Constructors
 
@@ -361,7 +361,7 @@
         if (ignoreCreateExceptions) {
         
             if (exceptionIgnoredStack == null) {
-                exceptionIgnoredStack = new ArrayStack();
+                exceptionIgnoredStack = new Stack<Boolean>();
             }
             
             try {
@@ -412,7 +412,7 @@
                 exceptionIgnoredStack != null &&
                 !(exceptionIgnoredStack.empty())) {
                 
-            if (((Boolean) exceptionIgnoredStack.pop()).booleanValue()) {
+            if (exceptionIgnoredStack.pop().booleanValue()) {
                 // creation exception was ignored
                 // nothing was put onto the stack
                 if (digester.log.isTraceEnabled()) {

Modified: commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java?rev=729242&r1=729241&r2=729242&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java
(original)
+++ commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java
Tue Dec 23 22:10:07 2008
@@ -27,12 +27,10 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.Stack;
 import java.util.StringTokenizer;
 
 import org.apache.commons.beanutils.ConvertUtils;
-
-import org.apache.commons.collections.ArrayStack;
-
 import org.apache.commons.digester.AbstractObjectCreationFactory;
 import org.apache.commons.digester.BeanPropertySetterRule;
 import org.apache.commons.digester.CallMethodRule;
@@ -41,6 +39,7 @@
 import org.apache.commons.digester.FactoryCreateRule;
 import org.apache.commons.digester.NodeCreateRule;
 import org.apache.commons.digester.ObjectCreateRule;
+import org.apache.commons.digester.ObjectParamRule;
 import org.apache.commons.digester.Rule;
 import org.apache.commons.digester.RuleSetBase;
 import org.apache.commons.digester.Rules;
@@ -50,8 +49,6 @@
 import org.apache.commons.digester.SetPropertyRule;
 import org.apache.commons.digester.SetRootRule;
 import org.apache.commons.digester.SetTopRule;
-import org.apache.commons.digester.ObjectParamRule;
-
 import org.w3c.dom.Node;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
@@ -86,7 +83,7 @@
      * A stack whose toString method returns a '/'-separated concatenation
      * of all the elements in the stack.
      */
-    protected class PatternStack extends ArrayStack {
+    protected class PatternStack<E> extends Stack<E> {
 
         private static final long serialVersionUID = 1L;
 
@@ -111,7 +108,7 @@
      * pattern, the resulting pattern is a concatenation of that pattern with
      * all the ancestor elements' patterns. Hence the need for a stack.
      */
-    protected PatternStack patternStack;
+    protected PatternStack<String> patternStack;
     
     /**
      * Used to detect circular includes
@@ -123,7 +120,7 @@
      * until the target digester is set, via <code>setTarget(Digester)</code>
      */
     public DigesterRuleParser() {
-        patternStack = new PatternStack();
+        patternStack = new PatternStack<String>();
     }
     
     /**
@@ -133,7 +130,7 @@
      */
     public DigesterRuleParser(Digester targetDigester) {
         this.targetDigester = targetDigester;
-        patternStack = new PatternStack();
+        patternStack = new PatternStack<String>();
     }
     
     /**
@@ -147,7 +144,7 @@
      * to any pattern parsed by this rule set.
      */
     private DigesterRuleParser(Digester targetDigester,
-                                PatternStack stack, Set<String> includedFiles) {
+                                PatternStack<String> stack, Set<String> includedFiles)
{
         this.targetDigester = targetDigester;
         patternStack = stack;
         this.includedFiles = includedFiles;

Modified: commons/proper/digester/trunk/src/test/org/apache/commons/digester/xmlrules/DigesterPatternStackTest.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/test/org/apache/commons/digester/xmlrules/DigesterPatternStackTest.java?rev=729242&r1=729241&r2=729242&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/test/org/apache/commons/digester/xmlrules/DigesterPatternStackTest.java
(original)
+++ commons/proper/digester/trunk/src/test/org/apache/commons/digester/xmlrules/DigesterPatternStackTest.java
Tue Dec 23 22:10:07 2008
@@ -47,7 +47,7 @@
         return suite;
     }
 
-    private DigesterRuleParser.PatternStack stack;
+    private DigesterRuleParser.PatternStack<String> stack;
 
     public void setUp() {
         DigesterRuleParser parser = new DigesterRuleParser();



Mime
View raw message