KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > test > server > appserver > StandardAppServerParameters


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.server.appserver;
5
6 import com.tc.test.server.tcconfig.TerracottaServerConfigGenerator;
7
8 import java.io.File JavaDoc;
9 import java.util.HashMap JavaDoc;
10 import java.util.Map JavaDoc;
11 import java.util.Properties JavaDoc;
12
13 /**
14  * This concrete implementation allows it's creator to set values while the appserver itself interacts with the
15  * immutable {@link AppServerParameters} interface.
16  */

17 public class StandardAppServerParameters implements AppServerParameters {
18
19   private final Map JavaDoc wars = new HashMap JavaDoc();
20   private final String JavaDoc instanceName;
21   private final Properties JavaDoc props;
22   private final String JavaDoc tcSessionClasspath;
23   private String JavaDoc jvmArgs = "";
24   private String JavaDoc classpath = "";
25
26   public StandardAppServerParameters(String JavaDoc instanceName, Properties JavaDoc props, String JavaDoc tcSessionClasspath) {
27     this.instanceName = instanceName;
28     this.props = props;
29     this.tcSessionClasspath = tcSessionClasspath;
30   }
31
32   public void addWar(String JavaDoc context, File JavaDoc file) {
33     wars.put(context, file);
34   }
35
36   public final void addWar(File JavaDoc war) {
37     String JavaDoc name = war.getName();
38     addWar(name.substring(0, name.length() - 4), war);
39   }
40
41   public final String JavaDoc jvmArgs() {
42     return jvmArgs;
43   }
44
45   public final void appendJvmArgs(String JavaDoc jvmArgsVar) {
46     this.jvmArgs += jvmArgsVar + " ";
47   }
48
49   public final String JavaDoc classpath() {
50     return classpath;
51   }
52
53   protected final void appendClasspath(String JavaDoc classpathVar) {
54     this.classpath += classpathVar + " ";
55   }
56
57   public final Map JavaDoc wars() {
58     return wars;
59   }
60
61   public final String JavaDoc instanceName() {
62     return instanceName;
63   }
64
65   public final Properties JavaDoc properties() {
66     return props;
67   }
68
69   public final void enableDSO(TerracottaServerConfigGenerator dsoConfig, File JavaDoc bootJar) {
70     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
71     sb.append("-Dtc.config='" + dsoConfig.configPath() + "'");
72     sb.append(' ');
73     sb.append("-Xbootclasspath/p:'" + bootJar + "'");
74     sb.append(' ');
75     sb.append("-Dtc.classpath='" + System.getProperty("java.class.path") + "'");
76     sb.append(' ');
77     sb.append("-Dtc.session.classpath='" + tcSessionClasspath + "'");
78     appendJvmArgs(sb.toString());
79   }
80
81   public void appendSysProp(String JavaDoc name, int value) {
82     appendSysProp(name, Integer.toString(value));
83   }
84
85   private void appendSysProp(String JavaDoc name, String JavaDoc value) {
86     if (value == null) appendJvmArgs("-D" + name);
87     else appendJvmArgs("-D" + name + "=" + value);
88   }
89
90   public void appendSysProp(String JavaDoc name) {
91     appendSysProp(name, null);
92   }
93
94   public void appendSysProp(String JavaDoc name, boolean b) {
95     appendSysProp(name, Boolean.toString(b));
96   }
97
98 }
Popular Tags