KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > ant > JOnASTask


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: JOnASTask.java,v 1.1 2004/05/05 14:19:30 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.ant;
28
29 import org.apache.tools.ant.BuildException;
30 import org.apache.tools.ant.taskdefs.Java;
31
32 /**
33  * Uses to start/stop/... JOnAS
34  * @author Florent Benoit
35  */

36 public class JOnASTask extends BootstrapTask {
37
38     /**
39      * Start class (Server class)
40      */

41     private static final String JavaDoc START_CLASS = "org.objectweb.jonas.server.Server";
42
43     /**
44      * Stop class (Admin class)
45      */

46     private static final String JavaDoc ADMIN_CLASS = "org.objectweb.jonas.adm.JonasAdmin";
47
48     /**
49      * Check Environment class
50      */

51     private static final String JavaDoc CHECKENV_CLASS = "org.objectweb.jonas.tools.CheckEnv";
52
53     /**
54      * Version class
55      */

56     private static final String JavaDoc VERSION_CLASS = "org.objectweb.jonas_lib.version.Version";
57
58     /**
59      * (START) mode
60      */

61     private static final int START_MODE = 0;
62
63     /**
64      * (STOP) mode
65      */

66     private static final int STOP_MODE = 1;
67
68     /**
69      * (JNDI) mode (print jndi names of the registry)
70      */

71     private static final int JNDI_MODE = 2;
72
73     /**
74      * (CHECK) mode
75      */

76     private static final int CHECK_MODE = 3;
77
78     /**
79      * (VERSION) mode
80      */

81     private static final int VERSION_MODE = 4;
82
83     /**
84      * (PING) mode
85      */

86     private static final int PING_MODE = 5;
87
88     /**
89      * Default mode (START)
90      */

91     private static final int DEFAULT_MODE = START_MODE;
92
93     /**
94      * Mode (start or stop)
95      */

96     private String JavaDoc mode = null;
97
98     /**
99      * Run the task
100      * @see org.apache.tools.ant.Task#execute()
101      */

102     public void execute() {
103         int userMode = DEFAULT_MODE;
104
105         if (mode.equalsIgnoreCase("start")) {
106             userMode = START_MODE;
107         } else if (mode.equalsIgnoreCase("stop")) {
108             userMode = STOP_MODE;
109         } else if (mode.equalsIgnoreCase("jndi")) {
110             userMode = JNDI_MODE;
111         } else if (mode.equalsIgnoreCase("check")) {
112             userMode = CHECK_MODE;
113         } else if (mode.equalsIgnoreCase("version")) {
114             userMode = VERSION_MODE;
115         } else if (mode.equalsIgnoreCase("ping")) {
116             userMode = PING_MODE;
117         } else {
118             throw new BuildException("The mode '" + mode + "' is invalid.");
119         }
120
121         // Start the task
122
Java bootstrapTask = null;
123         switch (userMode) {
124             default:
125             case START_MODE:
126                 bootstrapTask = getBootstraptask(START_CLASS);
127                 break;
128             case STOP_MODE:
129                 bootstrapTask = getBootstraptask(ADMIN_CLASS);
130                 bootstrapTask.createArg().setValue("-s");
131                 break;
132             case JNDI_MODE:
133                 bootstrapTask = getBootstraptask(ADMIN_CLASS);
134                 bootstrapTask.createArg().setValue("-j");
135                 break;
136             case CHECK_MODE:
137                 bootstrapTask = getBootstraptask(CHECKENV_CLASS);
138                 break;
139             case VERSION_MODE:
140                 bootstrapTask = getBootstraptask(VERSION_CLASS);
141                 break;
142             case PING_MODE:
143                 bootstrapTask = getBootstraptask(ADMIN_CLASS);
144                 bootstrapTask.createArg().setValue("-ping");
145                 break;
146         }
147
148         bootstrapTask.executeJava();
149
150     }
151
152     /**
153      * @return the mode.
154      */

155     public String JavaDoc getMode() {
156         return mode;
157     }
158
159     /**
160      * Sets the mode for the server (start or stop)
161      * @param mode The mode to set.
162      */

163     public void setMode(String JavaDoc mode) {
164         this.mode = mode;
165     }
166 }
Popular Tags