KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > plugin > local > StartCommand


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

17
18 package org.apache.geronimo.deployment.plugin.local;
19
20 import java.util.List JavaDoc;
21 import javax.enterprise.deploy.shared.CommandType JavaDoc;
22 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
23 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
24
25 import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
26 import org.apache.geronimo.kernel.Kernel;
27 import org.apache.geronimo.kernel.config.Configuration;
28 import org.apache.geronimo.kernel.config.ConfigurationManager;
29 import org.apache.geronimo.kernel.config.ConfigurationUtil;
30 import org.apache.geronimo.kernel.repository.Artifact;
31 import org.apache.geronimo.gbean.AbstractName;
32
33 /**
34  * @version $Rev:392614 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
35  */

36 public class StartCommand extends CommandSupport {
37     private final Kernel kernel;
38     private final TargetModuleID JavaDoc[] modules;
39
40     public StartCommand(Kernel kernel, TargetModuleID JavaDoc modules[]) {
41         super(CommandType.START);
42         this.kernel = kernel;
43         this.modules = modules;
44     }
45
46     public void run() {
47         try {
48             ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
49             try {
50                 for (int i = 0; i < modules.length; i++) {
51                     TargetModuleID JavaDoc module = modules[i];
52
53                     // Check to see whether the module is already started
54
Artifact moduleID = Artifact.create(module.getModuleID());
55                     if (configurationManager.isRunning(moduleID)) {
56                         updateStatus("Module " + moduleID + " is already running");
57                         Thread.sleep(100);
58                         continue;
59                     }
60
61                     // Load
62
if(!configurationManager.isLoaded(moduleID)) {
63                         configurationManager.loadConfiguration(moduleID);
64                     }
65
66                     // Start
67
configurationManager.startConfiguration(moduleID);
68
69                     // Determine the child modules of the configuration
70
//TODO might be a hack
71
List JavaDoc kids = loadChildren(kernel, moduleID.toString());
72
73                     // Build a response obect containg the started configuration and a list of it's contained modules
74
TargetModuleIDImpl id = new TargetModuleIDImpl(modules[i].getTarget(), module.getModuleID(),
75                             (String JavaDoc[]) kids.toArray(new String JavaDoc[kids.size()]));
76                     if (isWebApp(kernel, moduleID.toString())) {
77                         id.setType(ModuleType.WAR);
78                     }
79                     if (id.getChildTargetModuleID() != null) {
80                         for (int k = 0; k < id.getChildTargetModuleID().length; k++) {
81                             TargetModuleIDImpl child = (TargetModuleIDImpl) id.getChildTargetModuleID()[k];
82                             if (isWebApp(kernel, child.getModuleID())) {
83                                 child.setType(ModuleType.WAR);
84                             }
85                         }
86                     }
87                     addModule(id);
88                 }
89             } finally {
90                 ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
91             }
92             addWebURLs(kernel);
93             complete("Completed");
94         } catch (Exception JavaDoc e) {
95             e.printStackTrace();
96             doFail(e);
97         }
98     }
99 }
100
Popular Tags