Source Code Cross Referenced for TcConfigBuilder.java in  » Net » Terracotta » com » tc » test » server » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Terracotta » com.tc.test.server.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.tc.test.server.util;
002:
003:        import org.apache.commons.io.IOUtils;
004:        import org.apache.xmlbeans.XmlOptions;
005:
006:        import com.tc.config.Loader;
007:        import com.terracottatech.config.Autolock;
008:        import com.terracottatech.config.Include;
009:        import com.terracottatech.config.LockLevel;
010:        import com.terracottatech.config.Module;
011:        import com.terracottatech.config.QualifiedClassName;
012:        import com.terracottatech.config.Root;
013:        import com.terracottatech.config.TcConfigDocument;
014:        import com.terracottatech.config.WebApplication;
015:        import com.terracottatech.config.TcConfigDocument.TcConfig;
016:
017:        import java.io.File;
018:        import java.io.FileOutputStream;
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:
022:        public class TcConfigBuilder {
023:            private TcConfigDocument tcConfigDocument;
024:            private TcConfig tcConfig;
025:            private XmlOptions xmlOptions;
026:
027:            public TcConfigBuilder() {
028:                this ("default-tc-config.xml");
029:            }
030:
031:            public TcConfigBuilder(String resourcePath) {
032:                try {
033:                    tcConfigDocument = new Loader().parse(getClass()
034:                            .getResourceAsStream(resourcePath));
035:                    tcConfig = tcConfigDocument.getTcConfig();
036:                } catch (Exception e) {
037:                    throw new RuntimeException(e);
038:                }
039:            }
040:
041:            public TcConfigBuilder(File file) {
042:                try {
043:                    tcConfigDocument = new Loader().parse(file);
044:                    tcConfig = tcConfigDocument.getTcConfig();
045:                } catch (Exception e) {
046:                    throw new RuntimeException(e);
047:                }
048:            }
049:
050:            private TcConfigBuilder(TcConfigDocument tcd) {
051:                tcConfigDocument = tcd;
052:                tcConfig = tcConfigDocument.getTcConfig();
053:            }
054:
055:            public void setDsoPort(int portNo) {
056:                ensureServers();
057:                tcConfig.getServers().getServerArray(0).setDsoPort(portNo);
058:            }
059:
060:            public int getDsoPort() {
061:                ensureServers();
062:                return tcConfig.getServers().getServerArray(0).getDsoPort();
063:            }
064:
065:            public void setJmxPort(int portNo) {
066:                ensureServers();
067:                tcConfig.getServers().getServerArray(0).setJmxPort(portNo);
068:            }
069:
070:            public int getJmxPort() {
071:                ensureServers();
072:                return tcConfig.getServers().getServerArray(0).getJmxPort();
073:            }
074:
075:            public void setServerLogs(String path) {
076:                ensureServers();
077:                tcConfig.getServers().getServerArray(0).setLogs(path);
078:            }
079:
080:            public void setServerData(String path) {
081:                ensureServers();
082:                tcConfig.getServers().getServerArray(0).setData(path);
083:            }
084:
085:            public void setClientLogs(String path) {
086:                ensureClients();
087:                tcConfig.getClients().setLogs(path);
088:            }
089:
090:            public void addAutoLock(String pattern, String lockLevel) {
091:                addAutoLock(pattern, lockLevel, false);
092:            }
093:
094:            public void addAutoLock(String pattern, String lockLevel,
095:                    boolean autoSynch) {
096:                ensureLocks();
097:                Autolock autoLock = tcConfig.getApplication().getDso()
098:                        .getLocks().insertNewAutolock(0);
099:                autoLock.setMethodExpression(pattern);
100:                autoLock.setLockLevel(LockLevel.Enum.forString(lockLevel));
101:                if (autoSynch) {
102:                    autoLock.setAutoSynchronized(autoSynch);
103:                }
104:            }
105:
106:            public void addRoot(String fieldName, String rootName) {
107:                ensureRoots();
108:                Root root = tcConfig.getApplication().getDso().getRoots()
109:                        .addNewRoot();
110:                root.setFieldName(fieldName);
111:                root.setRootName(rootName);
112:            }
113:
114:            public void addInstrumentedClass(String pattern) {
115:                addInstrumentedClass(pattern, false);
116:            }
117:
118:            public void addInstrumentedClass(String pattern,
119:                    boolean honorTransient) {
120:                ensureInstrumentedClasses();
121:                Include include = tcConfig.getApplication().getDso()
122:                        .getInstrumentedClasses().insertNewInclude(0);
123:                include.setClassExpression(pattern);
124:                if (honorTransient) {
125:                    include.setHonorTransient(honorTransient);
126:                }
127:            }
128:
129:            public void addBootJarClass(String classname) {
130:                ensureBootJarClasses();
131:                QualifiedClassName qcn = tcConfig.getApplication().getDso()
132:                        .getAdditionalBootJarClasses().insertNewInclude(0);
133:                qcn.setStringValue(classname);
134:            }
135:
136:            public void addExclude(String pattern) {
137:                ensureInstrumentedClasses();
138:                tcConfig.getApplication().getDso().getInstrumentedClasses()
139:                        .addExclude(pattern);
140:            }
141:
142:            public void addModule(String name, String version) {
143:                ensureModules();
144:                Module newModule = tcConfig.getClients().getModules()
145:                        .insertNewModule(0);
146:                newModule.setName(name);
147:                newModule.setVersion(version);
148:            }
149:
150:            public void addRepository(String location) {
151:                ensureModules();
152:                tcConfig.getClients().getModules().addRepository(location);
153:            }
154:
155:            public void addWebApplication(String appName) {
156:                addWebApplication(appName, false);
157:            }
158:
159:            public void addWebApplication(String appName, boolean synchWrite) {
160:                ensureWebApplications();
161:                WebApplication wa = tcConfig.getApplication().getDso()
162:                        .getWebApplications().insertNewWebApplication(0);
163:                wa.setStringValue(appName);
164:                if (synchWrite) {
165:                    wa.setSynchronousWrite(synchWrite);
166:                }
167:            }
168:
169:            public String toString() {
170:                return tcConfigDocument.toString();
171:            }
172:
173:            public void saveToFile(File filename) throws IOException {
174:                InputStream is = null;
175:                FileOutputStream fos = null;
176:                try {
177:                    is = tcConfigDocument.newInputStream(getXmlOptions());
178:                    fos = new FileOutputStream(filename);
179:                    IOUtils.copy(tcConfigDocument
180:                            .newInputStream(getXmlOptions()), fos);
181:                } finally {
182:                    IOUtils.closeQuietly(fos);
183:                    IOUtils.closeQuietly(is);
184:                }
185:            }
186:
187:            private XmlOptions getXmlOptions() {
188:                if (xmlOptions == null) {
189:                    xmlOptions = new XmlOptions();
190:                    xmlOptions.setLoadLineNumbers();
191:                    xmlOptions.setSavePrettyPrint();
192:                    xmlOptions.setSavePrettyPrintIndent(2);
193:                }
194:                return xmlOptions;
195:            }
196:
197:            private void ensureServers() {
198:                if (!tcConfig.isSetServers()) {
199:                    tcConfig.addNewServers();
200:                }
201:            }
202:
203:            private void ensureClients() {
204:                if (!tcConfig.isSetClients()) {
205:                    tcConfig.addNewClients();
206:                }
207:            }
208:
209:            private void ensureModules() {
210:                ensureClients();
211:                if (!tcConfig.getClients().isSetModules()) {
212:                    tcConfig.getClients().addNewModules();
213:                }
214:            }
215:
216:            private void ensureApplication() {
217:                if (!tcConfig.isSetApplication()) {
218:                    tcConfig.addNewApplication();
219:                }
220:            }
221:
222:            private void ensureDso() {
223:                ensureApplication();
224:                if (!tcConfig.getApplication().isSetDso()) {
225:                    tcConfig.getApplication().addNewDso();
226:                }
227:            }
228:
229:            private void ensureLocks() {
230:                ensureDso();
231:                if (!tcConfig.getApplication().getDso().isSetLocks()) {
232:                    tcConfig.getApplication().getDso().addNewLocks();
233:                }
234:            }
235:
236:            private void ensureRoots() {
237:                ensureDso();
238:                if (!tcConfig.getApplication().getDso().isSetRoots()) {
239:                    tcConfig.getApplication().getDso().addNewRoots();
240:                }
241:            }
242:
243:            private void ensureInstrumentedClasses() {
244:                ensureDso();
245:                if (!tcConfig.getApplication().getDso()
246:                        .isSetInstrumentedClasses()) {
247:                    tcConfig.getApplication().getDso()
248:                            .addNewInstrumentedClasses();
249:                }
250:            }
251:
252:            private void ensureBootJarClasses() {
253:                ensureDso();
254:                if (!tcConfig.getApplication().getDso()
255:                        .isSetAdditionalBootJarClasses()) {
256:                    tcConfig.getApplication().getDso()
257:                            .addNewAdditionalBootJarClasses();
258:                }
259:            }
260:
261:            private void ensureWebApplications() {
262:                ensureDso();
263:                if (!tcConfig.getApplication().getDso().isSetWebApplications()) {
264:                    tcConfig.getApplication().getDso().addNewWebApplications();
265:                }
266:            }
267:
268:            public TcConfigBuilder copy() {
269:                try {
270:                    TcConfigBuilder aCopy = new TcConfigBuilder(new Loader()
271:                            .parse(this .toString()));
272:                    return aCopy;
273:                } catch (Exception e) {
274:                    throw new RuntimeException(e);
275:                }
276:            }
277:
278:            public static void main(String[] args) {
279:                TcConfigBuilder tc = new TcConfigBuilder();
280:                tc.setDsoPort(3232);
281:                tc.addModule("tc", "1.2");
282:                tc.addModule("asdfa", "23432");
283:                tc.setServerData("c:/temp");
284:                tc.setClientLogs("c:/temp/logs");
285:                tc.addAutoLock("* com.tctest.*.*(..)", "write", true);
286:                tc.addAutoLock("* adfad..*()", "read");
287:                tc.addRoot("com.tc.Test.field", "myField");
288:                tc.addWebApplication("events", false);
289:                tc.addBootJarClass("java.lang.Local");
290:                TcConfigBuilder aCopy = tc.copy();
291:                aCopy.addModule("hung", "huynh");
292:                System.out.println(aCopy.toString());
293:            }
294:
295:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.