rubys       01/10/08 06:49:07

  Modified:    proposal/gump/java Project.java
               proposal/gump/stylesheet build.xsl
  Log:
  A bit less logic in the stylesheet; better performance
  
  Revision  Changes    Path
  1.4       +52 -8     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Project.java      2001/10/03 12:33:39     1.3
  +++ Project.java      2001/10/08 13:49:07     1.4
  @@ -10,6 +10,7 @@
   
   public class Project {
   
  +    static private Hashtable projects = new Hashtable();
       private Document document;
       private Element element;
       private String name;
  @@ -17,12 +18,26 @@
   
       /**
        * Create a set of Project definitions based on XML nodes.
  -     * @param project list of <project> elements
  +     * @param elements list of <project> elements
        */
  -    public static void load(Enumeration projects) throws Exception {
  -        while (projects.hasMoreElements()) {
  -           new Project((Element)projects.nextElement());
  +    public static void load(Enumeration elements) throws Exception {
  +        while (elements.hasMoreElements()) {
  +           new Project((Element)elements.nextElement());
           }
  +
  +        // expand dependencies for easier generation
  +        for (Enumeration e=projects.elements(); e.hasMoreElements();) {
  +            ((Project)(e.nextElement())).expandDepends();
  +        }
  +    }
  +
  +    /**
  +     * General attribute accessor.
  +     * @param name attribute name
  +     * @return Value of the specified attribute.
  +     */
  +    public String get(String name) {
  +        return element.getAttribute(name);
       }
   
       /**
  @@ -38,17 +53,16 @@
           Element ant = null;
   
           Node child=element.getFirstChild();
  -        while (child != null) {
  +        for (; child != null; child=child.getNextSibling()) {
               if (child.getNodeName().equals("depend")) {
  -                depends.put(((Element)child).getAttribute("project"),child);
  +                depends.put(((Element)child).getAttribute("project"), child);
               } else if (child.getNodeName().equals("option")) {
  -                depends.put(((Element)child).getAttribute("project"),child);
  +                depends.put(((Element)child).getAttribute("project"), child);
               } else if (child.getNodeName().equals("ant")) {
                   ant = (Element)child;
               } else if (child.getNodeName().equals("home")) {
                   home = (Element)child;
               }
  -            child=child.getNextSibling();
           }
   
           computeHome(home);
  @@ -57,6 +71,8 @@
               genProperties(ant);
               genDepends(ant);
           }
  +
  +        projects.put(name, this);
       }
   
       /**
  @@ -156,6 +172,34 @@
   
               if (result.equals("")) result=srcdir;
               element.setAttribute("home", result);
  +        }
  +    }
  +
  +    /**
  +     * Copy selected attribute and elements from dependent projects.  This
  +     * simplifies generation by essentially making project definitions
  +     * self contained.
  +     */
  +    private void expandDepends() {
  +        for (Enumeration e=depends.keys(); e.hasMoreElements(); ) {
  +            String name = (String)e.nextElement();
  +            Project target = (Project)projects.get(name);
  +            if (target == null) continue;
  +
  +            Element depend = (Element) depends.get(name);
  +            depend.setAttribute("home",target.get("home"));
  +            depend.setAttribute("defined-in",target.get("defined-in"));
  +
  +            Node child=target.element.getFirstChild();
  +            for (; child != null; child=child.getNextSibling()) {
  +                if (child.getNodeName().equals("jar")) {
  +                    depend.appendChild(child.cloneNode(false));
  +                } else if (child.getNodeName().equals("ant")) {
  +                    depend.appendChild(child.cloneNode(false));
  +                } else if (child.getNodeName().equals("script")) {
  +                    depend.appendChild(child.cloneNode(false));
  +                }
  +            }
           }
       }
   }
  
  
  
  1.32      +16 -28    jakarta-alexandria/proposal/gump/stylesheet/build.xsl
  
  Index: build.xsl
  ===================================================================
  RCS file: /home/cvs/jakarta-alexandria/proposal/gump/stylesheet/build.xsl,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- build.xsl 2001/09/29 15:41:06     1.31
  +++ build.xsl 2001/10/08 13:49:07     1.32
  @@ -147,24 +147,18 @@
             <br/>
             <xsl:text>Dependencies: </xsl:text>
             <xsl:for-each select="depend|option">
  -            <xsl:variable name="dependent" select="@project"/>
  -            <xsl:for-each select="/workspace/project[@name=$dependent]">
  -              <xsl:choose>
  -                <xsl:when test="ant|script">
  -                  <a href="{@name}.html">
  -                    <xsl:value-of select="$dependent"/>
  -                  </a>
  -                </xsl:when>
  -                <xsl:otherwise>
  -                  <xsl:variable name="module" select="@module"/>
  -                  <xsl:for-each select="/workspace/module[@name=$module]">
  -                    <a href="module_{@defined-in}.html">
  -                      <xsl:value-of select="$dependent"/>
  -                    </a>
  -                  </xsl:for-each>
  -                </xsl:otherwise>
  -              </xsl:choose>
  -            </xsl:for-each>
  +            <xsl:choose>
  +              <xsl:when test="ant|script">
  +                <a href="{@project}.html">
  +                  <xsl:value-of select="@project"/>
  +                </a>
  +              </xsl:when>
  +              <xsl:when test="@defined-in">
  +                <a href="module_{@defined-in}.html">
  +                  <xsl:value-of select="@project"/>
  +                </a>
  +              </xsl:when>
  +            </xsl:choose>
             </xsl:for-each>
           </menu>
   
  @@ -173,12 +167,9 @@
             <!-- prereq check -->
   
             <xsl:for-each select="depend">
  -            <xsl:variable name="dependent" select="@project"/>
               <prereq project="{@project}">
  -              <xsl:for-each select="/workspace/project[@name=$dependent]">
  -                <xsl:for-each select="jar">
  -                  <file path="{../@home}/{@name}"/>
  -                </xsl:for-each>
  +              <xsl:for-each select="jar">
  +                <file path="{../@home}/{@name}"/>
                 </xsl:for-each>
               </prereq>
             </xsl:for-each>
  @@ -207,11 +198,8 @@
                 </xsl:for-each>
   
                 <xsl:for-each select="depend[not(noclasspath)]|option">
  -                <xsl:variable name="dependent" select="@project"/>
  -                <xsl:for-each select="/workspace/project[@name=$dependent]">
  -                  <xsl:for-each select="jar">
  -                    <pathelement location="{../@home}/{@name}"/>
  -                  </xsl:for-each>
  +                <xsl:for-each select="jar">
  +                  <pathelement location="{../@home}/{@name}"/>
                   </xsl:for-each>
                 </xsl:for-each>
               </classpath>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to