001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.config.schema.test;
006:
007: import java.util.ArrayList;
008: import java.util.HashMap;
009: import java.util.Iterator;
010: import java.util.List;
011: import java.util.Map;
012:
013: /**
014: * Allows you to build valid config for the L1. This class <strong>MUST NOT</strong> invoke the actual XML beans to do
015: * its work; one of its purposes is, in fact, to test that those beans are set up correctly.
016: */
017: public class L1ConfigBuilder extends BaseConfigBuilder {
018:
019: private List modules = new ArrayList();
020: private List repos = new ArrayList();
021:
022: public L1ConfigBuilder() {
023: super (1, ALL_PROPERTIES);
024: }
025:
026: public void setILClass(boolean use) {
027: setProperty("class", use);
028: }
029:
030: public void setILClass(String use) {
031: setProperty("class", use);
032: }
033:
034: public void setILHierarchy(boolean use) {
035: setProperty("hierarchy", use);
036: }
037:
038: public void setILHierarchy(String use) {
039: setProperty("hierarchy", use);
040: }
041:
042: public void setILLocks(boolean use) {
043: setProperty("locks", use);
044: }
045:
046: public void setILLocks(String use) {
047: setProperty("locks", use);
048: }
049:
050: public void setILTransientRoot(boolean use) {
051: setProperty("transient-root", use);
052: }
053:
054: public void setILTransientRoot(String use) {
055: setProperty("transient-root", use);
056: }
057:
058: public void setILRoots(boolean use) {
059: setProperty("roots", use);
060: }
061:
062: public void setILRoots(String use) {
063: setProperty("roots", use);
064: }
065:
066: public void setILDistributedMethods(boolean use) {
067: setProperty("distributed-methods", use);
068: }
069:
070: public void setILDistributedMethods(String use) {
071: setProperty("distributed-methods", use);
072: }
073:
074: public void setRLLockDebug(boolean use) {
075: setProperty("lock-debug", use);
076: }
077:
078: public void setRLLockDebug(String use) {
079: setProperty("lock-debug", use);
080: }
081:
082: public void setRLPartialInstrumentation(boolean use) {
083: setProperty("partial-instrumentation", use);
084: }
085:
086: public void setRLPartialInstrumentation(String use) {
087: setProperty("partial-instrumentation", use);
088: }
089:
090: public void setRLNonPortableWarning(boolean use) {
091: setProperty("non-portable-warning", use);
092: }
093:
094: public void setRLNonPortableWarning(String use) {
095: setProperty("non-portable-warning", use);
096: }
097:
098: public void setRLWaitNotifyDebug(boolean use) {
099: setProperty("wait-notify-debug", use);
100: }
101:
102: public void setRLWaitNotifyDebug(String use) {
103: setProperty("wait-notify-debug", use);
104: }
105:
106: public void setRLDistributedMethodDebug(boolean use) {
107: setProperty("distributed-method-debug", use);
108: }
109:
110: public void setRLDistributedMethodDebug(String use) {
111: setProperty("distributed-method-debug", use);
112: }
113:
114: public void setRLNewObjectDebug(boolean use) {
115: setProperty("new-object-debug", use);
116: }
117:
118: public void setRLNewObjectDebug(String use) {
119: setProperty("new-object-debug", use);
120: }
121:
122: public void setROOAutoLockDetails(boolean use) {
123: setProperty("auto-lock-details", use);
124: }
125:
126: public void setROOAutoLockDetails(String use) {
127: setProperty("auto-lock-details", use);
128: }
129:
130: public void setROOCaller(boolean use) {
131: setProperty("caller", use);
132: }
133:
134: public void setROOCaller(String use) {
135: setProperty("caller", use);
136: }
137:
138: public void setROOFullStack(boolean use) {
139: setProperty("full-stack", use);
140: }
141:
142: public void setROOFullStack(String use) {
143: setProperty("full-stack", use);
144: }
145:
146: public void setMaxInMemoryObjectCount(int value) {
147: setProperty("max-in-memory-object-count", value);
148: }
149:
150: public void setMaxInMemoryObjectCount(String value) {
151: setProperty("max-in-memory-object-count", value);
152: }
153:
154: public void setLogs(String value) {
155: setProperty("logs", value);
156: }
157:
158: public void addRepository(String location) {
159: repos.add(location);
160: }
161:
162: public void addModule(String name, String version) {
163: addModule(name, "org.terracotta.modules", version);
164: }
165:
166: public void addModule(String name, String groupId, String version) {
167: modules.add(new Module(name, groupId, version));
168: }
169:
170: private String addModuleElement() {
171: StringBuffer moduleElement = new StringBuffer();
172:
173: if (modules.size() > 0 || repos.size() > 0) {
174: moduleElement.append(openElement("modules"));
175:
176: for (Iterator it = repos.iterator(); it.hasNext();) {
177: String loc = (String) it.next();
178: moduleElement.append(openElement("repository"));
179: moduleElement.append(loc);
180: moduleElement.append(closeElement("repository"));
181: }
182:
183: for (Iterator it = modules.iterator(); it.hasNext();) {
184: Module m = (Module) it.next();
185: moduleElement.append(selfCloseElement("module", m
186: .asAttribute()));
187: }
188:
189: moduleElement.append(closeElement("modules"));
190: }
191:
192: return moduleElement.toString();
193: }
194:
195: private static final String[] DSO_INSTRUMENTATION_LOGGING = new String[] {
196: "class", "hierarchy", "locks", "transient-root", "roots",
197: "distributed-methods" };
198: private static final String[] DSO_RUNTIME_LOGGING = new String[] {
199: "lock-debug", "partial-instrumentation",
200: "non-portable-warning", "wait-notify-debug",
201: "distributed-method-debug", "new-object-debug" };
202: private static final String[] DSO_RUNTIME_OUTPUT_OPTIONS = new String[] {
203: "auto-lock-details", "caller", "full-stack" };
204:
205: private static final String[] DSO_DEBUGGING = concat(new Object[] {
206: DSO_INSTRUMENTATION_LOGGING, DSO_RUNTIME_LOGGING,
207: DSO_RUNTIME_OUTPUT_OPTIONS });
208: private static final String[] DSO = concat(new Object[] {
209: "max-in-memory-object-count", DSO_DEBUGGING });
210: private static final String[] MODULE_ATTRIBUTES = new String[] {
211: "name", "group-id", "version" };
212: private static final String[] ALL_PROPERTIES = concat(new Object[] {
213: "modules", "logs", DSO });
214:
215: public String toString() {
216: return addModuleElement()
217: + element("logs")
218: + openElement("dso", DSO)
219: + element("max-in-memory-object-count")
220: + openElement("debugging", DSO_DEBUGGING)
221: + elementGroup("instrumentation-logging",
222: DSO_INSTRUMENTATION_LOGGING)
223: + elementGroup("runtime-logging", DSO_RUNTIME_LOGGING)
224: + elementGroup("runtime-output-options",
225: DSO_RUNTIME_OUTPUT_OPTIONS)
226: + closeElement("debugging", DSO_DEBUGGING)
227: + closeElement("dso", DSO);
228: }
229:
230: public static L1ConfigBuilder newMinimalInstance() {
231: return new L1ConfigBuilder();
232: }
233:
234: private static class Module {
235: private String name;
236: private String groupId;
237: private String version;
238:
239: public Module(String name, String groupId, String version) {
240: this .name = name;
241: this .groupId = groupId;
242: this .version = version;
243: }
244:
245: public Map asAttribute() {
246: Map attr = new HashMap();
247: attr.put(MODULE_ATTRIBUTES[0], name);
248: attr.put(MODULE_ATTRIBUTES[1], groupId);
249: attr.put(MODULE_ATTRIBUTES[2], version);
250: return attr;
251: }
252: }
253:
254: public static void main(String[] args) {
255: L1ConfigBuilder builder = new L1ConfigBuilder();
256: System.err.println(builder);
257:
258: builder.setROOCaller(true);
259: builder.setROOFullStack(false);
260: builder.setLogs("funk");
261: builder.addModule("testmo", "org.mycompany.modules", "1.2");
262: System.err.println(builder);
263: }
264:
265: }
|