KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > management > ServiceAdmin


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis.management;
17
18 import org.apache.axis.AxisFault;
19 import org.apache.axis.ConfigurationException;
20 import org.apache.axis.EngineConfiguration;
21 import org.apache.axis.WSDDEngineConfiguration;
22 import org.apache.axis.deployment.wsdd.WSDDGlobalConfiguration;
23 import org.apache.axis.deployment.wsdd.WSDDHandler;
24 import org.apache.axis.deployment.wsdd.WSDDService;
25 import org.apache.axis.deployment.wsdd.WSDDTransport;
26 import org.apache.axis.description.ServiceDesc;
27 import org.apache.axis.handlers.soap.SOAPService;
28 import org.apache.axis.management.jmx.DeploymentAdministrator;
29 import org.apache.axis.management.jmx.DeploymentQuery;
30 import org.apache.axis.management.jmx.ServiceAdministrator;
31 import org.apache.axis.server.AxisServer;
32
33 import javax.xml.namespace.QName JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Iterator JavaDoc;
36
37 /**
38  * The ServiceControl Object is responsible for starting and
39  * stopping specific services
40  *
41  * @author bdillon
42  * @version 1.0
43  */

44 public class ServiceAdmin {
45     //Singleton AxisServer for Management
46
static private AxisServer axisServer = null;
47
48     /**
49      * Start the Service
50      *
51      * @param serviceName
52      * @throws AxisFault ConfigurationException
53      */

54     static public void startService(String JavaDoc serviceName)
55             throws AxisFault, ConfigurationException {
56         AxisServer server = getEngine();
57         try {
58             SOAPService service = server.getConfig().getService(
59                     new QName JavaDoc("", serviceName));
60             service.start();
61         } catch (ConfigurationException configException) {
62             if (configException.getContainedException() instanceof AxisFault) {
63                 throw (AxisFault) configException.getContainedException();
64             } else {
65                 throw configException;
66             }
67         }
68     }
69
70     /**
71      * Stop the Service
72      *
73      * @param serviceName
74      * @throws AxisFault ConfigurationException
75      */

76     static public void stopService(String JavaDoc serviceName)
77             throws AxisFault, ConfigurationException {
78         AxisServer server = getEngine();
79         try {
80             SOAPService service = server.getConfig().getService(
81                     new QName JavaDoc("", serviceName));
82             service.stop();
83         } catch (ConfigurationException configException) {
84             if (configException.getContainedException() instanceof AxisFault) {
85                 throw (AxisFault) configException.getContainedException();//Throw Axis fault if ist. of
86
} else {
87                 throw configException;
88             }
89         }
90     }
91
92     /**
93      * List all registered services
94      *
95      * @return Map of Services (SOAPService objects, Key is the ServiceName)
96      * @throws AxisFault ConfigurationException
97      */

98     static public String JavaDoc[] listServices()
99             throws AxisFault, ConfigurationException {
100         ArrayList JavaDoc list = new ArrayList JavaDoc();
101         AxisServer server = getEngine();
102         Iterator JavaDoc iter; // get list of ServiceDesc objects
103
try {
104             iter = server.getConfig().getDeployedServices();
105         } catch (ConfigurationException configException) {
106             if (configException.getContainedException() instanceof AxisFault) {
107                 throw (AxisFault) configException.getContainedException();//Throw Axis fault if inst. of
108
} else {
109                 throw configException;
110             }
111         }
112         while (iter.hasNext()) {
113             ServiceDesc sd = (ServiceDesc) iter.next();
114             String JavaDoc name = sd.getName();
115             list.add(name);
116         }
117         return (String JavaDoc[]) list.toArray(new String JavaDoc[list.size()]);
118     }
119
120     /**
121      * Get the singleton engine for this management object
122      *
123      * @return
124      * @throws AxisFault
125      */

126     static public AxisServer getEngine() throws AxisFault {
127         if (axisServer == null) {
128             //Throw a could not get AxisEngine Exception
129
throw new AxisFault(
130                     "Unable to locate AxisEngine for ServiceAdmin Object");
131         }
132         return axisServer;
133     }
134
135     /**
136      * Set the singleton engine
137      *
138      * @param axisSrv
139      */

140     static public void setEngine(AxisServer axisSrv, String JavaDoc name) {
141         ServiceAdmin.axisServer = axisSrv;
142         Registrar.register(new ServiceAdministrator(), "axis:type=server", "ServiceAdministrator");
143         Registrar.register(new DeploymentAdministrator(), "axis:type=deploy", "DeploymentAdministrator");
144         Registrar.register(new DeploymentQuery(), "axis:type=query", "DeploymentQuery");
145     }
146
147     static public void start() {
148         if (axisServer != null) {
149             axisServer.start();
150         }
151     }
152
153     static public void stop() {
154         if (axisServer != null) {
155             axisServer.stop();
156         }
157     }
158
159     static public void restart() {
160         if (axisServer != null) {
161             axisServer.stop();
162             axisServer.start();
163         }
164     }
165
166     static public void saveConfiguration() {
167         if (axisServer != null) {
168             axisServer.saveConfiguration();
169         }
170     }
171
172     static private WSDDEngineConfiguration getWSDDEngineConfiguration() {
173         if (axisServer != null) {
174             EngineConfiguration config = axisServer.getConfig();
175             if (config instanceof WSDDEngineConfiguration) {
176                 return (WSDDEngineConfiguration) config;
177             } else {
178                 throw new RuntimeException JavaDoc("WSDDDeploymentHelper.getWSDDEngineConfiguration(): EngineConguration not of type WSDDEngineConfiguration");
179             }
180         }
181         return null;
182     }
183
184     static public void setGlobalConfig(WSDDGlobalConfiguration globalConfig) {
185         getWSDDEngineConfiguration().getDeployment().setGlobalConfiguration(globalConfig);
186     }
187
188     static public WSDDGlobalConfiguration getGlobalConfig() {
189         return getWSDDEngineConfiguration().getDeployment().getGlobalConfiguration();
190     }
191
192     static public WSDDHandler getHandler(QName JavaDoc qname) {
193         return getWSDDEngineConfiguration().getDeployment().getWSDDHandler(qname);
194     }
195
196     static public WSDDHandler[] getHandlers() {
197         return getWSDDEngineConfiguration().getDeployment().getHandlers();
198     }
199
200     static public WSDDService getService(QName JavaDoc qname) {
201         return getWSDDEngineConfiguration().getDeployment().getWSDDService(qname);
202     }
203
204     static public WSDDService[] getServices() {
205         return getWSDDEngineConfiguration().getDeployment().getServices();
206     }
207
208     static public WSDDTransport getTransport(QName JavaDoc qname) {
209         return getWSDDEngineConfiguration().getDeployment().getWSDDTransport(qname);
210     }
211
212     static public WSDDTransport[] getTransports() {
213         return getWSDDEngineConfiguration().getDeployment().getTransports();
214     }
215
216     static public void deployHandler(WSDDHandler handler) {
217         getWSDDEngineConfiguration().getDeployment().deployHandler(handler);
218     }
219
220     static public void deployService(WSDDService service) {
221         getWSDDEngineConfiguration().getDeployment().deployService(service);
222     }
223
224     static public void deployTransport(WSDDTransport transport) {
225         getWSDDEngineConfiguration().getDeployment().deployTransport(transport);
226     }
227
228     static public void undeployHandler(QName JavaDoc qname) {
229         getWSDDEngineConfiguration().getDeployment().undeployHandler(qname);
230     }
231
232     static public void undeployService(QName JavaDoc qname) {
233         getWSDDEngineConfiguration().getDeployment().undeployService(qname);
234     }
235
236     static public void undeployTransport(QName JavaDoc qname) {
237         getWSDDEngineConfiguration().getDeployment().undeployTransport(qname);
238     }
239 }
Popular Tags