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     */
017    
018    package org.apache.geronimo.deployment.plugin.local;
019    
020    import java.io.File;
021    import java.io.InputStream;
022    
023    import javax.enterprise.deploy.shared.CommandType;
024    import javax.enterprise.deploy.shared.ModuleType;
025    import javax.enterprise.deploy.spi.Target;
026    
027    import org.apache.geronimo.kernel.Kernel;
028    
029    /**
030     * @version $Rev: 512979 $ $Date: 2007-02-28 16:28:28 -0500 (Wed, 28 Feb 2007) $
031     */
032    public class DistributeCommand extends AbstractDeployCommand {
033        protected final Target[] targetList;
034    
035        public DistributeCommand(Kernel kernel, Target[] targetList, File moduleArchive, File deploymentPlan) {
036            super(CommandType.DISTRIBUTE, kernel, moduleArchive, deploymentPlan, null, null, null, false);
037            this.targetList = targetList;
038        }
039    
040        public DistributeCommand(Kernel kernel, Target[] targetList, ModuleType moduleType, InputStream moduleStream, InputStream deploymentStream) {
041            super(CommandType.DISTRIBUTE, kernel, null, null, moduleType, moduleStream, deploymentStream, true);    
042            this.targetList = targetList;
043        }
044    
045        public void run() {
046            try {
047                if (spool) {
048                    if (moduleStream != null) {
049                        moduleArchive = createTempFile(moduleType == null? null: moduleType.getModuleExtension());
050                        copyTo(moduleArchive, moduleStream);
051                    }
052                    if (deploymentStream != null) {
053                        deploymentPlan = createTempFile(null);
054                        copyTo(deploymentPlan, deploymentStream);
055                    }
056                }
057                if (deployer == null) {
058                    return;
059                }
060                for(int i = 0; i < targetList.length; i++) {
061                    doDeploy(targetList[i], true);
062                }
063            } catch (Exception e) {
064                doFail(e);
065            } finally {
066                if (spool) {
067                    if (moduleArchive != null) {
068                        moduleArchive.delete();
069                    }
070                    if (deploymentPlan != null) {
071                        deploymentPlan.delete();
072                    }
073                }
074            }
075        }
076    
077    }