KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > DirSet


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18
19 package org.apache.tools.ant.types;
20
21 import java.util.Iterator JavaDoc;
22 import org.apache.tools.ant.DirectoryScanner;
23 import org.apache.tools.ant.types.resources.FileResourceIterator;
24
25 /**
26  * Subclass as hint for supporting tasks that the included directories
27  * instead of files should be used.
28  *
29  * @since Ant 1.5
30  */

31 public class DirSet extends AbstractFileSet implements ResourceCollection {
32
33     /**
34      * Constructor for DirSet.
35      */

36     public DirSet() {
37         super();
38     }
39
40     /**
41      * Constructor for DirSet, with DirSet to shallowly clone.
42      * @param dirset the dirset to clone.
43      */

44     protected DirSet(DirSet dirset) {
45         super(dirset);
46     }
47
48     /**
49      * Return a DirSet that has the same basedir and same patternsets
50      * as this one.
51      * @return the cloned dirset.
52      */

53     public Object JavaDoc clone() {
54         if (isReference()) {
55             return ((DirSet) getRef(getProject())).clone();
56         } else {
57             return super.clone();
58         }
59     }
60
61     /**
62      * Fulfill the ResourceCollection contract.
63      * @return an Iterator of Resources.
64      * @since Ant 1.7
65      */

66     public Iterator JavaDoc iterator() {
67         if (isReference()) {
68             return ((DirSet) getRef(getProject())).iterator();
69         }
70         return new FileResourceIterator(getDir(getProject()),
71             getDirectoryScanner(getProject()).getIncludedDirectories());
72     }
73
74     /**
75      * Fulfill the ResourceCollection contract.
76      * @return number of elements as int.
77      * @since Ant 1.7
78      */

79     public int size() {
80         if (isReference()) {
81             return ((DirSet) getRef(getProject())).size();
82         }
83         return getDirectoryScanner(getProject()).getIncludedDirsCount();
84     }
85
86     /**
87      * Always returns true.
88      * @return true indicating that all elements will be FileResources.
89      * @since Ant 1.7
90      */

91     public boolean isFilesystemOnly() {
92         return true;
93     }
94
95     /**
96      * Returns included directories as a list of semicolon-separated paths.
97      *
98      * @return a <code>String</code> of included directories.
99      */

100     public String JavaDoc toString() {
101         DirectoryScanner ds = getDirectoryScanner(getProject());
102         String JavaDoc[] dirs = ds.getIncludedDirectories();
103         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
104
105         for (int i = 0; i < dirs.length; i++) {
106             if (i > 0) {
107                 sb.append(';');
108             }
109             sb.append(dirs[i]);
110         }
111         return sb.toString();
112     }
113
114 }
115
Popular Tags