KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > integrationtests > framework > FileSystemPath


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tctest.spring.integrationtests.framework;
5
6 import java.io.File JavaDoc;
7 import java.io.IOException JavaDoc;
8
9 public class FileSystemPath {
10
11   private final File JavaDoc path;
12
13   public boolean equals(Object JavaDoc obj) {
14     if (!(obj instanceof FileSystemPath)) return false;
15     FileSystemPath other = (FileSystemPath) obj;
16     return path.equals(other.path);
17   }
18   
19   public int hashCode() {
20     return path.hashCode();
21   }
22   
23   private FileSystemPath(String JavaDoc path) {
24     this.path = new File JavaDoc(path);
25   }
26
27   public FileSystemPath(File JavaDoc dir) {
28     this.path = dir;
29   }
30
31   public static FileSystemPath existingDir(String JavaDoc path) {
32     FileSystemPath f = new FileSystemPath(path);
33     if (!f.isDirectory()) { throw new RuntimeException JavaDoc("Non-existent directory: " + path); }
34     return f;
35   }
36
37   boolean isDirectory() {
38     return path.isDirectory();
39   }
40
41   public static FileSystemPath makeExistingFile(String JavaDoc path) {
42     FileSystemPath f = new FileSystemPath(path);
43     if (!f.isFile()) {
44       throw new RuntimeException JavaDoc("Non-existent file: " + path);
45     }
46     return f;
47   }
48
49   private boolean isFile() {
50     return path.isFile();
51   }
52
53   public String JavaDoc toString() {
54     try {
55       return path.getCanonicalPath();
56     } catch (IOException JavaDoc e) {
57       return path.getAbsolutePath();
58     }
59   }
60
61   public FileSystemPath existingSubdir(String JavaDoc subdirectoryPath) {
62     return existingDir(path + "/" + subdirectoryPath);
63   }
64
65   public FileSystemPath existingFile(String JavaDoc fileName) {
66     return makeExistingFile(this.path + "/" + fileName);
67   }
68   
69   public Deployment warDeployment(String JavaDoc warName) {
70     return new WARDeployment(existingFile(warName));
71   }
72   
73
74   public File JavaDoc getFile() {
75     return path;
76   }
77
78   public FileSystemPath subdir(String JavaDoc subdirectoryPath) {
79     return new FileSystemPath(path + "/" + subdirectoryPath);
80   }
81
82   public void delete() {
83     path.delete();
84   }
85
86   public FileSystemPath file(String JavaDoc fileName) {
87     return new FileSystemPath((this.path + "/" + fileName));
88   }
89
90   public FileSystemPath mkdir(String JavaDoc subdir) {
91     return subdir(subdir).mkdir();
92   }
93
94   private FileSystemPath mkdir() {
95     path.mkdirs();
96     return this;
97   }
98
99   public static FileSystemPath makeNewFile(String JavaDoc fileName) {
100     return new FileSystemPath(fileName);
101   }
102
103 }
104
Popular Tags