KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ecm > taskdefs > IR3StopTask


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@objectweb.org
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Lesser General Public
9
// License as published by the Free Software Foundation; either
10
// version 2.1 of the License, or any later version.
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
// USA
21
//
22
// Initial developer(s): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ecm.taskdefs;
31
32 /**
33  ** <p>Stops the OpenCCM Interface Repository.</p>
34  **
35  ** <p><bold>Parameters</bold></p>
36  ** <tr>
37  ** <td><bold>Attributes</bold></td>
38  ** <td><bold>Description</bold></td>
39  ** <td><bold>Required</bold></td>
40  ** </tr>
41  ** <tr>
42  ** <td>cfgdir</td>
43  ** <td>The directory corresponding to the OpenCCM_CONFIG_DIR environment variable and where the
44  ** IR3-related executables of OpenCCM store and lookup IORs, PIDs, etc. Can be set to a
45  ** temporary directory.</td>
46  ** <td>Yes</td>
47  ** </tr>
48  **
49  ** <tr>
50  ** <td><bold>Properties</bold></td>
51  ** <td><bold>Description</bold></td>
52  ** <td><bold>Required</bold></td>
53  ** </tr>
54  ** <tr>
55  ** <td>OpenCCM.install.bin.dir</td>
56  ** <td>Location of the OpenCCM binaries installation directory.</td>
57  ** <td>Yes</td>
58  ** </tr>
59  **/

60 public class IR3StopTask
61 extends org.apache.tools.ant.Task
62 {
63     // params
64
private java.io.File JavaDoc _cfgdir;
65
66     // default constructor
67
public
68     IR3StopTask()
69     {
70         // params
71
_cfgdir = null;
72     }
73
74     //
75
// internal operations
76
//
77

78
79     // NOTE: check required attributes, properties, environment, ...
80
private void
81     validate()
82     throws org.apache.tools.ant.BuildException
83     {
84         String JavaDoc msg = "";
85
86         // check OS family
87
if (!OSHelper.isUnix() && !OSHelper.isWindows()) {
88             msg = "target os must be of unix or windows family";
89             throw new org.apache.tools.ant.BuildException(msg);
90         }
91
92         // check cfgdir
93
if (_cfgdir==null) {
94             msg = "cfgdir attribute is missing";
95             throw new org.apache.tools.ant.BuildException(msg);
96         }
97         if ((!_cfgdir.exists()) || (!_cfgdir.isDirectory())) {
98             msg = "Configuration directory does not exist or is not a directory";
99             throw new org.apache.tools.ant.BuildException(msg);
100         }
101
102         // check "OpenCCM.install.bin.dir" property
103
String JavaDoc bindir = getProject().getProperty("OpenCCM.install.bin.dir");
104         if (bindir==null) {
105             msg = "OpenCCM.install.bin.dir property must be set";
106             throw new org.apache.tools.ant.BuildException(msg);
107         }
108     }
109
110     private void
111     ir3stop(java.io.File JavaDoc cfgdir)
112     throws org.apache.tools.ant.BuildException
113     {
114         // uses exec ant task to execute the ir3_start command
115
org.apache.tools.ant.taskdefs.ExecTask cmd = null;
116         cmd = (org.apache.tools.ant.taskdefs.ExecTask)getProject().createTask("exec");
117
118         // build executable name
119
String JavaDoc cmdname = null;
120         // convert OpenCCM.install.bin.dir path
121
OSHelper.pathConvert(getProject(), "os.OpenCCM.install.bin.dir", "OpenCCM.install.bin.dir");
122         String JavaDoc bindir = getProject().getProperty("os.OpenCCM.install.bin.dir");
123         if (OSHelper.isUnix()) {
124             cmdname = bindir+"/ir3_stop";
125         }
126         else if (OSHelper.isWindows()) {
127             cmdname = bindir+"\\ir3_stop.bat";
128         }
129
130         cmd.setExecutable(cmdname);
131
132         // add environment variables
133
org.apache.tools.ant.types.Environment.Variable openccm_homedir = null;
134         org.apache.tools.ant.types.Environment.Variable openccm_cfgdir = null;
135
136         // convert OpenCCM.install.dir path
137
OSHelper.pathConvert(getProject(), "os.OpenCCM.install.dir", "OpenCCM.install.dir");
138         String JavaDoc homedir = getProject().getProperty("os.OpenCCM.install.dir");
139         openccm_homedir = new org.apache.tools.ant.types.Environment.Variable();
140         openccm_homedir.setKey("OpenCCM_HOMEDIR");
141         openccm_homedir.setValue(homedir);
142         cmd.addEnv(openccm_homedir);
143
144         openccm_cfgdir = new org.apache.tools.ant.types.Environment.Variable();
145         openccm_cfgdir.setKey("OpenCCM_CONFIG_DIR");
146         openccm_cfgdir.setValue(cfgdir.getPath());
147         cmd.addEnv(openccm_cfgdir);
148
149         // launch
150
cmd.execute();
151     }
152
153     //
154
// attribute setter
155
//
156

157     final public void
158     setCfgdir(java.io.File JavaDoc cfgdir)
159     {
160         _cfgdir = cfgdir;
161     }
162
163     //
164
// org.apache.tools.ant.Task
165
//
166

167     final public void
168     execute()
169     throws org.apache.tools.ant.BuildException
170     {
171         validate();
172
173         // launch IR3
174
ir3stop(_cfgdir);
175     }
176 }
177
Popular Tags