KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > transport > util > JoramConfigurationBuilder


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: JoramConfigurationBuilder.java 2:04:08 PM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.transport.util;
23
24
25 /**
26  * This class is used to build the Joram configuration file a3servers.xml
27  *
28  * @author ddesjardins - eBMWebsourcing
29  */

30 public class JoramConfigurationBuilder {
31
32     private JoramConfigurationBuilder() {
33         // do nothing
34
}
35
36     /**
37      * Build a joram configuration file (a3servers.xml) for a single Joram
38      * server
39      *
40      * @param domain
41      * domain of the server
42      * @param id
43      * id of the server
44      * @param name
45      * name of the server
46      * @param host
47      * host of the server
48      * @param username
49      * username to access to the admin module
50      * @param password
51      * password to access to the admin module
52      * @param domainPort
53      * port of the domain
54      * @param tcpPort
55      * port for the tcp connector
56      * @param uid
57      * uid of the server
58      * @return xml String containing the configuration
59      */

60     public static String JavaDoc buildFullMasterConf(String JavaDoc domain, String JavaDoc id,
61         String JavaDoc name, String JavaDoc host, String JavaDoc username, String JavaDoc password,
62         String JavaDoc domainPort, String JavaDoc tcpPort, String JavaDoc uid) {
63         StringBuffer JavaDoc xml = new StringBuffer JavaDoc();
64         xml.append("<?xml version=\"1.0\"?>\n");
65         xml.append("<!-- <!DOCTYPE config SYSTEM \"a3config.dtd\">-->\n");
66         xml.append("<config>\n");
67         xml.append("\t<domain name=\"" + domain + "\"/>\n");
68         // xml
69
// .append("\t<property name=\"Transaction\"
70
// value=\"fr.dyade.aaa.util.NullTransaction\"/>\n");
71
xml.append(buildMasterServerConf(domain, id, name, host, username,
72             password, domainPort, tcpPort, uid));
73         xml.append("</config>\n");
74
75         return xml.toString();
76     }
77
78     /**
79      * Build the Joram server element of the configuration file (a3servers.xml)
80      *
81      * @param domain
82      * domain of the server
83      * @param id
84      * id of the server
85      * @param name
86      * name of the server
87      * @param host
88      * host of the server
89      * @param username
90      * username to access to the admin module
91      * @param password
92      * password to access to the admin module
93      * @param domainPort
94      * port of the domain
95      * @param tcpPort
96      * port for the tcp connector
97      * @param uid
98      * uid of the server
99      * @return xml String representing the element server
100      */

101     protected static String JavaDoc buildMasterServerConf(String JavaDoc domain, String JavaDoc id,
102         String JavaDoc name, String JavaDoc host, String JavaDoc username, String JavaDoc password,
103         String JavaDoc domainPort, String JavaDoc tcpPort, String JavaDoc uid) {
104         StringBuffer JavaDoc xml = new StringBuffer JavaDoc();
105         xml.append("\t<server id=\"" + id + "\" name=\"" + name
106             + "\" hostname=\"" + host + "\">\n");
107         xml.append("\t\t<property name=\"uid\" value=\"" + uid + "\"/>\n");
108         xml.append("\t\t<network domain=\"" + domain + "\" port=\""
109             + domainPort + "\"/>\n");
110         xml
111             .append("\t\t<service class=\"org.objectweb.joram.mom.proxies.ConnectionManager\" args=\""
112                 + username + " " + password + "\"/>\n");
113         xml
114             .append("\t\t<service class=\"org.objectweb.joram.mom.proxies.tcp.TcpProxyService\" args=\""
115                 + tcpPort + "\"/>\n");
116         // xml
117
// .append("\t\t<service
118
// class=\"fr.dyade.aaa.jndi2.distributed.DistributedJndiServer\"
119
// args=\""
120
// + jndiPort + "\"/>\n");
121
xml.append("\t</server>\n");
122         return xml.toString();
123     }
124
125     /**
126      * Build the Joram server element of the configuration file (a3servers.xml)
127      *
128      * @param domain
129      * domain of the server
130      * @param id
131      * id of the server
132      * @param name
133      * name of the server
134      * @param host
135      * host of the server
136      * @param username
137      * username to access to the admin module
138      * @param password
139      * password to access to the admin module
140      * @param domainPort
141      * port of the domain
142      * @param tcpPort
143      * port for the tcp connector
144      * @param uid
145      * uid of the server
146      * @return xml String representing the element server
147      */

148     protected static String JavaDoc buildSlaveServerConf(String JavaDoc domain, String JavaDoc id,
149         String JavaDoc name, String JavaDoc host, String JavaDoc username, String JavaDoc password,
150         String JavaDoc domainPort, String JavaDoc tcpPort, String JavaDoc uid) {
151         StringBuffer JavaDoc xml = new StringBuffer JavaDoc();
152         xml.append("\t<server id=\"" + id + "\" name=\"" + name
153             + "\" hostname=\"" + host + "\">\n");
154         xml.append("\t\t<property name=\"uid\" value=\"" + uid + "\"/>\n");
155         xml.append("\t\t<network domain=\"" + domain + "\" port=\""
156             + domainPort + "\"/>\n");
157         xml
158             .append("\t\t<service class=\"org.objectweb.joram.mom.proxies.ConnectionManager\" args=\""
159                 + username + " " + password + "\"/>\n");
160         xml
161             .append("\t\t<service class=\"org.objectweb.joram.mom.proxies.tcp.TcpProxyService\" args=\""
162                 + tcpPort + "\"/>\n");
163         // xml
164
// .append("\t\t<service
165
// class=\"fr.dyade.aaa.jndi2.distributed.DistributedJndiServer\"
166
// args=\""
167
// + jndiPort + " " + masterId + "\"/>\n");
168

169         xml.append("\t</server>\n");
170         return xml.toString();
171     }
172
173     /**
174      * Build a joram configuration file (a3servers.xml) for a distributed Joram
175      * server
176      *
177      * @param masterConf
178      * configuration of the others Joram servers
179      * @param domain
180      * domain of the server
181      * @param id
182      * id of the server
183      * @param name
184      * name of the server
185      * @param host
186      * host of the server
187      * @param username
188      * username to access to the admin module
189      * @param password
190      * password to access to the admin module
191      * @param domainPort
192      * port of the domain
193      * @param tcpPort
194      * port for the tcp connector
195      * @param uid
196      * uid of the server
197      * @return xml String containing the full configuration
198      */

199     public static String JavaDoc buildFullConfiguration(String JavaDoc masterConf,
200         String JavaDoc domain, String JavaDoc id, String JavaDoc name, String JavaDoc host, String JavaDoc username,
201         String JavaDoc password, String JavaDoc domainPort, String JavaDoc tcpPort, String JavaDoc uid) {
202         StringBuffer JavaDoc xml = new StringBuffer JavaDoc(masterConf);
203
204         // We add only this configuration if its necessary
205
if (xml.indexOf("id=\"" + id) == -1) {
206             xml.insert(xml.indexOf("</config>"), buildSlaveServerConf(domain,
207                 id, name, host, username, password, domainPort, tcpPort, uid));
208         }
209
210         return xml.toString();
211     }
212
213 }
214
Popular Tags