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 org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
019: import org.apache.geronimo.kernel.Kernel;
020: import org.apache.geronimo.kernel.config.ConfigurationManager;
021: import org.apache.geronimo.kernel.config.ConfigurationUtil;
022: import org.apache.geronimo.kernel.repository.Artifact;
023:
024: import java.util.List;
025: import javax.enterprise.deploy.shared.CommandType;
026: import javax.enterprise.deploy.shared.ModuleType;
027: import javax.enterprise.deploy.spi.TargetModuleID;
028:
029: /**
030: * @version $Rev: 537224 $ $Date: 2007-05-11 09:25:51 -0700 (Fri, 11 May 2007) $
031: */
032: public class StopCommand extends CommandSupport {
033: private final Kernel kernel;
034: private final TargetModuleID[] modules;
035:
036: public StopCommand(Kernel kernel, TargetModuleID modules[]) {
037: super (CommandType.STOP);
038: this .kernel = kernel;
039: this .modules = modules;
040: }
041:
042: public void run() {
043: try {
044: ConfigurationManager configurationManager = ConfigurationUtil
045: .getConfigurationManager(kernel);
046: int alreadyStopped = 0;
047:
048: try {
049: for (int i = 0; i < modules.length; i++) {
050: TargetModuleID module = modules[i];
051: Artifact moduleID = Artifact.create(module
052: .getModuleID());
053: org.apache.geronimo.kernel.config.LifecycleResults lcresult = null;
054:
055: if (configurationManager.isRunning(moduleID)) {
056: lcresult = configurationManager
057: .stopConfiguration(moduleID);
058: addModule(module);
059: } else {
060: updateStatus("Module " + moduleID
061: + " is already stopped");
062: alreadyStopped++;
063: }
064:
065: if (configurationManager.isLoaded(moduleID)) {
066: configurationManager
067: .unloadConfiguration(moduleID);
068: }
069:
070: if (lcresult != null) {
071: java.util.Iterator iterator = lcresult
072: .getStopped().iterator();
073: while (iterator.hasNext()) {
074: Artifact config = (Artifact) iterator
075: .next();
076: if (!config.toString().equals(
077: module.getModuleID())) {
078: //TODO might be a hack
079: List kidsChild = loadChildren(kernel,
080: config.toString());
081: //this.updateStatus("printing kidsChild="+kidsChild);
082: //this.updateStatus("printing config="+config.toString());
083: // Build a response obect containg the started configuration and a list of it's contained modules
084: TargetModuleIDImpl idChild = new TargetModuleIDImpl(
085: null,
086: config.toString(),
087: (String[]) kidsChild
088: .toArray(new String[kidsChild
089: .size()]));
090: if (isWebApp(kernel, config.toString())) {
091: idChild.setType(ModuleType.WAR);
092: }
093: if (idChild.getChildTargetModuleID() != null) {
094: for (int k = 0; k < idChild
095: .getChildTargetModuleID().length; k++) {
096: TargetModuleIDImpl child = (TargetModuleIDImpl) idChild
097: .getChildTargetModuleID()[k];
098: if (isWebApp(kernel, child
099: .getModuleID())) {
100: child
101: .setType(ModuleType.WAR);
102: }
103: }
104: }
105: addModule(idChild);
106: }
107: }
108: }
109: }
110: } finally {
111: ConfigurationUtil.releaseConfigurationManager(kernel,
112: configurationManager);
113: }
114: if ((getModuleCount() + alreadyStopped) < modules.length) {
115: fail("Some modules could not be stopped");
116: } else {
117: complete("Completed");
118: }
119: } catch (Exception e) {
120: doFail(e);
121: }
122: }
123: }
|