KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > tools > ant > QuerySet


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.tools.ant;
13
14 import org.apache.tools.ant.types.AbstractFileSet;
15 import org.apache.tools.ant.Project;
16 import org.apache.tools.ant.DirectoryScanner;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 /**
23  * @keep-all
24  *
25  */

26 public class QuerySet extends AbstractFileSet {
27     private ArrayList JavaDoc packages = new ArrayList JavaDoc();
28
29     public QuerySet() {
30         super();
31     }
32
33     protected QuerySet(QuerySet fileset) {
34         super(fileset);
35     }
36
37     public Package JavaDoc createPackage() {
38         Package JavaDoc pack = new Package JavaDoc();
39         packages.add(pack);
40         return pack;
41     }
42
43     /**
44      * Return a FileSet that has the same basedir and same patternsets
45      * as this one.
46      */

47     public Object JavaDoc clone() {
48         if (isReference()) {
49             return new QuerySet((QuerySet) getRef(getProject()));
50         } else {
51             return new QuerySet(this);
52         }
53     }
54
55     public List JavaDoc getQueryClasses(Project project) {
56         ArrayList JavaDoc classlist = new ArrayList JavaDoc();
57         final String JavaDoc dotClass = ".class";
58         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
59         for (Iterator JavaDoc iterator = packages.iterator(); iterator.hasNext();) {
60             Package JavaDoc s = (Package JavaDoc) iterator.next();
61             String JavaDoc pat = s.getName();
62             if (pat.endsWith("*")) {
63                 pat = pat + "*";
64             } else {
65                 pat = pat + ".*";
66             }
67             buf.append(pat.replace('.', '/'));
68             buf.append(" ");
69
70         }
71         setIncludes(buf.toString().trim());
72         DirectoryScanner scanner = getDirectoryScanner(project);
73         String JavaDoc[] incFiles = scanner.getIncludedFiles();
74         for (int j = 0; j < incFiles.length; j++) {
75             String JavaDoc temp = incFiles[j];
76             if (temp.endsWith(dotClass)) {
77                 classlist.add(temp);
78             }
79
80         }
81         return classlist;
82     }
83
84     /**
85      * Used to track info about the packages to be
86      */

87     public static class Package {
88         /**
89          * The package name
90          */

91         private String JavaDoc name;
92
93         /**
94          * Set the name of the package
95          *
96          * @param name the package name.
97          */

98         public void setName(String JavaDoc name) {
99             this.name = name.trim();
100         }
101
102         /**
103          * Get the package name.
104          *
105          * @return the package's name.
106          */

107         public String JavaDoc getName() {
108             return name;
109         }
110
111         /**
112          * @see java.lang.Object#toString
113          */

114         public String JavaDoc toString() {
115             return getName();
116         }
117     }
118 }
119
Popular Tags