You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by me...@locus.apache.org on 2000/11/10 00:14:15 UTC
cvs commit: jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs ACSDefaultElement.java ACSElement.java ACSFactory.java ACSProjectElement.java ACSTargetElement.java acs-element.properties package.html
metasim 00/11/09 15:14:15
Added: src/antidote/org/apache/tools/ant/gui/acs
ACSDefaultElement.java ACSElement.java
ACSFactory.java ACSProjectElement.java
ACSTargetElement.java acs-element.properties
package.html
Log:
Started work on the Ant Construction Set classes (ACS), which will map directly
to DOM elements allowing easier manipulation of the XML and better editing of
Ant projects. NB: The code currently requires the Sun JAXP library (which Ant
needs anyway).
Revision Changes Path
1.1 jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSDefaultElement.java
Index: ACSDefaultElement.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999, 2000 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", "Tomcat", 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 apache@apache.org.
*
* 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.tools.ant.gui.acs;
import com.sun.xml.tree.ElementNode;
/**
* Default element used when no other element is specificed.
*
* @version $Revision: 1.1 $
* @author Simeon Fitch
*/
public class ACSDefaultElement extends ACSElement {
/**
* Default ctor.
*
*/
public ACSDefaultElement() {
}
}
1.1 jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java
Index: ACSElement.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999, 2000 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", "Tomcat", 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 apache@apache.org.
*
* 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.tools.ant.gui.acs;
import org.w3c.dom.Node;
import com.sun.xml.tree.ElementNode;
import javax.swing.tree.TreeNode;
import java.util.*;
/**
* Abstract base class for all Ant Construction Set
* elements. Depends on the JAXP XML library from Sun.
*
* @version $Revision: 1.1 $
* @author Simeon Fitch */
public abstract class ACSElement extends ElementNode implements TreeNode {
/** Cache of TreeNode only children. */
private List _treeNodeCache = null;
/**
* Default ctor.
*
*/
protected ACSElement() {
}
/**
* Get the display name of this.
*
* @return Display name.
*/
public String getDisplayName() {
return getTagName();
}
/**
* Get the cache of TreeNode only children.
*
* @return List of TreeNodes that are children.
*/
private List getCache() {
if(_treeNodeCache == null) {
_treeNodeCache = new ArrayList();
for(int i = 0; i < getLength(); i++) {
if(item(i) instanceof TreeNode) {
_treeNodeCache.add(item(i));
}
}
}
return _treeNodeCache;
}
/**
* Returns the child <code>TreeNode</code> at index
* <code>childIndex</code>.
*/
public TreeNode getChildAt(int childIndex) {
List nodes = getCache();
return (TreeNode) nodes.get(childIndex);
}
/**
* Returns the number of children <code>TreeNode</code>s the receiver
* contains.
*/
public int getChildCount() {
List nodes = getCache();
return nodes.size();
}
/**
* Returns the parent <code>TreeNode</code> of the receiver.
*/
public TreeNode getParent() {
return (TreeNode) getParent();
}
/**
* Returns the index of <code>node</code> in the receivers children.
* If the receiver does not contain <code>node</code>, -1 will be
* returned.
*/
public int getIndex(TreeNode node) {
List nodes = getCache();
return nodes.indexOf(node);
}
/**
* Returns true if the receiver allows children.
*/
public boolean getAllowsChildren() {
return true;
}
/**
* Returns true if the receiver is a leaf.
*/
public boolean isLeaf() {
List nodes = getCache();
return nodes.size() <= 0;
}
/**
* Returns the children of the reciever as an Enumeration.
*/
public Enumeration children() {
return new NodeEnum();
}
/** Internal iterator for the child nodes. */
private class NodeEnum implements Enumeration {
/** Current child index. */
private int _index = 0;
/**
* Determine if there are more elements to visit.
*
* @return True if nextElement() can be called, false otherwise.
*/
public boolean hasMoreElements() {
List nodes = getCache();
return _index < nodes.size();
}
/**
* Get the next element. hasMoreElements() must currently return true.
*
* @return Next element
*/
public Object nextElement() {
List nodes = getCache();
return nodes.get(_index++);
}
}
}
1.1 jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java
Index: ACSFactory.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999, 2000 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", "Tomcat", 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 apache@apache.org.
*
* 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.tools.ant.gui.acs;
import javax.xml.parsers.*;
import java.io.File;
import java.io.IOException;
import org.w3c.dom.*;
import com.sun.xml.parser.Parser;
import com.sun.xml.tree.SimpleElementFactory;
import com.sun.xml.tree.XmlDocument;
import com.sun.xml.tree.XmlDocumentBuilder;
import java.util.Properties;
import com.sun.xml.parser.Resolver;
/**
* Factory for loading Ant Construction set elements.
*
* @version $Revision: 1.1 $
* @author Simeon Fitch
*/
public class ACSFactory {
/** Singleton instance of the factory. */
private static ACSFactory _instance = null;
/** Element maping. */
private static final Properties _elementMap = new Properties();
static {
try {
_elementMap.load(ACSFactory.class.
getResourceAsStream("acs-element.properties"));
}
catch(Throwable ex) {
ex.printStackTrace();
System.exit(1);
}
}
/**
* Default ctor.
*
*/
private ACSFactory() {
}
/**
* Load a project from the given XML file.
* XXX fix me.
*
* @param f File to load.
* @return
*/
public ACSProjectElement load(File f) throws IOException {
XmlDocument doc = null;
try {
SAXParser sax = SAXParserFactory.newInstance().newSAXParser();
Parser parser = (Parser) sax.getParser();
XmlDocumentBuilder builder = new XmlDocumentBuilder();
builder.setIgnoringLexicalInfo(false);
SimpleElementFactory fact = new SimpleElementFactory();
fact.addMapping(_elementMap, ACSFactory.class.getClassLoader());
builder.setElementFactory(fact);
parser.setDocumentHandler(builder);
parser.setEntityResolver(new Resolver());
//parser.setErrorHandler();
sax.parse(f, null);
doc = builder.getDocument();
}
catch(Exception ex) {
ex.printStackTrace();
throw new IOException(ex.getMessage());
}
return (ACSProjectElement) doc.getDocumentElement();
}
/**
* Get an instance of the factory.
*
* @return Factory instance.
*/
public static ACSFactory getInstance() {
if(_instance == null) {
_instance = new ACSFactory();
}
return _instance;
}
/**
* Test code
*
* @param args XML file to parse.
*/
public static void main(String[] args) {
try {
ACSFactory f = ACSFactory.getInstance();
System.out.println(f.load(new File(args[0])));
}
catch(Exception ex) {
ex.printStackTrace();
}
}
}
1.1 jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElement.java
Index: ACSProjectElement.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999, 2000 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", "Tomcat", 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 apache@apache.org.
*
* 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.tools.ant.gui.acs;
import com.sun.xml.tree.ElementNode;
/**
* Class representing a project element in the build file.
*
* @version $Revision: 1.1 $
* @author Simeon Fitch
*/
public class ACSProjectElement extends ACSElement {
public ACSProjectElement() {
}
/**
* Get the project name.
*
* @return Project name.
*/
public String getName() {
return getAttribute("name");
}
/**
* Get the display name.
*
* @return Display name.
*/
public String getDisplayName() {
return getTagName() + ": " + getName();
}
}
1.1 jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElement.java
Index: ACSTargetElement.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999, 2000 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", "Tomcat", 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 apache@apache.org.
*
* 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.tools.ant.gui.acs;
import com.sun.xml.tree.ElementNode;
import java.util.StringTokenizer;
/**
* Class representing a build target.
*
* @version $Revision: 1.1 $
* @author Simeon Fitch
*/
public class ACSTargetElement extends ACSElement {
/**
* Default ctor.
*
*/
public ACSTargetElement() {
}
/**
* Get the target name.
*
* @return Target name.
*/
public String getName() {
return getAttribute("name");
}
/**
* Get the long description of the target.
*
* @return Target description.
*/
public String getDescription() {
return getAttribute("description");
}
/**
* Set the set of dependency names.
*
* @return Dependency names.
*/
public String[] getDependencyNames() {
String depends = getAttribute("depends");
StringTokenizer tok = new StringTokenizer(depends,",");
String[] retval = new String[tok.countTokens()];
for(int i = 0; i < retval.length; i++) {
retval[i] = tok.nextToken();
}
return retval;
}
/**
* Get the display name.
*
* @return Display name.
*/
public String getDisplayName() {
return getTagName() + ": " + getName();
}
}
1.1 jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/acs-element.properties
Index: acs-element.properties
===================================================================
#
# Property file mapping DOM nodes to Java class names.
#
# The default element
*Element=org.apache.tools.ant.gui.acs.ACSDefaultElement
# Specific elements.
project=org.apache.tools.ant.gui.acs.ACSProjectElement
target=org.apache.tools.ant.gui.acs.ACSTargetElement
1.1 jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/package.html
Index: package.html
===================================================================
<HTML><BODY> <H1>Ant Construction Set</H1>
<P>This package contains the tools for constructing and manipulating an Ant
build file</P>
<P><B>NB</B>: Requires the <A HREF="http://java.sun.com/xml">Java API for XML
Parsing</A> from Sun.</P>
</BODY>
</HTML>