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: JOnASTask.java 4695 2004-05-05 14:19:30Z benoitf $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.ant;
026:
027: import org.apache.tools.ant.BuildException;
028: import org.apache.tools.ant.taskdefs.Java;
029:
030: /**
031: * Uses to start/stop/... JOnAS
032: * @author Florent Benoit
033: */
034: public class JOnASTask extends BootstrapTask {
035:
036: /**
037: * Start class (Server class)
038: */
039: private static final String START_CLASS = "org.objectweb.jonas.server.Server";
040:
041: /**
042: * Stop class (Admin class)
043: */
044: private static final String ADMIN_CLASS = "org.objectweb.jonas.adm.JonasAdmin";
045:
046: /**
047: * Check Environment class
048: */
049: private static final String CHECKENV_CLASS = "org.objectweb.jonas.tools.CheckEnv";
050:
051: /**
052: * Version class
053: */
054: private static final String VERSION_CLASS = "org.objectweb.jonas_lib.version.Version";
055:
056: /**
057: * (START) mode
058: */
059: private static final int START_MODE = 0;
060:
061: /**
062: * (STOP) mode
063: */
064: private static final int STOP_MODE = 1;
065:
066: /**
067: * (JNDI) mode (print jndi names of the registry)
068: */
069: private static final int JNDI_MODE = 2;
070:
071: /**
072: * (CHECK) mode
073: */
074: private static final int CHECK_MODE = 3;
075:
076: /**
077: * (VERSION) mode
078: */
079: private static final int VERSION_MODE = 4;
080:
081: /**
082: * (PING) mode
083: */
084: private static final int PING_MODE = 5;
085:
086: /**
087: * Default mode (START)
088: */
089: private static final int DEFAULT_MODE = START_MODE;
090:
091: /**
092: * Mode (start or stop)
093: */
094: private String mode = null;
095:
096: /**
097: * Run the task
098: * @see org.apache.tools.ant.Task#execute()
099: */
100: public void execute() {
101: int userMode = DEFAULT_MODE;
102:
103: if (mode.equalsIgnoreCase("start")) {
104: userMode = START_MODE;
105: } else if (mode.equalsIgnoreCase("stop")) {
106: userMode = STOP_MODE;
107: } else if (mode.equalsIgnoreCase("jndi")) {
108: userMode = JNDI_MODE;
109: } else if (mode.equalsIgnoreCase("check")) {
110: userMode = CHECK_MODE;
111: } else if (mode.equalsIgnoreCase("version")) {
112: userMode = VERSION_MODE;
113: } else if (mode.equalsIgnoreCase("ping")) {
114: userMode = PING_MODE;
115: } else {
116: throw new BuildException("The mode '" + mode
117: + "' is invalid.");
118: }
119:
120: // Start the task
121: Java bootstrapTask = null;
122: switch (userMode) {
123: default:
124: case START_MODE:
125: bootstrapTask = getBootstraptask(START_CLASS);
126: break;
127: case STOP_MODE:
128: bootstrapTask = getBootstraptask(ADMIN_CLASS);
129: bootstrapTask.createArg().setValue("-s");
130: break;
131: case JNDI_MODE:
132: bootstrapTask = getBootstraptask(ADMIN_CLASS);
133: bootstrapTask.createArg().setValue("-j");
134: break;
135: case CHECK_MODE:
136: bootstrapTask = getBootstraptask(CHECKENV_CLASS);
137: break;
138: case VERSION_MODE:
139: bootstrapTask = getBootstraptask(VERSION_CLASS);
140: break;
141: case PING_MODE:
142: bootstrapTask = getBootstraptask(ADMIN_CLASS);
143: bootstrapTask.createArg().setValue("-ping");
144: break;
145: }
146:
147: bootstrapTask.executeJava();
148:
149: }
150:
151: /**
152: * @return the mode.
153: */
154: public String getMode() {
155: return mode;
156: }
157:
158: /**
159: * Sets the mode for the server (start or stop)
160: * @param mode The mode to set.
161: */
162: public void setMode(String mode) {
163: this.mode = mode;
164: }
165: }
|