KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > test > BaseDirectoryHelper


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.tc.test;
5
6 import com.tc.util.Assert;
7
8 import java.io.File JavaDoc;
9 import java.io.IOException JavaDoc;
10
11 /**
12  * A helper that provides directories to tests. This is the base of {@link DataDirectoryHelper}and
13  * {@link TempDirectoryHelper}.
14  */

15 public abstract class BaseDirectoryHelper {
16
17   private final Class JavaDoc theClass;
18   private File JavaDoc directoryPath;
19   private File JavaDoc theDirectory;
20
21   protected BaseDirectoryHelper(Class JavaDoc theClass, String JavaDoc directoryPath) {
22     Assert.assertNotNull(theClass);
23     this.theClass = theClass;
24     this.directoryPath = new File JavaDoc(directoryPath).getAbsoluteFile();
25   }
26
27   public synchronized File JavaDoc getDirectory() throws IOException JavaDoc {
28     if (this.theDirectory == null) {
29       this.theDirectory = fetchDirectory();
30     }
31
32     return this.theDirectory;
33   }
34
35   public File JavaDoc getFile(String JavaDoc path) throws IOException JavaDoc {
36     return new File JavaDoc(getDirectory(), path);
37   }
38
39   protected abstract File JavaDoc fetchDirectory() throws IOException JavaDoc;
40
41   protected final File JavaDoc getRoot() {
42     return this.directoryPath;
43   }
44
45   protected final Class JavaDoc getTargetClass() {
46     return this.theClass;
47   }
48
49 }
Popular Tags