001 /**
002 *
003 * Copyright 2003-2004 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * 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 */
017
018 package org.apache.geronimo.deployment.plugin.local;
019
020 import org.apache.geronimo.deployment.util.DeploymentUtil;
021 import org.apache.geronimo.kernel.Kernel;
022
023 import javax.enterprise.deploy.shared.CommandType;
024 import javax.enterprise.deploy.spi.Target;
025 import java.io.File;
026 import java.io.InputStream;
027
028 /**
029 * @version $Rev: 399026 $ $Date: 2006-05-02 13:03:28 -0700 (Tue, 02 May 2006) $
030 */
031 public class DistributeCommand extends AbstractDeployCommand {
032 protected final Target[] targetList;
033
034 public DistributeCommand(Kernel kernel, Target[] targetList, File moduleArchive, File deploymentPlan) {
035 super(CommandType.DISTRIBUTE, kernel, moduleArchive, deploymentPlan, null, null, false);
036 this.targetList = targetList;
037 }
038
039 public DistributeCommand(Kernel kernel, Target[] targetList, InputStream moduleStream, InputStream deploymentStream) {
040 super(CommandType.DISTRIBUTE, kernel, null, null, moduleStream, deploymentStream, true);
041 this.targetList = targetList;
042 }
043
044 public void run() {
045 try {
046 if (spool) {
047 if (moduleStream != null) {
048 moduleArchive = DeploymentUtil.createTempFile();
049 copyTo(moduleArchive, moduleStream);
050 }
051 if (deploymentStream != null) {
052 deploymentPlan = DeploymentUtil.createTempFile();
053 copyTo(deploymentPlan, deploymentStream);
054 }
055 }
056 if (deployer == null) {
057 return;
058 }
059 for(int i = 0; i < targetList.length; i++) {
060 doDeploy(targetList[i], true);
061 }
062 } catch (Exception e) {
063 doFail(e);
064 } finally {
065 if (spool) {
066 if (moduleArchive != null) {
067 moduleArchive.delete();
068 }
069 if (deploymentPlan != null) {
070 deploymentPlan.delete();
071 }
072 }
073 }
074 }
075
076 }