KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tcsimulator > Sandbox


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.tcsimulator;
5
6 import java.io.File JavaDoc;
7
8 public final class Sandbox {
9   public static final int TEST_SERVER = 0;
10   public static final int CONTROL_SERVER = 1;
11   private static final String JavaDoc TEST_SERVER_SANDBOX_NAME = "server";
12   private static final String JavaDoc CONTROL_SERVER_SANDBOX_NAME = "control";
13   private static final String JavaDoc TEST_CONFIG_FILENAME = "tc-config.xml";
14   private static final String JavaDoc CONTROL_CONFIG_FILENAME = "control-config.xml";
15   private static final String JavaDoc TC_DISTRIBUTION = "terracotta";
16
17   final File JavaDoc testHome;
18   final File JavaDoc installationRoot;
19   final File JavaDoc serverHome;
20   final File JavaDoc configFile;
21   final int serverType;
22
23   public Sandbox(File JavaDoc testHome, int serverType) {
24     this.testHome = testHome;
25     this.testHome.mkdir();
26     this.installationRoot = new File JavaDoc(testHome, "terracotta");
27     this.serverType = serverType;
28     if (this.serverType == TEST_SERVER) {
29       this.serverHome = new File JavaDoc(this.testHome, TEST_SERVER_SANDBOX_NAME);
30       this.configFile = new File JavaDoc(this.testHome, TEST_CONFIG_FILENAME);
31     } else if (serverType == CONTROL_SERVER) {
32       this.serverHome = new File JavaDoc(this.testHome, CONTROL_SERVER_SANDBOX_NAME);
33       this.configFile = new File JavaDoc(this.testHome, CONTROL_CONFIG_FILENAME);
34     } else {
35       throw new AssertionError JavaDoc("Can't resolve server type. Must be either test- or control-server.");
36     }
37     this.serverHome.mkdir();
38   }
39
40   public File JavaDoc getConfigFile() {
41     return this.configFile;
42   }
43
44   public File JavaDoc getServerHome() {
45     return this.serverHome;
46   }
47
48   public File JavaDoc getInstallationRoot() {
49     return this.installationRoot;
50   }
51
52   public File JavaDoc getTestHome() {
53     return this.testHome;
54   }
55
56   public String JavaDoc getDistributionName() {
57     return TC_DISTRIBUTION;
58   }
59 }
Popular Tags