cvs commit: jakarta-alexandria/src/java/org/apache/alexandria/vizant Vizant.java VizASType.java VizAttr.java VizAttrStmt.java VizPrinter.java VizPrinter.java.old VizProject.java VizProjectLoader.java VizProjectLoaderImpl.java VizReference.java VizSubgraph.java VizTarget.java VizWriter.java

[email protected] 11 Apr 2003 12:17:16 -0000
Newsgroups gmane.comp.jakarta.alexandria.devel
Message-ID <[email protected]>
nicolaken    2003/04/11 05:17:16

  Added:       src/java/org/apache/alexandria/vizant Vizant.java
                        VizASType.java VizAttr.java VizAttrStmt.java
                        VizPrinter.java VizPrinter.java.old VizProject.java
                        VizProjectLoader.java VizProjectLoaderImpl.java
                        VizReference.java VizSubgraph.java VizTarget.java
                        VizWriter.java
  Log:
  Alexadria gets Vizant :-)
  
  Revision  Changes    Path
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/Vizant.java
  
  Index: Vizant.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/Vizant.java,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
   
  package org.apache.alexandria.vizant;
  
  import java.util.Vector;
  import java.util.Enumeration;
  import java.io.File;
  import java.io.PrintWriter;
  import java.io.BufferedWriter;
  import java.io.FileWriter;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.FileNotFoundException;
  
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.BuildException;
  
  /**
   * Vizant task.
   * 
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
   */
  public class Vizant extends Task {
      private File antfile;
      private File outfile;
      private VizProjectLoader loader;
      private VizPrinter printer;
      private VizWriter writer;
  
      public void init() {
  	loader = getLoader();
  	printer = getPrinter();
      }
      
      public void setAntfile(File antfile) throws BuildException {
  	this.antfile = antfile;
  	try {
  	    loader.setInputStream(new FileInputStream(antfile));
  	} catch (FileNotFoundException e) {
  	    throw new BuildException(e);
  	}
      }
  
      public void setOutfile(File outfile) {
  	this.outfile = outfile;
      }
  
      public void setGraphid(String graphid) {
          printer.setGraphid(graphid);
      }
  
      public void setFrom(String targetName) {
          printer.setFrom(targetName);
      }
  
      public void setTo(String targetName) {
          printer.setTo(targetName);
      }
  
      public void setNocluster(boolean noclustor) {
          printer.setNocluster(noclustor);
      }
  
      public void setUniqueref(boolean uniqueref) {
          loader.uniqueRef(uniqueref);
      }
  
      public void setIgnoreant(boolean opt) {
          loader.ignoreAnt(opt);
      }
  
      public void setIgnoreantcall(boolean opt) {
          loader.ignoreAntcall(opt);
      }
  
      public void setIgnoredepends(boolean opt) {
          loader.ignoreDepends(opt);
      }
  
      public void addConfiguredAttrstmt(VizAttrStmt attrstmt) 
          throws BuildException {
          attrstmt.checkConfiguration();
          printer.addAttributeStatement(attrstmt);
      }
  
      public void addSubgraph(VizSubgraph subgraph) {
          subgraph.setPrinter(printer);
      }
  
      public void execute() throws BuildException {
  	checkConfiguration();
  	loadProjects();
  	writeDotToOutfile();
      }
  
      protected VizPrinter getPrinter() {
  	return new VizPrinter();
      }
  
      protected VizProjectLoader getLoader() {
  	return new VizProjectLoaderImpl();
      }
  
      protected void checkConfiguration() throws BuildException {
  	if (antfile == null) {
  	    throw new BuildException("antfile attribute is required");
  	}
  	if (outfile == null) {
  	    throw new BuildException("outfile attribute is required");
  	}
      }
  
      protected void loadProjects() throws BuildException {
          Enumeration enum = loader.getProjects().elements();
          while (enum.hasMoreElements()) {
              printer.addProject((VizProject)enum.nextElement());
          }
      }
  
      protected void writeDotToOutfile() throws BuildException {
  	VizFileWriter out = null;
  	try {
              out = new VizFileWriter(outfile);
  	    print(out);
  	} catch(IOException e) {
  	    throw new BuildException(e.toString());
  	} finally {
  	    if (out != null)
  		out.close();
  	}
      }
  
      protected void print(VizWriter out) {
  	printer.setWriter(out);
  	printer.print();
      }
  
      public class VizFileWriter implements VizWriter {
  	private PrintWriter out = null;
  	
  	public VizFileWriter(File outfile) throws IOException {
  	    out = new PrintWriter(new BufferedWriter(new FileWriter(outfile)));
  	}
  
  	public void print(String str) {
  	    out.print(str);
  	}
  
  	public void println(String str) {
  	    out.println(str);
  	}
  
  	public void close() {
  	    if (out != null) {
  		out.flush();
  		out.close();
  	    }
  	}
      }
  }
  
  
  
  
  
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizASType.java
  
  Index: VizASType.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizASType.java,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
   
  package org.apache.alexandria.vizant;
  
  import org.apache.tools.ant.BuildException;
  import java.util.Hashtable;
  
  /**
   * DOT attr_stmt type.
   * 
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
   */
  public class VizASType {
      private final String name;
      private final String typeName;
      private static final Hashtable types = new Hashtable();
  
      public static final VizASType GRAPH =
          new VizASType("graph", "graph");
  
      public static final VizASType EDGE =
          new VizASType("edge", "edge");
  
      public static final VizASType EDGE_ANT =
          new VizASType("edge.ant", "edge");
  
      public static final VizASType EDGE_ANTCALL =
          new VizASType("edge.antcall", "edge");
  
      public static final VizASType EDGE_DEPENDS =
          new VizASType("edge.depends", "edge");
  
      public static final VizASType NODE =
          new VizASType("node", "node");
  
      public static final VizASType NODE_DEFAULT =
          new VizASType("node.default", "node");
  
      private VizASType (String name, String typeName) {
          this.name = name;
          this.typeName = typeName;
  	types.put(name, this);
      }
  
      /**
       * get type instance.
       */
      public static VizASType get(String name) throws BuildException {
  	VizASType result = (VizASType)types.get(name);
  	if (result == null) {
  	    throw new BuildException(name + " is not a legal value for attrstmt type");
  	}
  	return result;
      }
  
      /**
       * get attr_stmt type (node|graph|edge).
       */
      public String getType() {
          return typeName;
      }
  
      public String toString() {
          return name;
      }
  }
  
  
  
  
  
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizAttr.java
  
  Index: VizAttr.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizAttr.java,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
   
  package org.apache.alexandria.vizant;
  
  /**
   * &lt;attr&gt; nested element handler. &lt;attr&gt; represents an
   * attribute in the DOT language.
   * 
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
   */
  public class VizAttr {
      private String name = null;
      private String value = null;
  
      /**
       * Set the name of this attirubte.
       */
      public void setName(String name) {
          this.name = name;
      }
  
      /**
       * Set the value of this attirubte.
       */
      public void setValue(String value) {
          this.value = value;
      }
  
      /**
       * Get the name of this attribute.
       */
      public String getName() {
          return name;
      }
  
      /**
       * Get the value of this attribute.
       */
      public String getValue() {
          return value;
      }
  
      public String toString() {
  	return name + "=" + value;
      }
  }
  
  
  
  
  
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizAttrStmt.java
  
  Index: VizAttrStmt.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizAttrStmt.java,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
   
  package org.apache.alexandria.vizant;
  
  import java.util.Vector;
  import java.util.Hashtable;
  import java.util.Enumeration;
  import org.apache.tools.ant.BuildException;
  
  /**
   * &lt;attrstmt&gt; nested element handler. &lt;attrstmt&gt; represents
   * attr_stmt in <a href="http://www.research.att.com/~erg/graphviz/info/lang.html" target="_blank">the DOT language</a>.
   * 
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
   */
  public class VizAttrStmt {
      /** attribute statement type */
      private VizASType type = null;
      /** attributes table */
      private Vector attrs = new Vector();
  
      /**
       * set attribute statement type.
       */
      public void setType(String type) throws BuildException {
          this.type = VizASType.get(type);
      }
  
      /**
       * get attribute statement type.
       */
      public VizASType getType() {
          return type;
      }
  
      /**
       * add &lt;attr&gt; nested element.
       */
      public void addConfiguredAttr(VizAttr attr) {
  	addAttribute(attr);
      }
  
      /**
       * add attribute.
       */
      public void addAttribute(VizAttr attr) {
  	Enumeration enum = attrs.elements();
  	while (enum.hasMoreElements()) {
  	    VizAttr a = (VizAttr)enum.nextElement();
  	    if (a.getName().equals(attr.getName())) {
  		a.setValue(attr.getValue());
  		return;
  	    }
  	}
  	attrs.addElement(attr);
      }
  
      /**
       * add attribute.
       *
       * @param name Name of the attribute.
       * @param value Value of the attribute.
       */
      public void addAttribute(String name, String value) {
  	VizAttr attr = new VizAttr();
  	attr.setName(name);
  	attr.setValue(value);
  	addAttribute(attr);
      }
  
      /**
       * add attribute(s) from the other attrstmt.
       */
      public void addAttribute(VizAttrStmt attrstmt) {
  	if (! type.equals(attrstmt.getType()))
  	    return;
          Enumeration enum = attrstmt.getAttributes();
          while (enum.hasMoreElements()) {
              addAttribute((VizAttr)enum.nextElement());
          }
      }
  
      /**
       * get attributes as Enumeration.
       */
      public Enumeration getAttributes() {
          return attrs.elements();
      }
  
      protected void checkConfiguration() throws BuildException {
          if (this.type == null)
              throw new BuildException("attrstmt: type attribute is required.");
      }
  
      public String toString() {
  	StringBuffer buffer = new StringBuffer();
  	buffer.append(type).append(" [ ");
  	Enumeration enum = getAttributes();
  	while (enum.hasMoreElements()) {
  	    buffer.append(enum.nextElement().toString()).append(" ");
  	}
  	buffer.append("]");
  	return buffer.toString();
      }
  }
  
  
  
  
  
  
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizPrinter.java
  
  Index: VizPrinter.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizPrinter.java,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
   
  package org.apache.alexandria.vizant;
  
  import java.util.Hashtable;
  import java.util.Vector;
  import java.util.Enumeration;
  
  /**
   * A class to print xml graph of dependencies.
   * 
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
   * @author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
   */
  public class VizPrinter {
      /** the projects which will be printed */
      private Vector projects = new Vector();
      /** table of attribute statement (VizASType to VizAttrStmt) */
      private Hashtable attrMap;
      /** table of subgraph attribute statement (VizASType to VizAttrStmt) */
      private Hashtable subgraphAttrMap;
      /** output */
      private VizWriter out;
      /** graph ID. The default value is 'G'. */
      private String graphid = "G";
      /** wheter to use cluster or not */
      private boolean noCluster = false;
      /** print only the targets which are depended from this target */
      private String targetFrom = "";
      /** print only the targets which depend on this target */
      private String targetTo = "";
      /** the namespace of node id */
      private IDTable idtable;
      private int indentLevel = 0;
      private final String indent;
  
      public VizPrinter() {
  	attrMap = getDefaultAttrMap();
  	subgraphAttrMap = new Hashtable();
  	indent = "    ";
      }
  
      /**
       * return default attributes.
       */
      private Hashtable getDefaultAttrMap() {
          Hashtable result = new Hashtable();
          VizAttrStmt graphAttrs = new VizAttrStmt();
  	graphAttrs.setType("graph");
          graphAttrs.addAttribute("rankdir", "LR");
          result.put(graphAttrs.getType(), graphAttrs);
          return result;
      }
  
      /**
       * add a project which will be printed.
       */
      public void addProject(VizProject project) {
          projects.addElement(project);
      }
  
      public void setGraphid(String graphid) {
          this.graphid = graphid;
      }
  
      public void setNocluster(boolean noCluster) {
          this.noCluster = noCluster;
      }
  
      public void setFrom(String targetName) {
          this.targetFrom = targetName;
      }
  
      public void setTo(String targetName) {
          this.targetTo = targetName;
      }
  
      public void setWriter(VizWriter out) {
          this.out = out;
      }
  
      public void printIndent() {
          for (int i = 0; i < indentLevel; i++) {
              out.print(indent);
          }
      }
  
      /**
       * print indent + string.
       */
      public void print(String str) {
          printIndent();
          out.print(str);
      }
  
      /**
       * print indent + string + line break.
       */
      public void println(String str) {
          printIndent();
          out.println(str);
      }
  
      /**
       * add attributes
       *
       * @param attrstmt attribute statement
       */
      public void addAttributeStatement(VizAttrStmt attrstmt) {
          addAttributeStatement(attrMap, attrstmt);
      }
  
      /**
       * add subgraph attributes
       *
       * @param attrstmt attribute statement
       */
      public void addSubgraphAttributeStatement(VizAttrStmt attrstmt) {
          addAttributeStatement(subgraphAttrMap, attrstmt);
      }
  
      /**
       * add attributes to the attribute table.
       *
       * @param map attribute table
       * @param attrstmt attribute statement
       */
      protected void addAttributeStatement(Hashtable table,
  					 VizAttrStmt attrstmt) {
          VizASType type = attrstmt.getType();
          VizAttrStmt oldAttrstmt = 
              (VizAttrStmt)table.get(type);
          if (oldAttrstmt == null) {
              table.put(type, attrstmt);
          } else {
              oldAttrstmt.addAttribute(attrstmt);
          }
      }
  
      /**
       * escape special characters in the ID.
       */
      private String escapeId(String id) {
  	id = replace(id, "\\", "\\\\");
  	id = replace(id, "\"", "\\\"");
  	return id;
      }
  
      private String getQuotedId(String id) {
          return "\"" + escapeId(id) + "\"";
      }
  
      public void printAttrStmt(VizAttrStmt as) {
          Enumeration enum = as.getAttributes();
          while (enum.hasMoreElements()) {
  	    VizAttr attr = (VizAttr)enum.nextElement();
  
  	    // The attribute value must be raw. DO NOT ESCAPE.
  	    // Some escape sequence exists: 
  	    // justification: \r \l \n
  	    // conversion: \N
  	    // \xT \xt \xD \xd \xf \xb \xx
              out.print("<attribute name="+getQuotedId(attr.getName()) + " value=\"" + attr.getValue() + "\" />");
          }
      }
  
      public boolean printAttrIfExists(Hashtable map, VizASType type) {
          if (map.get(type) != null) {
              printAttrStmt((VizAttrStmt)map.get(type));
              return true;
          }
          return false;
      }
  
  
      private void filterReferences() {
          if (! "".equals(targetFrom)) {
              Vector targets = new Vector();
              VizTarget from = 
                  ((VizProject)projects.elementAt(0)).getTarget(targetFrom);
              if (from != null)
                  addReferredTargets(from, targets, false);
              eraseNotContainsTargets(targets);
          }
  
          if (! "".equals(targetTo)) {
              Vector targets = new Vector();
              VizTarget to = 
                  ((VizProject)projects.elementAt(0)).getTarget(targetTo);
              if (to != null)
                  addReferredTargets(to, targets, true);
              eraseNotContainsTargets(targets);
              filterReferences(targets);
          }
      }
  
      private void filterReferences(Vector targets) {
          Enumeration enum = projects.elements();
          while (enum.hasMoreElements()) {
              Enumeration targetEnum = ((VizProject)enum.nextElement())
                  .getOrderedTargets().elements();
              while (targetEnum.hasMoreElements()) {
                  VizTarget target = (VizTarget)targetEnum.nextElement();
                  target.filterReferences(targets);
              }
          }
      }
  
      private void eraseNotContainsTargets(Vector targets) {
          Vector newProjects = new Vector();
          Enumeration enum = projects.elements();
          while (enum.hasMoreElements()) {
              VizProject oldp = (VizProject)enum.nextElement();
              VizProject newp = new VizProject();
              oldp.copyAttributes(newp);
              Enumeration targetEnum = oldp.getOrderedTargets().elements();
              while (targetEnum.hasMoreElements()) {
                  VizTarget target = (VizTarget)targetEnum.nextElement();
                  if (targets.contains(target)) {
                      target.setProject(newp);
                      newp.appendTarget(target);
                  }
              }
              newProjects.addElement(newp);
          }
          projects = newProjects;
      }
  
  
      private void addReferredTargets(VizTarget target, Vector set, 
  				    boolean backward) {
          if (set.contains(target)) {
              return;
          }
          set.addElement(target);
  	Vector refs;
  	if (backward) {
  	    refs = target.getReferencesIn();
  	} else {
  	    refs = target.getReferencesOut();
  	}
          Enumeration enum = refs.elements();
  	while (enum.hasMoreElements()) {
  	    VizReference ref = (VizReference)enum.nextElement();
  	    VizTarget t = (backward) ? ref.getFrom() : ref.getTo();
  	    addReferredTargets(t, set, backward);
  	}
      }
  
      protected void printBaseAttributes(Hashtable map) {
          printAttributeStatement(map, VizASType.GRAPH);
          printAttributeStatement(map, VizASType.NODE);
          printAttributeStatement(map, VizASType.EDGE);
      }
  
      public void printAttributeStatement(Hashtable map, VizASType type) {
          if (map.get(type) != null) {
              print("<attributes type=\""+type.getType()+"\">");
              printAttrIfExists(map, type);
              out.println("</attributes>");
          }
      }
  
      public void printDefaultNodeAttributes(boolean isSubgraph) {
  	if (isSubgraph &&
  	    printAttrIfExists(subgraphAttrMap, VizASType.NODE_DEFAULT)) {
  	    return;
  	}
  	printAttrIfExists(attrMap, VizASType.NODE_DEFAULT);
      }
  
  
      public IDTable createIDTable(Vector projects) {
  	return new IDTable(projects);
      }
  
      public void print() {
          filterReferences();
  	idtable = createIDTable(projects);
  
          out.println("<?xml version=\"1.0\"?>\n<graph name=" + getQuotedId(graphid)+ ">\n");
          indentLevel++;
  
          printBaseAttributes(attrMap);
  
          int subgraphNum = 0;
          Vector clusterRefs = new Vector();
  
          Enumeration enum = projects.elements();
          while (enum.hasMoreElements()) {
  	    printProject((VizProject)enum.nextElement(),
  			 clusterRefs, subgraphNum);
              subgraphNum++;
          }
  	printClusterRefs(clusterRefs);
  
          indentLevel--;
          out.println("</graph>");
      }
  
  
      private void printProject(VizProject project, 
  			      Vector clusterRefs,
  			      int subgraphNum) {
  	if (0 < subgraphNum) {
  	    println("<subgraph "
  		    + (noCluster ? "" : "numcluster=\"")
  		    + subgraphNum
  		    + "\"");
  	    indentLevel++;
  	    println(" label="
  		    + getQuotedId(project.getDir() + " "
  				  + project.getFile())
  		    + " ");
  	    printBaseAttributes(subgraphAttrMap);
              println(">");	    
  	}
  	Enumeration targetEnum = project.getOrderedTargets().elements();
  	while (targetEnum.hasMoreElements()) {
  	    printTarget((VizTarget)targetEnum.nextElement(), project,
  			clusterRefs, (0 < subgraphNum));
  	}
  	if (0 < subgraphNum) {
  	    indentLevel--;
  	    println("</subgraph>");
  	}
      }
  
  
      private void printTarget(VizTarget target,
  			     VizProject project,
  			     Vector clusterRefs,
  			     boolean isSubgraph) {
  	String id = idtable.getId(target);
  	print("<node id=" + getQuotedId(id));
  	
  	String label = target.getId();
  	label = ("".equals(label)) ? "(default)" : label;
  	if (isSubgraph && noCluster) {
  	    label = escapeId(project.getDir() + " " 
  			     + project.getFile())
  		+ "\\n" + escapeId(label);
  	    out.print(" label=\"" + label + "\"");
  	} else if (! id.equals(label)) {
  	    out.print(" label=" + getQuotedId(label) + " ");
  	}
  	if (target.isDefault()) {
  	    printDefaultNodeAttributes(isSubgraph);
  	}
  	out.println("/>");
  
  	Enumeration refs = target.getReferencesOut().elements();
  	while (refs.hasMoreElements()) {
  	    VizReference ref = (VizReference)refs.nextElement();
  	    if (ref.getType() == VizReference.ANT) {
  		clusterRefs.addElement(ref);
  	    } else {
  		String refid = idtable.getId(ref.getTo());
  		print("<edge from="+getQuotedId(id) + " to=" + getQuotedId(refid) + " ");
  		if (ref.getType() == VizReference.DEPENDS) {
  		    printAttrIfExists(attrMap, VizASType.EDGE_DEPENDS);
  		} else if (ref.getType() == VizReference.ANTCALL) {
  		    printAttrIfExists(attrMap, VizASType.EDGE_ANTCALL);
  		}
  		out.println("/>\n");
  	    }
  	}
      }
  
  
      private void printClusterRefs(Vector clusterRefs) {
          Enumeration enum = clusterRefs.elements();
          while (enum.hasMoreElements()) {
              VizReference ref = (VizReference)enum.nextElement();
              String from = idtable.getId(ref.getFrom());
              String to = idtable.getId(ref.getTo());
              print("<edge from="+getQuotedId(from) + " to=" + getQuotedId(to) + " ");
              printAttrIfExists(attrMap, VizASType.EDGE_ANT);
  	    print("/>\n");
          }
      }
  
      /**
       * replace string.
       */
      private String replace(String in, String before, String after) {
          if (in.length() == 0)
              return "";
          if (before.length() == 0)
              return in;
  
          int start = 0;
          int end = -1;
          int len = before.length();
          StringBuffer result = new StringBuffer(in.length());
          
          while ((end = in.indexOf(before, start)) != -1) {
              result.append(in.substring(start, end));
              result.append(after);
              start = end + len;
          }
          result.append(in.substring(start));
          return result.toString();
      }
  
  
      public class IDTable {
  	private Hashtable ids;
  
  	public IDTable(Vector projects) {
  	    this.ids = getIdTable(projects);
  	}
  
  	public String getId(VizTarget target) {
  	    return (String)ids.get(target);
  	}
  
  	public String toString() {
  	    return ids.toString();
  	}
  
  	private Hashtable getIdTable(Vector projects) {
  	    Hashtable result = new Hashtable();
  	    Vector idSet = new Vector();
  
  	    Enumeration enum = projects.elements();
  	    while (enum.hasMoreElements()) {
  		VizProject project = (VizProject)enum.nextElement();
  		Vector targetlist = project.getOrderedTargets();
  		Enumeration targetEnum = targetlist.elements();
  		while (targetEnum.hasMoreElements()) {
  		    VizTarget target = (VizTarget)targetEnum.nextElement();
  		    String label = target.getId();
  		    label = ("".equals(label)) ? "(default)" : label;
  		    String id = label;
  		    int idSuffixNum = 0;
  		    while (idSet.contains(id)) {
  			id = label + "-" + (++idSuffixNum);
  		    }
  		    idSet.addElement(id);
  		    result.put(target, id);
  		}
  	    }
  	    return result;
  	}
      }
  }
  
  
  
  
  
  
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizPrinter.java.old
  
  Index: VizPrinter.java.old
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizPrinter.java.old,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.alexandria.vizant;
  
  import java.util.Hashtable;
  import java.util.Vector;
  import java.util.Enumeration;
  
  /**
   * A class to print DOT.
   * 
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
   */
  public class VizPrinter {
      /** the projects which will be printed */
      private Vector projects = new Vector();
      /** table of attribute statement (VizASType to VizAttrStmt) */
      private Hashtable attrMap;
      /** table of subgraph attribute statement (VizASType to VizAttrStmt) */
      private Hashtable subgraphAttrMap;
      /** output */
      private VizWriter out;
      /** graph ID. The default value is 'G'. */
      private String graphid = "G";
      /** wheter to use cluster or not */
      private boolean noCluster = false;
      /** print only the targets which are depended from this target */
      private String targetFrom = "";
      /** print only the targets which depend on this target */
      private String targetTo = "";
      /** the namespace of node id */
      private IDTable idtable;
      private int indentLevel = 0;
      private final String indent;
  
      public VizPrinter() {
  	attrMap = getDefaultAttrMap();
  	subgraphAttrMap = new Hashtable();
  	indent = "    ";
      }
  
      /**
       * return default attributes.
       */
      private Hashtable getDefaultAttrMap() {
          Hashtable result = new Hashtable();
          VizAttrStmt graphAttrs = new VizAttrStmt();
  	graphAttrs.setType("graph");
          graphAttrs.addAttribute("rankdir", "LR");
          result.put(graphAttrs.getType(), graphAttrs);
          return result;
      }
  
      /**
       * add a project which will be printed.
       */
      public void addProject(VizProject project) {
          projects.addElement(project);
      }
  
      public void setGraphid(String graphid) {
          this.graphid = graphid;
      }
  
      public void setNocluster(boolean noCluster) {
          this.noCluster = noCluster;
      }
  
      public void setFrom(String targetName) {
          this.targetFrom = targetName;
      }
  
      public void setTo(String targetName) {
          this.targetTo = targetName;
      }
  
      public void setWriter(VizWriter out) {
          this.out = out;
      }
  
      public void printIndent() {
          for (int i = 0; i < indentLevel; i++) {
              out.print(indent);
          }
      }
  
      /**
       * print indent + string.
       */
      public void print(String str) {
          printIndent();
          out.print(str);
      }
  
      /**
       * print indent + string + line break.
       */
      public void println(String str) {
          printIndent();
          out.println(str);
      }
  
      /**
       * add attributes
       *
       * @param attrstmt attribute statement
       */
      public void addAttributeStatement(VizAttrStmt attrstmt) {
          addAttributeStatement(attrMap, attrstmt);
      }
  
      /**
       * add subgraph attributes
       *
       * @param attrstmt attribute statement
       */
      public void addSubgraphAttributeStatement(VizAttrStmt attrstmt) {
          addAttributeStatement(subgraphAttrMap, attrstmt);
      }
  
      /**
       * add attributes to the attribute table.
       *
       * @param map attribute table
       * @param attrstmt attribute statement
       */
      protected void addAttributeStatement(Hashtable table,
  					 VizAttrStmt attrstmt) {
          VizASType type = attrstmt.getType();
          VizAttrStmt oldAttrstmt = 
              (VizAttrStmt)table.get(type);
          if (oldAttrstmt == null) {
              table.put(type, attrstmt);
          } else {
              oldAttrstmt.addAttribute(attrstmt);
          }
      }
  
      /**
       * escape special characters in the ID.
       */
      private String escapeId(String id) {
  	id = replace(id, "\\", "\\\\");
  	id = replace(id, "\"", "\\\"");
  	return id;
      }
  
      private String getQuotedId(String id) {
          return "\"" + escapeId(id) + "\"";
      }
  
      public void printAttrStmt(VizAttrStmt as) {
          out.print(" [");
          Enumeration enum = as.getAttributes();
          while (enum.hasMoreElements()) {
  	    VizAttr attr = (VizAttr)enum.nextElement();
  
  	    // The attribute value must be raw. DO NOT ESCAPE.
  	    // Some escape sequence exists: 
  	    // justification: \r \l \n
  	    // conversion: \N
  	    // \xT \xt \xD \xd \xf \xb \xx
              out.print(getQuotedId(attr.getName()) + "=\""
  		      + attr.getValue() + "\",");
          }
          out.print("]");
      }
  
      public boolean printAttrIfExists(Hashtable map, VizASType type) {
          if (map.get(type) != null) {
              printAttrStmt((VizAttrStmt)map.get(type));
              return true;
          }
          return false;
      }
  
  
      private void filterReferences() {
          if (! "".equals(targetFrom)) {
              Vector targets = new Vector();
              VizTarget from = 
                  ((VizProject)projects.elementAt(0)).getTarget(targetFrom);
              if (from != null)
                  addReferredTargets(from, targets, false);
              eraseNotContainsTargets(targets);
          }
  
          if (! "".equals(targetTo)) {
              Vector targets = new Vector();
              VizTarget to = 
                  ((VizProject)projects.elementAt(0)).getTarget(targetTo);
              if (to != null)
                  addReferredTargets(to, targets, true);
              eraseNotContainsTargets(targets);
              filterReferences(targets);
          }
      }
  
      private void filterReferences(Vector targets) {
          Enumeration enum = projects.elements();
          while (enum.hasMoreElements()) {
              Enumeration targetEnum = ((VizProject)enum.nextElement())
                  .getOrderedTargets().elements();
              while (targetEnum.hasMoreElements()) {
                  VizTarget target = (VizTarget)targetEnum.nextElement();
                  target.filterReferences(targets);
              }
          }
      }
  
      private void eraseNotContainsTargets(Vector targets) {
          Vector newProjects = new Vector();
          Enumeration enum = projects.elements();
          while (enum.hasMoreElements()) {
              VizProject oldp = (VizProject)enum.nextElement();
              VizProject newp = new VizProject();
              oldp.copyAttributes(newp);
              Enumeration targetEnum = oldp.getOrderedTargets().elements();
              while (targetEnum.hasMoreElements()) {
                  VizTarget target = (VizTarget)targetEnum.nextElement();
                  if (targets.contains(target)) {
                      target.setProject(newp);
                      newp.appendTarget(target);
                  }
              }
              newProjects.addElement(newp);
          }
          projects = newProjects;
      }
  
  
      private void addReferredTargets(VizTarget target, Vector set, 
  				    boolean backward) {
          if (set.contains(target)) {
              return;
          }
          set.addElement(target);
  	Vector refs;
  	if (backward) {
  	    refs = target.getReferencesIn();
  	} else {
  	    refs = target.getReferencesOut();
  	}
          Enumeration enum = refs.elements();
  	while (enum.hasMoreElements()) {
  	    VizReference ref = (VizReference)enum.nextElement();
  	    VizTarget t = (backward) ? ref.getFrom() : ref.getTo();
  	    addReferredTargets(t, set, backward);
  	}
      }
  
      protected void printBaseAttributes(Hashtable map) {
          printAttributeStatement(map, VizASType.GRAPH);
          printAttributeStatement(map, VizASType.NODE);
          printAttributeStatement(map, VizASType.EDGE);
      }
  
      public void printAttributeStatement(Hashtable map, VizASType type) {
          if (map.get(type) != null) {
              print(type.getType());
              printAttrIfExists(map, type);
              out.println(";");
          }
      }
  
      public void printDefaultNodeAttributes(boolean isSubgraph) {
  	if (isSubgraph &&
  	    printAttrIfExists(subgraphAttrMap, VizASType.NODE_DEFAULT)) {
  	    return;
  	}
  	printAttrIfExists(attrMap, VizASType.NODE_DEFAULT);
      }
  
  
      public IDTable createIDTable(Vector projects) {
  	return new IDTable(projects);
      }
  
      public void print() {
          filterReferences();
  	idtable = createIDTable(projects);
  
          out.println("digraph " + getQuotedId(graphid) + " {");
          indentLevel++;
  
          printBaseAttributes(attrMap);
  
          int subgraphNum = 0;
          Vector clusterRefs = new Vector();
  
          Enumeration enum = projects.elements();
          while (enum.hasMoreElements()) {
  	    printProject((VizProject)enum.nextElement(),
  			 clusterRefs, subgraphNum);
              subgraphNum++;
          }
  	printClusterRefs(clusterRefs);
  
          indentLevel--;
          out.println("}");
      }
  
  
      private void printProject(VizProject project, 
  			      Vector clusterRefs,
  			      int subgraphNum) {
  	if (0 < subgraphNum) {
  	    println("subgraph \""
  		    + (noCluster ? "" : "cluster:")
  		    + subgraphNum
  		    + "\" {");
  	    indentLevel++;
  	    println("\"label\"="
  		    + getQuotedId(project.getDir() + " "
  				  + project.getFile())
  		    + ";");
  	    printBaseAttributes(subgraphAttrMap);
  	}
  	Enumeration targetEnum = project.getOrderedTargets().elements();
  	while (targetEnum.hasMoreElements()) {
  	    printTarget((VizTarget)targetEnum.nextElement(), project,
  			clusterRefs, (0 < subgraphNum));
  	}
  	if (0 < subgraphNum) {
  	    indentLevel--;
  	    println("}");
  	}
      }
  
  
      private void printTarget(VizTarget target,
  			     VizProject project,
  			     Vector clusterRefs,
  			     boolean isSubgraph) {
  	String id = idtable.getId(target);
  	print(getQuotedId(id));
  	
  	String label = target.getId();
  	label = ("".equals(label)) ? "(default)" : label;
  	if (isSubgraph && noCluster) {
  	    label = escapeId(project.getDir() + " " 
  			     + project.getFile())
  		+ "\\n" + escapeId(label);
  	    out.print(" [\"label\"=\"" + label + "\"]");
  	} else if (! id.equals(label)) {
  	    out.print(" [\"label\"=" + getQuotedId(label) + "]");
  	}
  	if (target.isDefault()) {
  	    printDefaultNodeAttributes(isSubgraph);
  	}
  	out.println(";");
  
  	Enumeration refs = target.getReferencesOut().elements();
  	while (refs.hasMoreElements()) {
  	    VizReference ref = (VizReference)refs.nextElement();
  	    if (ref.getType() == VizReference.ANT) {
  		clusterRefs.addElement(ref);
  	    } else {
  		String refid = idtable.getId(ref.getTo());
  		print(getQuotedId(id) + " -> " + getQuotedId(refid));
  		if (ref.getType() == VizReference.DEPENDS) {
  		    printAttrIfExists(attrMap, VizASType.EDGE_DEPENDS);
  		} else if (ref.getType() == VizReference.ANTCALL) {
  		    printAttrIfExists(attrMap, VizASType.EDGE_ANTCALL);
  		}
  		out.println(";");
  	    }
  	}
      }
  
  
      private void printClusterRefs(Vector clusterRefs) {
          Enumeration enum = clusterRefs.elements();
          while (enum.hasMoreElements()) {
              VizReference ref = (VizReference)enum.nextElement();
              String from = idtable.getId(ref.getFrom());
              String to = idtable.getId(ref.getTo());
              print(getQuotedId(from) + " -> " + getQuotedId(to));
              printAttrIfExists(attrMap, VizASType.EDGE_ANT);
              out.println(";");
          }
      }
  
      /**
       * replace string.
       */
      private String replace(String in, String before, String after) {
          if (in.length() == 0)
              return "";
          if (before.length() == 0)
              return in;
  
          int start = 0;
          int end = -1;
          int len = before.length();
          StringBuffer result = new StringBuffer(in.length());
          
          while ((end = in.indexOf(before, start)) != -1) {
              result.append(in.substring(start, end));
              result.append(after);
              start = end + len;
          }
          result.append(in.substring(start));
          return result.toString();
      }
  
  
      public class IDTable {
  	private Hashtable ids;
  
  	public IDTable(Vector projects) {
  	    this.ids = getIdTable(projects);
  	}
  
  	public String getId(VizTarget target) {
  	    return (String)ids.get(target);
  	}
  
  	public String toString() {
  	    return ids.toString();
  	}
  
  	private Hashtable getIdTable(Vector projects) {
  	    Hashtable result = new Hashtable();
  	    Vector idSet = new Vector();
  
  	    Enumeration enum = projects.elements();
  	    while (enum.hasMoreElements()) {
  		VizProject project = (VizProject)enum.nextElement();
  		Vector targetlist = project.getOrderedTargets();
  		Enumeration targetEnum = targetlist.elements();
  		while (targetEnum.hasMoreElements()) {
  		    VizTarget target = (VizTarget)targetEnum.nextElement();
  		    String label = target.getId();
  		    label = ("".equals(label)) ? "(default)" : label;
  		    String id = label;
  		    int idSuffixNum = 0;
  		    while (idSet.contains(id)) {
  			id = label + "-" + (++idSuffixNum);
  		    }
  		    idSet.addElement(id);
  		    result.put(target, id);
  		}
  	    }
  	    return result;
  	}
      }
  }
  
  
  
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizProject.java
  
  Index: VizProject.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizProject.java,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
   
  package org.apache.alexandria.vizant;
  
  import java.util.Hashtable;
  import java.util.Vector;
  
  /**
   * Ant project.
   * 
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
   */
  public class VizProject {
      private String dir = "";
      private String file = "";
      private Hashtable allTargets = new Hashtable();
      private Vector orderedTargets = new Vector();
  
      public void setDir(String dir) {
          this.dir = dir;
      }
  
      public String getDir() {
          return dir;
      }
  
      public void setFile(String file) {
          this.file = file;
      }
  
      public String getFile() {
          return file;
      }
  
      public void copyAttributes(VizProject project) {
          project.setDir(getDir());
          project.setFile(getFile());
      }
  
      public void appendTarget(VizTarget target) {
          if (! orderedTargets.contains(target)) {
              orderedTargets.addElement(target);
              if (! allTargets.contains(target))
                  allTargets.put(target.getId(), target);
          }
      }
  
      public VizTarget getTarget(String id) {
          VizTarget target = (VizTarget)allTargets.get(id);
          if (target == null) {
              target = new VizTarget();
              target.setId(id);
              target.setProject(this);
              allTargets.put(target.getId(), target);
          }
          return target;
      }
  
      public Vector getOrderedTargets() {
          return orderedTargets;
      }
  
      public String toString() {
          return "VizProject:" 
              + " dir:" + dir
              + " file:" + file
              + " allTargets:" + allTargets
              + " orderedTargets:" + orderedTargets;
      }
  
  }
  
  
  
  
  
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizProjectLoader.java
  
  Index: VizProjectLoader.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizProjectLoader.java,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
   
  package org.apache.alexandria.vizant;
  
  import java.io.InputStream;
  import java.util.Vector;
  import org.apache.tools.ant.BuildException;
  
  /**
   * Project loader.
   * 
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
   */
  public interface VizProjectLoader {
      public void uniqueRef(boolean opt);
      public void ignoreAnt(boolean opt);
      public void ignoreAntcall(boolean opt);
      public void ignoreDepends(boolean opt);
      public void setInputStream(InputStream stream);
      public Vector getProjects() throws BuildException;
  }
  
  
  
  
  
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizProjectLoaderImpl.java
  
  Index: VizProjectLoaderImpl.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizProjectLoaderImpl.java,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
   
  package org.apache.alexandria.vizant;
  
  
  
  import java.util.Vector;
  
  import java.util.Enumeration;
  
  import java.util.StringTokenizer;
  
  import java.io.File;
  
  import java.io.InputStream;
  
  import java.io.IOException;
  
  
  
  import org.xml.sax.InputSource;
  
  import org.xml.sax.SAXException;
  
  import org.xml.sax.helpers.DefaultHandler;
  
  import org.xml.sax.Attributes;
  
  import javax.xml.parsers.SAXParser;
  
  import javax.xml.parsers.SAXParserFactory;
  
  import javax.xml.parsers.ParserConfigurationException;
  
  
  
  import org.apache.tools.ant.BuildException;
  
  
  
  /**
  
   * An implementation of VizProjectLoader.
  
   * 
  
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
  
   */
  
  public class VizProjectLoaderImpl implements VizProjectLoader {
  
      private InputStream stream;
  
      private boolean uniqueref;
  
      private boolean ignoreAnt;
  
      private boolean ignoreAntcall;
  
      private boolean ignoreDepends;
  
  
  
      public VizProjectLoaderImpl() {
  
  	uniqueref = false;
  
  	ignoreAnt = false;
  
  	ignoreAntcall = false;
  
  	ignoreDepends = false;
  
      }
  
  
  
      public void uniqueRef(boolean uniqueref) {
  
  	this.uniqueref = uniqueref;
  
      }
  
  
  
      public void ignoreAnt(boolean ignoreAnt) {
  
  	this.ignoreAnt = ignoreAnt;
  
      }
  
  
  
      public void ignoreAntcall(boolean ignoreAntcall) {
  
  	this.ignoreAntcall = ignoreAntcall;
  
      }
  
  
  
      public void ignoreDepends(boolean ignoreDepends) {
  
  	this.ignoreDepends = ignoreDepends;
  
      }
  
  
  
      public void setInputStream(InputStream stream) {
  
  	this.stream = stream;
  
      }
  
  
  
      public Vector getProjects() throws BuildException {
  
  	try {
  
              SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
  
  	    SAXHandler handler = new SAXHandler();
  
  	    parser.parse(new InputSource(stream), handler);
  
  	    return handler.getProjects();
  
  	} catch(SAXException e) {
  
  	    throw new BuildException(e);
  
  	} catch(ParserConfigurationException e) {
  
  	    throw new BuildException(e);
  
  	} catch(IOException e) {
  
  	    throw new BuildException(e);
  
  	}
  
      }
  
  
  
      private class SAXHandler extends DefaultHandler {
  
  	private String defaultName;
  
  	private Vector projects;
  
  	private VizTarget target;
  
  	private VizProject baseProject;
  
  
  
  	public SAXHandler() {
  
  	    defaultName = "main";
  
  	    baseProject = new VizProject();
  
  	}
  
  
  
  	public Vector getProjects() {
  
  	    return projects;
  
  	}
  
  
  
  	public void startDocument() {
  
  	    projects = new Vector();
  
  	    projects.addElement(baseProject);
  
  	}
  
  
  
  	public void startElement (String uri, 
  
  				  String name, 
  
  				  String qName, 
  
  				  Attributes atts) {
  
  	    if ("project".equals(qName)) {
  
  		String def = atts.getValue("default");
  
  		String dir = atts.getValue("dir");
  
  		if (def != null)
  
  		    defaultName = def;
  
  		if (dir != null)
  
  		    baseProject.setDir(dir);
  
  	    } else if ("target".equals(qName)) {
  
  		String targetName = atts.getValue("name");
  
  		String depends = atts.getValue("depends");
  
  		target = baseProject.getTarget(targetName);
  
  		target.setDefault(targetName.equals(defaultName));
  
  		baseProject.appendTarget(target);
  
  		if (null != depends && ! ignoreDepends)
  
  		    addDepends(target, depends);
  
  	    } else if ("antcall".equals(qName)) {
  
  		if (! ignoreAntcall)
  
  		    addAntCall(target, atts.getValue("target"));
  
  	    } else if ("ant".equals(qName)) {
  
  		if (! ignoreAnt)
  
  		    addAnt(target, 
  
  			   atts.getValue("dir"),
  
  			   atts.getValue("antfile"),
  
  			   atts.getValue("target"));
  
  	    }
  
  	}
  
  	
  
  	private void addReference(VizTarget from, VizTarget to, int type) {
  
  	    VizReference reference = new VizReference();
  
  	    reference.setFrom(from);
  
  	    reference.setTo(to);
  
  	    reference.setType(type);
  
  	    from.addReferenceOut(reference, uniqueref);
  
  	    to.addReferenceIn(reference, uniqueref);
  
  	}
  
  
  
  	private void addDepends(VizTarget from, String toNames) {
  
  	    StringTokenizer st = new StringTokenizer(toNames, ",");
  
  	    while (st.hasMoreTokens()) {
  
  		VizTarget to = baseProject.getTarget(st.nextToken().trim());
  
  		addReference(from, to, VizReference.DEPENDS);
  
  	    }
  
  	}
  
  
  
  	private void addAntCall(VizTarget from, String toName) {
  
  	    VizTarget to = baseProject.getTarget(toName);
  
  	    addReference(from, to, VizReference.ANTCALL);
  
  	}
  
  
  
  	private void addAnt(VizTarget from,
  
  			    String toDir, String toFile, String toName) {
  
  	    toDir = (toDir != null) ? toDir : "";
  
  	    toFile = (toFile != null) ? toFile : "";
  
  	    toName = (toName != null) ? toName : "";
  
  	    VizProject toProject = getProject(toDir, toFile);
  
  	    VizTarget to = toProject.getTarget(toName);
  
  	    if ("".equals(toName))
  
  		to.setDefault(true);
  
  	    toProject.appendTarget(to);
  
  	    addReference(from, to, VizReference.ANT);
  
  	}
  
  
  
  	private VizProject getProject(String dir, String file) {
  
  	    Enumeration enum = projects.elements();
  
  	    while(enum.hasMoreElements()) {
  
  		VizProject project = (VizProject)enum.nextElement();
  
  		if (dir.equals(project.getDir()) && file.equals(project.getFile()))
  
  		    return project;
  
  	    }
  
  	    VizProject project = new VizProject();
  
  	    project.setDir(dir);
  
  	    project.setFile(file);
  
  	    projects.addElement(project);
  
  	    return project;
  
  	}
  
      } 
  
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizReference.java
  
  Index: VizReference.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizReference.java,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
   
  package org.apache.alexandria.vizant;
  
  /**
   * Target dependency.
   * 
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
   */
  public class VizReference {
      public static final int DEPENDS = 0;
      public static final int ANTCALL = 1;
      public static final int ANT = 2;
      
      private int type = DEPENDS;
      private VizTarget from = null;
      private VizTarget to = null;
  
      public int getType() {
          return type;
      }
  
      public void setType(int type) {
          this.type = type;
      }
  
      public void setFrom(VizTarget from) {
          this.from = from;
      }
  
      public VizTarget getFrom() {
          return from;
      }
  
      public void setTo(VizTarget to) {
          this.to = to;
      }
  
      public VizTarget getTo() {
          return to;
      }
  
      public boolean equals(Object o) {
          if (! (o instanceof VizReference))
              return false;
          VizReference ref = (VizReference)o;
          if (getType() != ref.getType())
              return false;
          if (getFrom() == null && ref.getFrom() != null)
              return false;
          if (getTo() == null && ref.getTo() != null) 
              return false;
          return (getFrom().equals(ref.getFrom()) &&
                  getTo().equals(ref.getTo()));
      }
  
      public int hashCode() {
          int ret = 17;
          ret = 37 * ret + getType();
          ret = 37 * ret + ((getFrom() == null) ? 0 : getFrom().hashCode());
          ret = 37 * ret + ((getTo() == null) ? 0 : getTo().hashCode());
          return ret;
      }
  }
  
  
  
  
  
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizSubgraph.java
  
  Index: VizSubgraph.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizSubgraph.java,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
   
  package org.apache.alexandria.vizant;
  
  import org.apache.tools.ant.BuildException;
  
  /**
   * &lt;subgraph&gt; nested element handler.
   * 
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
   */
  public class VizSubgraph {
      VizPrinter printer = null;
  
      public void setPrinter(VizPrinter printer) {
          this.printer = printer;
      }
  
      public void addConfiguredAttrstmt(VizAttrStmt attrstmt) 
          throws BuildException{
          attrstmt.checkConfiguration();
          printer.addSubgraphAttributeStatement(attrstmt);
      }
  }
  
  
  
  
  
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizTarget.java
  
  Index: VizTarget.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizTarget.java,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
   
  package org.apache.alexandria.vizant;
  
  import java.util.Vector;
  import java.util.Enumeration;
  
  /**
   * Ant target.
   * 
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
   */
  public class VizTarget {
      private String id;
      private Vector referencesIn = new Vector();
      private Vector referencesOut = new Vector();
      private VizProject project;
      private boolean defaultTarget = false;
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getId() {
          return id;
      }
  
      public void setDefault(boolean defaultTarget) {
          this.defaultTarget = defaultTarget;
      }
  
      public boolean isDefault() {
          return defaultTarget;
      }
  
      public void setProject(VizProject project) {
          this.project = project;
      }
  
      public VizProject getProject() {
          return project;
      }
  
      public Vector getReferencesIn() {
          return referencesIn;
      }
  
      public Vector getReferencesOut() {
          return referencesOut;
      }
  
      public void addReferenceIn(VizReference ref, boolean unique) {
          if (unique && referencesIn.contains(ref))
              return;
          if (! this.equals(ref.getTo()))
              return;
          referencesIn.addElement(ref);
      }
  
      public void addReferenceOut(VizReference ref, boolean unique) {
          if (unique && referencesOut.contains(ref))
              return;
          if (! this.equals(ref.getFrom()))
              return;
          referencesOut.addElement(ref);
      }
  
      public void filterReferences(Vector targets) {
          referencesIn = filterReferences(targets, referencesIn);
          referencesOut = filterReferences(targets, referencesOut);
      }
  
      private Vector filterReferences(Vector targets, 
                                      Vector references) {
          Vector ret = new Vector();
          Enumeration enum = references.elements();
          while (enum.hasMoreElements()) {
              VizReference r = (VizReference)enum.nextElement();
              if(targets.contains(r.getFrom()) &&
                 targets.contains(r.getTo())) {
                  ret.addElement(r);
              }
          }
          return ret;
      }
  
      public String toString() {
          return "VizTarget: id:" + id 
              + " referencesIn:" + referencesIn
              + " referencesOut:" + referencesOut
              + " default:" + defaultTarget;
      }
  }
  
  
  
  
  
  1.1                  jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizWriter.java
  
  Index: VizWriter.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-alexandria/src/java/org/apache/alexandria/vizant/VizWriter.java,v 1.1 2003/04/11 12:17:16 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 12:17:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [email protected].
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
   
  package org.apache.alexandria.vizant;
  
  /**
   * writer.
   * 
   * @author <a href="mailto:[email protected]">KOSEKI Kengo</a>
   */
  public interface VizWriter {
      public void print(String str);
      public void println(String str);
  }