KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > util > DirectoryBuilder


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.util;
9
10 import java.io.File JavaDoc;
11
12 /**
13  * A simple utility to make it easier to build File objects for nested
14  * directories based on the command line 'cd' pattern.
15  *
16  * @author <a HREF="mailto:jason@planet57.com">Jason Dillon</a>
17  * @version $Revision: 1.1 $
18  */

19 public class DirectoryBuilder
20 {
21    protected File JavaDoc root;
22
23    public DirectoryBuilder() {
24       // empty
25
}
26
27    public DirectoryBuilder(final File JavaDoc root) {
28       this.root = root;
29    }
30
31    public DirectoryBuilder(final File JavaDoc root, final File JavaDoc child) {
32       this(root);
33       cd(child);
34    }
35
36    public DirectoryBuilder(final String JavaDoc rootname) {
37       this(new File JavaDoc(rootname));
38    }
39
40    public DirectoryBuilder(final String JavaDoc rootname, final String JavaDoc childname) {
41       this(new File JavaDoc(rootname), new File JavaDoc(childname));
42    }
43
44    public DirectoryBuilder cd(final File JavaDoc child) {
45       if (child.isAbsolute()) {
46      root = child;
47       }
48       else {
49      root = new File JavaDoc(root, child.getPath());
50       }
51       return this;
52    }
53
54    public DirectoryBuilder cd(final String JavaDoc childname) {
55       return cd(new File JavaDoc(childname));
56    }
57
58    public File JavaDoc get() {
59       return root;
60    }
61
62    public String JavaDoc toString() {
63       return root.toString();
64    }
65 }
66
Popular Tags