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 Shyam Koppikar <vk...@tds.net> on 2001/10/02 05:16:29 UTC
Re: cvs commit: jakarta-alexandria/proposal/gump/java Jenny.java Module.java Project.java
----- Original Message -----
From: <ru...@apache.org>
To: <ja...@apache.org>
Sent: Sunday, September 30, 2001 9:32 AM
Subject: cvs commit: jakarta-alexandria/proposal/gump/java Jenny.java
Module.java Project.java
> rubys 01/09/30 09:32:58
>
> Modified: proposal/gump/java Jenny.java Module.java Project.java
> Log:
> Replace usages of XPath with directly walking the tree for performance
> reasons.
>
> Revision Changes Path
> 1.2 +10 -40 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.1
> retrieving revision 1.2
> diff -u -r1.1 -r1.2
> --- Jenny.java 2001/09/30 14:46:59 1.1
> +++ Jenny.java 2001/09/30 16:32:58 1.2
> @@ -17,16 +17,12 @@
> import org.w3c.dom.Element;
> import org.w3c.dom.NamedNodeMap;
> import org.w3c.dom.Node;
> -import org.w3c.dom.traversal.NodeIterator;
> import org.xml.sax.SAXParseException;
>
> // Java classes
> import java.util.Enumeration;
> import java.util.Hashtable;
>
> -// Apache xpath
> -import org.apache.xpath.XPathAPI;
> -
> public class Jenny {
>
> DocumentBuilderFactory dFactory =
DocumentBuilderFactory.newInstance();
> @@ -132,14 +128,17 @@
> * Attributes from later definitions get added (or overlay) prior
> * definitions. Elements get appended.
> * @param type Element localname. Typically project or repository.
> - * @param list Hashtable used for recursion. Must initially be
empty.
> * @param document Starting point for search.
> + * @return hashtable of resulting elements
> */
> - private void merge(String type, Hashtable list, Node document)
> + private Hashtable merge(String type, Node document)
> throws Exception
> {
> - NodeIterator nl = XPathAPI.selectNodeIterator(document,
"file://"+type);
> - for (Node child=nl.nextNode(); child!=null;
child=nl.nextNode()) {
> + Hashtable list = new Hashtable();
> +
> + Node child=document.getFirstChild();
> + for (; child!=null; child=child.getNextSibling()) {
> + if (!child.getNodeName().equals(type)) continue;
> Element element = (Element) child;
> String name = element.getAttribute("name");
>
> @@ -155,36 +154,7 @@
> }
> list.put(name, element);
> }
> - }
>
> - /**
> - * Unnest all elements of a given type by moving them all to become
> - * direct children of the specified root node. In the process,
merge
> - * all matching nodes which contain the same value for the name
attribute.
> - * For elements that get "hoisted", an additional "defined-in"
attribute
> - * is added indicating where the element was originally defined.
> - * @param type Element localname. Typically project or repository.
> - * @param root Root (workspace) node
> - */
> - private Hashtable flatten(String type, Node root)
> - throws Exception
> - {
> - Hashtable list = new Hashtable();
> - merge(type, list, root);
> - for (Enumeration e=list.keys(); e.hasMoreElements();) {
> - Element element = (Element)list.get(e.nextElement());
> - Element parent = (Element)element.getParentNode();
> -
> - if (parent != root) {
> - String definedIn = parent.getAttribute("defined-in");
> - if (definedIn.equals(""))
> - definedIn = parent.getAttribute("name");
> - element.setAttribute("defined-in",definedIn);
> -
> - parent.removeChild(element);
> - root.appendChild(element);
> - }
> - }
> return list;
> }
>
> @@ -209,9 +179,9 @@
> Workspace.init(workspace);
>
> expand(workspace);
> - Module.load(flatten("module",workspace).elements());
> - Project.load(flatten("project",workspace).elements());
> - flatten("repository", workspace);
> + Module.load(merge("module",workspace).elements());
> + Project.load(merge("project",workspace).elements());
> + merge("repository", workspace);
> output (doc, "work/merge.xml");
>
> Node sorted = transform(doc, "sortdep.xsl");
>
>
>
> 1.2 +27 -10 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.1
> retrieving revision 1.2
> diff -u -r1.1 -r1.2
> --- Module.java 2001/09/30 14:46:59 1.1
> +++ Module.java 2001/09/30 16:32:58 1.2
> @@ -4,6 +4,7 @@
>
> // Java classes
> import java.util.Enumeration;
> +import java.util.Vector;
> import java.util.Hashtable;
>
> public class Module {
> @@ -41,7 +42,7 @@
> name = element.getAttribute("name");
>
> computeSrcDir();
> - markProjects();
> + promoteProjects();
>
> modules.put(name, this);
> }
> @@ -66,18 +67,34 @@
> }
>
> /**
> - * Set module name on any projects contained herein.
> + * Set module name on any projects contained herein, and move the
> + * element up to the workspace.
> */
> - private void markProjects() throws Exception {
> + private void promoteProjects() throws Exception {
> + Vector projects = new Vector();
> +
> + // Collect a list of projects, marking them as we go
> Node child=element.getFirstChild();
> - while (child != null) {
> - if (child.getNodeName().equals("project")) {
> - Element project = (Element) child;
> - if (project.getAttributeNode("module") == null) {
> - project.setAttribute("module", name);
> - }
> + for (; child != null; child=child.getNextSibling()) {
> + if (! child.getNodeName().equals("project")) continue;
> +
> + Element project = (Element) child;
> + if (project.getAttributeNode("module") == null) {
> + project.setAttribute("module", name);
> }
> - child=child.getNextSibling();
> +
> + projects.add(project);
> + }
> +
> + // Move each project from the module to the workspace
> + Node parent = element.getParentNode();
> + String definedIn = element.getAttribute("defined-in");
> + for (Enumeration e=projects.elements(); e.hasMoreElements(); )
{
> + Element project = (Element) e.nextElement();
> + if (project.getAttributeNode("defined-in") == null)
> + project.setAttribute("defined-in", definedIn);
> + element.removeChild(project);
> + parent.appendChild(project);
> }
> }
>
>
>
>
> 1.2 +26 -27 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.1
> retrieving revision 1.2
> diff -u -r1.1 -r1.2
> --- Project.java 2001/09/30 14:46:59 1.1
> +++ Project.java 2001/09/30 16:32:58 1.2
> @@ -3,15 +3,11 @@
> import org.w3c.dom.Document;
> import org.w3c.dom.Element;
> import org.w3c.dom.Node;
> -import org.w3c.dom.traversal.NodeIterator;
>
> // Java classes
> import java.util.Enumeration;
> import java.util.Hashtable;
>
> -// Apache xpath
> -import org.apache.xpath.XPathAPI;
> -
> public class Project {
>
> private Document document;
> @@ -72,29 +68,31 @@
> */
> private void genProperties(Element ant) throws Exception {
>
> - NodeIterator nl = XPathAPI.selectNodeIterator(ant, "depend");
> - for (Node depend=nl.nextNode(); depend!=null;) {
> - Node next = nl.nextNode();
> -
> - // create a new element based on existing element
> - Element property = document.createElement("property");
> - property.setAttribute("reference", "jarpath");
> - property.setAttribute("classpath", "add");
> - Jenny.copyChildren((Element)depend, property);
> -
> - // change property attribute to name attribute
> - if (property.getAttributeNode("name")==null) {
> - Attr pname = property.getAttributeNode("property");
> - if (pname != null) {
> - property.setAttribute("name",pname.getValue());
> - property.removeAttributeNode(pname);
> - }
> - }
> + Node child=ant.getFirstChild();
> + while (child != null) {
> + Node next = child.getNextSibling();
> +
> + if (child.getNodeName().equals("depend")) {
> + // create a new element based on existing element
> + Element property = document.createElement("property");
> + property.setAttribute("reference", "jarpath");
> + property.setAttribute("classpath", "add");
> + Jenny.copyChildren((Element)child, property);
> +
> + // change property attribute to name attribute
> + if (property.getAttributeNode("name")==null) {
> + Attr pname = property.getAttributeNode("property");
> + if (pname != null) {
> + property.setAttribute("name",pname.getValue());
> + property.removeAttributeNode(pname);
> + }
> + }
>
> - // replace existing element with new one
> - depend.getParentNode().replaceChild(property, depend);
> + // replace existing element with new one
> + ant.replaceChild(property, child);
> + }
>
> - depend = next;
> + child = next;
> }
> }
>
> @@ -103,8 +101,9 @@
> * @param ant <ant> element to be processed
> */
> private void genDepends(Element ant) throws Exception {
> - NodeIterator nl = XPathAPI.selectNodeIterator(ant, "property");
> - for (Node child=nl.nextNode(); child!=null;
child=nl.nextNode()) {
> + Node child=ant.getFirstChild();
> + for (;child!=null; child=child.getNextSibling()) {
> + if (!child.getNodeName().equals("property")) continue;
> Element property = (Element) child;
>
> String dependency = property.getAttribute("project");
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: alexandria-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: alexandria-dev-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: alexandria-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: alexandria-dev-help@jakarta.apache.org