You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by cr...@apache.org on 2007/04/17 22:00:38 UTC

svn commit: r529746 - /beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeElement.java

Author: crogers
Date: Tue Apr 17 13:00:37 2007
New Revision: 529746

URL: http://svn.apache.org/viewvc?view=rev&rev=529746
Log:
New fix for BEEHIVE-1162. In svn revision 483829 I changed TreeElement class to use a LinkedHashMap instead of an ArrayList for the set of attributes. However, the _attributes field was public, implying an API change. In this revision I've changed this field back to an ArrayList and added code in addAttribute() to check if an attribute is being reset. The test case for this bug still passes.

Tests: NetUI BVT (WinXP passed)


Modified:
    beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeElement.java

Modified: beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeElement.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeElement.java?view=diff&rev=529746&r1=529745&r2=529746
==============================================================================
--- beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeElement.java (original)
+++ beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeElement.java Tue Apr 17 13:00:37 2007
@@ -21,7 +21,6 @@
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.LinkedHashMap;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
@@ -82,7 +81,7 @@
 
     private TreeElement _parent;     // The parent node of this node, null for the root
     private ArrayList _children;     // The children of this node
-    public HashMap _attribute;       // The attributes associated with the element.
+    public ArrayList _attribute;     // The attributes associated with the element.
 
     private ExtendedInfo _info;      // The extended info
 
@@ -499,17 +498,41 @@
     }
 
     /**
-     * This method is called by the children tags of the TreeItem.  If there is a <code>TreeHtmlAttribute</code>
-     * it will set the attribute name and value.
-     * @param attr
+     * This method is called by the children tags of the TreeItem.  If there is
+     * a <code>TreeHtmlAttribute</code> it will set the attribute name and value.
+     * @param attr the attribute to add.
      */
     public void addAttribute(TreeHtmlAttributeInfo attr)
     {
+        if (attr == null) {
+            return;
+        }
         if (_attribute == null) {
-            _attribute = new LinkedHashMap();
+            _attribute = new ArrayList();
         }
         attr.setParent(this);
-        _attribute.put(attr.getAttribute(), attr);
+
+        // BEEHIVE-1162 - check to see if the attribute is being reset.
+        // This would be more efficient if it was a LinkedHashMap, but
+        // unfortunately _attribute is declared public so we cannot change
+        // the type. Also, since this field is public, we can't even assume
+        // that all attributes are added via this method and use a different
+        // data type to identify what attributes are already in use,
+        // implying a reset. Just cycle through and check.
+        boolean attributeReplaced = false;
+        int size = _attribute.size();
+        for (int i = 0; i < size; i++) {
+            TreeHtmlAttributeInfo a = (TreeHtmlAttributeInfo) _attribute.get(i);
+            if (attr.getAttribute() != null && attr.getAttribute().equals(a.getAttribute())) {
+                attributeReplaced = true;
+                _attribute.set(i, attr);
+                break;
+            }
+        }
+
+        if (!attributeReplaced) {
+            _attribute.add(attr);
+        }
     }
 
     /**
@@ -519,10 +542,7 @@
      */
     public ArrayList getAttributeList()
     {
-        if (_attribute == null) {
-            return null;
-        }
-        return new ArrayList(_attribute.values());
+        return _attribute;
     }
 
     ///*********************** PROTECTED PROPERTY SETTERS *************************************