KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.geronimo.deployment.plugin.local;
18
19 import java.net.URI JavaDoc;
20 import javax.enterprise.deploy.shared.CommandType JavaDoc;
21 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
22
23 import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
24 import org.apache.geronimo.kernel.InternalKernelException;
25 import org.apache.geronimo.kernel.Kernel;
26 import org.apache.geronimo.kernel.config.ConfigurationManager;
27 import org.apache.geronimo.kernel.config.ConfigurationUtil;
28 import org.apache.geronimo.kernel.config.NoSuchConfigException;
29 import org.apache.geronimo.kernel.repository.Artifact;
30
31 /**
32  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
33  */

34 public class UndeployCommand extends CommandSupport {
35     private static final String JavaDoc[] UNINSTALL_SIG = {URI JavaDoc.class.getName()};
36     private final Kernel kernel;
37     private final TargetModuleID JavaDoc[] modules;
38
39     public UndeployCommand(Kernel kernel, TargetModuleID JavaDoc modules[]) {
40         super(CommandType.UNDEPLOY);
41         this.kernel = kernel;
42         this.modules = modules;
43     }
44
45     public void run() {
46         try {
47             ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
48             try {
49                 for (int i = 0; i < modules.length; i++) {
50                     TargetModuleIDImpl module = (TargetModuleIDImpl) modules[i];
51
52                     Artifact moduleID = Artifact.create(module.getModuleID());
53                     try {
54                         if(!configurationManager.isOnline()) {
55                             //If an offline undeploy, need to load the configuration first, so that stopConfiguration()
56
//can resolve the configuration and successfully set load=false in attribute manager, otherwise
57
//starting the server will fail attempting to start an config that does not exist.
58
configurationManager.loadConfiguration(moduleID);
59                         }
60                         
61                         configurationManager.stopConfiguration(moduleID);
62
63
64                         configurationManager.unloadConfiguration(moduleID);
65                         updateStatus("Module " + moduleID + " unloaded.");
66                     } catch (InternalKernelException e) {
67                         // this is cause by the kernel being already shutdown
68
} catch (NoSuchConfigException e) {
69                         // module was already unloaded - just continue
70
}
71
72                     try {
73                         configurationManager.uninstallConfiguration(moduleID);
74                         updateStatus("Module " + moduleID + " uninstalled.");
75                         addModule(module);
76                     } catch (NoSuchConfigException e) {
77                         // module was already undeployed - just continue
78
}
79                 }
80             } finally {
81                 ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
82             }
83
84             //todo: this will probably never happen because the command line args are compared to actual modules
85
if (getModuleCount() < modules.length) {
86                 updateStatus("Some of the modules to undeploy were not previously deployed. This is not treated as an error.");
87             }
88             complete("Completed");
89         } catch (Exception JavaDoc e) {
90             doFail(e);
91         }
92     }
93 }
94
Popular Tags