You are viewing a plain text version of this content. The canonical link for it is here.
Posted to alexandria-dev@jakarta.apache.org by "Sikha, Naresh" <Na...@schwab.com> on 2002/01/02 07:07:46 UTC

RE: cvs commit: jakarta-alexandria/proposal/gump/java Jenny.java Module.java Project.java

My take on this is that the bug isn't in copyChildren logic per se, but in
expand (the copyChildren method, as is, is useful elsewhere). You'll have to
pardon the lack of a real diff (we're CVS challenged at Schwab), but here is
a proposed fix to expand. It works by literally replacing the profile
element with all of its children and then reinvokes expand on the parent
element.

Since this does remove the profile element all together, you can use
"syntactic sugar" to recreate it later on in the processing.

private void expand(Element node) throws Exception {

...
	Element parent = (Element)node.getParentNode();
	if (node.getNodeName().equals("profile")) {
		DocumentFragment fragment =
node.getOwnerDocument().createDocumentFragment();
		Node child = expanded.getFirstChild();
		while (child != null) {
			Node next = child.getNextSibling();
			if (child.getNodeType() == Node.ELEMENT_NODE) {
		      	fragment.appendChild(child);
     		      }
            	child = next;
      	}
      	parent.replaceChild(fragment, node);
      	expand(parent);
	}

...

}

Cheers.

-Naresh Sikha

-----Original Message-----
From: rubys@apache.org [mailto:rubys@apache.org]
Sent: Tuesday, January 01, 2002 3:45 PM
To: jakarta-alexandria-cvs@apache.org
Subject: cvs commit: jakarta-alexandria/proposal/gump/java Jenny.java
Module.java Project.java


rubys       02/01/01 15:45:05

  Modified:    proposal/gump/java Jenny.java Module.java Project.java
  Log:
  CopyChildren actually moved the children.  This resulted in a sublte bug.
  In the process of correcting this bug, I renamed the method so as to
  prevent further confusion.
  
  Revision  Changes    Path
  1.6       +6 -6      jakarta-alexandria/proposal/gump/java/Jenny.java
  
  Index: Jenny.java
  ===================================================================
  RCS file: /home/cvs/jakarta-alexandria/proposal/gump/java/Jenny.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Jenny.java	10 Dec 2001 15:48:08 -0000	1.5
  +++ Jenny.java	1 Jan 2002 23:45:05 -0000	1.6
  @@ -59,11 +59,11 @@
       }
   
       /**
  -     * Copy child nodes (attributes, elements, text, etc).
  -     * @param source element to copy from
  +     * Move child nodes (attributes, elements, text, etc).
  +     * @param source element to move from
        * @param target element to update
        */
  -    protected static void copyChildren(Element source, Element target) {
  +    protected static void moveChildren(Element source, Element target) {
          Node child=source.getFirstChild();
          while (child != null) {
              Node next=child.getNextSibling();
  @@ -102,12 +102,12 @@
   
              Document doc = node.getOwnerDocument();
              Element copy=(Element)doc.importNode(sub.getFirstChild(),
true);
  -           copyChildren(node, copy);
  +           moveChildren(node, copy);
   
              Element parent = (Element)node.getParentNode();
              if (node.getNodeName().equals("profile")) {
                  copy.removeAttribute("defined-in");
  -               copyChildren(copy, parent);
  +               moveChildren(copy, parent);
              } else {
                  parent.replaceChild(copy,node);
              }
  @@ -148,7 +148,7 @@
                   if (!definedIn.equals(""))
                       element.setAttribute("defined-in",definedIn);
   
  -                copyChildren(priorDefinition, element);
  +                moveChildren(priorDefinition, element);
                   parent.removeChild(priorDefinition);
               }
               list.put(name, element);
  
  
  
  1.11      +1 -1      jakarta-alexandria/proposal/gump/java/Module.java
  
  Index: Module.java
  ===================================================================
  RCS file: /home/cvs/jakarta-alexandria/proposal/gump/java/Module.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Module.java	27 Oct 2001 14:57:17 -0000	1.10
  +++ Module.java	1 Jan 2002 23:45:05 -0000	1.11
  @@ -178,7 +178,7 @@
               if (cvs == null)  {
                   cvs = (Element) child;
               } else {
  -                Jenny.copyChildren((Element) child, cvs);
  +                Jenny.moveChildren((Element) child, cvs);
               }
   
           }
  
  
  
  1.21      +17 -20    jakarta-alexandria/proposal/gump/java/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-alexandria/proposal/gump/java/Project.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- Project.java	1 Jan 2002 18:25:36 -0000	1.20
  +++ Project.java	1 Jan 2002 23:45:05 -0000	1.21
  @@ -75,7 +75,7 @@
               } else if (child.getNodeName().equals("ant")) {
                   if (ant != null) {
                       // multiple ant children?  Merge them!
  -                    Jenny.copyChildren(ant, (Element)child);
  +                    Jenny.moveChildren(ant, (Element)child);
                       element.removeChild(ant);
                   }
                   ant = (Element)child;
  @@ -130,7 +130,7 @@
                   Element property = document.createElement("property");
                   property.setAttribute("reference", "jarpath");
                   property.setAttribute("classpath", "add");
  -                Jenny.copyChildren((Element)child, property);
  +                Jenny.moveChildren((Element)child, property);
       
                   // change property attribute to name attribute
                   if (property.getAttributeNode("name")==null) {
  @@ -321,12 +321,11 @@
                       if (dependsOn.get(name) == null) {
                           Element source = (Element) p.dependsOn.get(name);
                           String type = source.getNodeName();
  -                        Element clone;
  +                        Element clone = (Element) source.cloneNode(true);
                           if (inherit.equals("hard") &&
type.equals("option")) {
  -                            clone = document.createElement("depend");
  -                            Jenny.copyChildren(source, clone);
  -                        } else {
  -                            clone = (Element) source.cloneNode(true);
  +                            Element renamed =
document.createElement("depend");
  +                            Jenny.moveChildren(clone, renamed);
  +                            clone = renamed;
                           }
                           clone.setAttribute("inherited", "true");
                           dependsOn.put(name,clone);
  @@ -340,20 +339,18 @@
                   String type = depend.getNodeName();
                   for (Enumeration d=p.dependsOn.keys();
d.hasMoreElements(); ) {
                       String name = (String) d.nextElement();
  -                    if (dependsOn.get(name) == null) {
  -                        Element source = (Element) p.dependsOn.get(name);
  -                        if
(source.getAttribute("runtime").equals("true")) {
  -                            Element clone;
  -                            if (type.equals("option")) {
  -                                clone = document.createElement("option");
  -                                Jenny.copyChildren(source, clone);
  -                            } else {
  -                                clone = (Element) source.cloneNode(true);
  -                            }
  -                            clone.setAttribute("inherited", "true");
  -                            dependsOn.put(name,clone);
  -                            element.appendChild(clone);
  +                    if (dependsOn.get(name) != null) continue;
  +                    Element source = (Element) p.dependsOn.get(name);
  +                    if (source.getAttribute("runtime").equals("true")) {
  +                        Element clone = (Element) source.cloneNode(true);
  +                        if (type.equals("option")) {
  +                            Element renamed =
document.createElement("option");
  +                            Jenny.moveChildren(clone, renamed);
  +                            clone = renamed;
                           }
  +                        clone.setAttribute("inherited", "true");
  +                        dependsOn.put(name,clone);
  +                        element.appendChild(clone);
                       }
                   }
               }
  
  
  

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>