01: /**
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */package com.tc.test;
04:
05: import com.tc.util.Assert;
06:
07: import java.io.File;
08: import java.io.IOException;
09:
10: /**
11: * A helper that provides directories to tests. This is the base of {@link DataDirectoryHelper}and
12: * {@link TempDirectoryHelper}.
13: */
14: public abstract class BaseDirectoryHelper {
15:
16: private final Class theClass;
17: private File directoryPath;
18: private File theDirectory;
19:
20: protected BaseDirectoryHelper(Class theClass, String directoryPath) {
21: Assert.assertNotNull(theClass);
22: this .theClass = theClass;
23: this .directoryPath = new File(directoryPath).getAbsoluteFile();
24: }
25:
26: public synchronized File getDirectory() throws IOException {
27: if (this .theDirectory == null) {
28: this .theDirectory = fetchDirectory();
29: }
30:
31: return this .theDirectory;
32: }
33:
34: public File getFile(String path) throws IOException {
35: return new File(getDirectory(), path);
36: }
37:
38: protected abstract File fetchDirectory() throws IOException;
39:
40: protected final File getRoot() {
41: return this .directoryPath;
42: }
43:
44: protected final Class getTargetClass() {
45: return this.theClass;
46: }
47:
48: }
|