001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: Jms.java 7884 2006-01-11 08:30:02Z pelletib $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.ant.jonasbase;
026:
027: import java.util.StringTokenizer;
028:
029: import org.objectweb.jonas.ant.JOnASBaseTask;
030:
031: /**
032: * Allow to configure the JMS service
033: * @author Florent Benoit
034: */
035: public class Jms extends Tasks {
036:
037: /**
038: * Info for the logger
039: */
040: private static final String INFO = "[JMS] ";
041:
042: /**
043: * Default port number
044: */
045: private static final String DEFAULT_PORT = "16010";
046:
047: /**
048: * Token for the end of the joramAdmin configuration file
049: */
050: private static final String TOKEN_END_CONF_FILE = "</JoramAdmin>";
051:
052: /**
053: * Default constructor
054: */
055: public Jms() {
056: super ();
057: }
058:
059: /**
060: * Set the port number for Joram
061: * @param portNumber the port for Joram
062: */
063: public void setPort(String portNumber) {
064:
065: // For JMS
066: JReplace propertyReplace = new JReplace();
067: propertyReplace
068: .setConfigurationFile(JOnASBaseTask.JORAM_CONF_FILE);
069: propertyReplace.setToken(DEFAULT_PORT);
070: propertyReplace.setValue(portNumber);
071: propertyReplace.setLogInfo(INFO
072: + "Setting Joram port number to : " + portNumber
073: + " in " + JOnASBaseTask.JORAM_CONF_FILE + " file.");
074: addTask(propertyReplace);
075:
076: // for RAR file
077: propertyReplace = new JReplace();
078: propertyReplace
079: .setConfigurationFile(JOnASBaseTask.JORAM_ADMIN_CONF_FILE);
080: propertyReplace.setToken(DEFAULT_PORT);
081: propertyReplace.setValue(portNumber);
082: propertyReplace.setLogInfo(INFO
083: + "Setting Joram port number to : " + portNumber
084: + " in " + JOnASBaseTask.JORAM_ADMIN_CONF_FILE
085: + " file.");
086: addTask(propertyReplace);
087:
088: // Patch the RAR file
089: JmsRa jmsRa = new JmsRa();
090: jmsRa.setServerPort(portNumber);
091: addTask(jmsRa);
092:
093: }
094:
095: /**
096: * Set the initial topics when JOnAS start
097: * @param initialTopics comma separated list of topics
098: */
099: public void setInitialTopics(String initialTopics) {
100: JReplace propertyReplace = new JReplace();
101: propertyReplace
102: .setConfigurationFile(JOnASBaseTask.JORAM_ADMIN_CONF_FILE);
103: propertyReplace.setToken(TOKEN_END_CONF_FILE);
104: String tokenValue = "";
105: StringTokenizer st = new StringTokenizer(initialTopics, ",");
106:
107: while (st.hasMoreTokens()) {
108: String topic = st.nextToken();
109: tokenValue += " <Topic name=\"" + topic + "\">" + "\n"
110: + " <freeReader/>" + "\n" + " <freeWriter/>"
111: + "\n" + " <jndi name=\"" + topic + "\"/>" + "\n"
112: + " </Topic>" + "\n";
113: }
114:
115: tokenValue += TOKEN_END_CONF_FILE;
116:
117: propertyReplace.setValue(tokenValue);
118: propertyReplace.setLogInfo(INFO
119: + "Setting initial topics to : " + initialTopics);
120: addTask(propertyReplace);
121: }
122:
123: /**
124: * Set the initial queues when JOnAS start
125: * @param initialQueues comma separated list of topics
126: */
127: public void setInitialQueues(String initialQueues) {
128: JReplace propertyReplace = new JReplace();
129: propertyReplace
130: .setConfigurationFile(JOnASBaseTask.JORAM_ADMIN_CONF_FILE);
131: propertyReplace.setToken(TOKEN_END_CONF_FILE);
132:
133: String tokenValue = "";
134: StringTokenizer st = new StringTokenizer(initialQueues, ",");
135:
136: while (st.hasMoreTokens()) {
137: String queue = st.nextToken();
138: tokenValue += " <Queue name=\"" + queue + "\">" + "\n"
139: + " <freeReader/>" + "\n" + " <freeWriter/>"
140: + "\n" + " <jndi name=\"" + queue + "\"/>" + "\n"
141: + " </Queue>" + "\n";
142: }
143:
144: tokenValue += TOKEN_END_CONF_FILE;
145:
146: propertyReplace.setValue(tokenValue);
147: propertyReplace.setLogInfo(INFO
148: + "Setting initial queues to : " + initialQueues);
149: addTask(propertyReplace);
150: }
151: }
|