KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > cli > CommandStart


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
18 package org.apache.geronimo.deployment.cli;
19
20 import org.apache.geronimo.common.DeploymentException;
21
22 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
23 import javax.enterprise.deploy.spi.Target JavaDoc;
24 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
25 import javax.enterprise.deploy.spi.exceptions.TargetException JavaDoc;
26 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
27 import java.io.PrintWriter JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30
31 /**
32  * The CLI deployer logic to start.
33  *
34  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
35  */

36 public class CommandStart extends AbstractCommand {
37     public CommandStart() {
38         super("start", "1. Common Commands", "[ModuleID|TargetModuleID]+",
39                 "Accepts the configId of a module, or the fully-qualified " +
40                 "TargetModuleID identifying both the module and the server or cluster it's " +
41                 "on, and starts that module. The module should be available to the server " +
42                 "but not currently running. If multiple modules are specified, they will " +
43                 "all be started.\n" +
44                 "If the server is not running, the module will be marked to start " +
45                 "next time the server is started.");
46     }
47
48     public CommandStart(String JavaDoc command, String JavaDoc group, String JavaDoc helpArgumentList, String JavaDoc helpText) {
49         super(command, group, helpArgumentList, helpText);
50     }
51
52     public void execute(PrintWriter JavaDoc out, ServerConnection connection, String JavaDoc[] args) throws DeploymentException {
53         if(args.length == 0) {
54             throw new DeploymentSyntaxException("Must specify at least one module name or TargetModuleID");
55         }
56         DeploymentManager JavaDoc mgr = connection.getDeploymentManager();
57         Target JavaDoc[] allTargets = mgr.getTargets();
58         TargetModuleID JavaDoc[] allModules;
59         try {
60             allModules = mgr.getAvailableModules(null, allTargets);
61         } catch(TargetException JavaDoc e) {
62             throw new DeploymentException("Unable to load module list from server", e);
63         }
64         List JavaDoc modules = new ArrayList JavaDoc();
65         for(int i=0; i<args.length; i++) {
66             modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, args[i], false));
67         }
68         TargetModuleID JavaDoc[] ids = (TargetModuleID JavaDoc[]) modules.toArray(new TargetModuleID JavaDoc[modules.size()]);
69         boolean multiple = isMultipleTargets(ids);
70         ProgressObject JavaDoc po = runCommand(out, mgr, ids);
71         TargetModuleID JavaDoc[] done = po.getResultTargetModuleIDs();
72         out.println();
73         for(int i = 0; i < done.length; i++) {
74             TargetModuleID JavaDoc id = done[i];
75             out.print(DeployUtils.reformat(getAction()+" "+id.getModuleID()+(multiple ? " on "+id.getTarget().getName() : "")+(id.getWebURL() == null || !getAction().equals("Started") ? "" : " @ "+id.getWebURL()),4, 72));
76             if(id.getChildTargetModuleID() != null) {
77                 for (int j = 0; j < id.getChildTargetModuleID().length; j++) {
78                     TargetModuleID JavaDoc child = id.getChildTargetModuleID()[j];
79                     out.print(DeployUtils.reformat(" `-> "+child.getModuleID()+(child.getWebURL() == null || !getAction().equals("Started") ? "" : " @ "+child.getWebURL()),4, 72));
80                 }
81             }
82             out.println();
83         }
84         if(po.getDeploymentStatus().isFailed()) {
85             throw new DeploymentException("Operation failed: "+po.getDeploymentStatus().getMessage());
86         }
87     }
88
89     protected ProgressObject JavaDoc runCommand(PrintWriter JavaDoc out, DeploymentManager JavaDoc mgr, TargetModuleID JavaDoc[] ids) {
90         ProgressObject JavaDoc po = mgr.start(ids);
91         waitForProgress(out, po);
92         return po;
93     }
94
95     protected String JavaDoc getAction() {
96         return "Started";
97     }
98
99 }
100
Popular Tags