001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.deployment.plugin.local;
017:
018: import java.net.URI;
019: import javax.enterprise.deploy.shared.CommandType;
020: import javax.enterprise.deploy.spi.TargetModuleID;
021:
022: import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
023: import org.apache.geronimo.kernel.InternalKernelException;
024: import org.apache.geronimo.kernel.Kernel;
025: import org.apache.geronimo.kernel.config.ConfigurationManager;
026: import org.apache.geronimo.kernel.config.ConfigurationUtil;
027: import org.apache.geronimo.kernel.config.NoSuchConfigException;
028: import org.apache.geronimo.kernel.repository.Artifact;
029:
030: /**
031: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
032: */
033: public class UndeployCommand extends CommandSupport {
034: private static final String[] UNINSTALL_SIG = { URI.class.getName() };
035: private final Kernel kernel;
036: private final TargetModuleID[] modules;
037:
038: public UndeployCommand(Kernel kernel, TargetModuleID modules[]) {
039: super (CommandType.UNDEPLOY);
040: this .kernel = kernel;
041: this .modules = modules;
042: }
043:
044: public void run() {
045: try {
046: ConfigurationManager configurationManager = ConfigurationUtil
047: .getConfigurationManager(kernel);
048: try {
049: for (int i = 0; i < modules.length; i++) {
050: TargetModuleIDImpl module = (TargetModuleIDImpl) modules[i];
051:
052: Artifact moduleID = Artifact.create(module
053: .getModuleID());
054: try {
055: if (!configurationManager.isOnline()) {
056: //If an offline undeploy, need to load the configuration first, so that stopConfiguration()
057: //can resolve the configuration and successfully set load=false in attribute manager, otherwise
058: //starting the server will fail attempting to start an config that does not exist.
059: configurationManager
060: .loadConfiguration(moduleID);
061: }
062:
063: configurationManager
064: .stopConfiguration(moduleID);
065:
066: configurationManager
067: .unloadConfiguration(moduleID);
068: updateStatus("Module " + moduleID
069: + " unloaded.");
070: } catch (InternalKernelException e) {
071: // this is cause by the kernel being already shutdown
072: } catch (NoSuchConfigException e) {
073: // module was already unloaded - just continue
074: }
075:
076: try {
077: configurationManager
078: .uninstallConfiguration(moduleID);
079: updateStatus("Module " + moduleID
080: + " uninstalled.");
081: addModule(module);
082: } catch (NoSuchConfigException e) {
083: // module was already undeployed - just continue
084: }
085: }
086: } finally {
087: ConfigurationUtil.releaseConfigurationManager(kernel,
088: configurationManager);
089: }
090:
091: //todo: this will probably never happen because the command line args are compared to actual modules
092: if (getModuleCount() < modules.length) {
093: updateStatus("Some of the modules to undeploy were not previously deployed. This is not treated as an error.");
094: }
095: complete("Completed");
096: } catch (Exception e) {
097: doFail(e);
098: }
099: }
100: }
|