KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > StartAppservCommand


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.cli.commands;
25
26 import com.sun.enterprise.cli.framework.CommandValidationException;
27 import com.sun.enterprise.cli.framework.CommandException;
28 import com.sun.enterprise.cli.framework.CLILogger;
29
30 import com.sun.enterprise.admin.servermgmt.DomainsManager;
31 import com.sun.enterprise.admin.servermgmt.DomainConfig;
32
33 /**
34  * Starts all the domains in the specified/default domaindir
35  * @version $Revision: 1.3 $
36  */

37 public class StartAppservCommand extends StartDomainCommand
38 {
39   
40     /**
41      * An abstract method that validates the options
42      * on the specification in the xml properties file
43      * This method verifies for the correctness of number of
44      * operands and if all the required options are supplied by the client.
45      * @return boolean returns true if success else returns false
46      */

47     public boolean validateOptions() throws CommandValidationException
48     {
49         return super.validateOptions();
50     }
51    
52     /**
53      * An abstract method that Executes the command
54      * @throws CommandException
55      */

56     public void runCommand() throws CommandException, CommandValidationException
57     {
58         CLILogger.getInstance().printWarning(getLocalizedString("CommandDeprecated",
59                                                                 new Object JavaDoc[] {name}));
60                                                                
61         validateOptions();
62
63         String JavaDoc[] domainsList = null;
64         try
65         {
66             DomainConfig domainConfig = new DomainConfig(null, getDomainsRoot());
67             DomainsManager manager = getFeatureFactory().getDomainsManager();
68             domainsList = manager.listDomains(domainConfig);
69         }
70         catch(Exception JavaDoc e)
71         {
72             throw new CommandException(getLocalizedString("CommandUnSuccessful",
73                                                      new Object JavaDoc[] {name} ), e);
74         }
75         boolean allDomainsStarted = true;
76
77         if (domainsList.length == 0)
78             throw new CommandException(getLocalizedString("NoDomainsToStart"));
79         else
80             CLILogger.getInstance().printDetailMessage(getLocalizedString("StartingAppserv",
81                                                              new Object JavaDoc[] {getDomainsRoot()}));
82         
83         for (int i = 0; i < domainsList.length; i++)
84         {
85             try
86             {
87                 startDomain(domainsList[i]);
88             }
89             catch(Exception JavaDoc e)
90             {
91                 allDomainsStarted = false;
92                 CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage());
93                 CLILogger.getInstance().printExceptionStackTrace(e);
94                 CLILogger.getInstance().printError(getLocalizedString("CannotStartDomainMsg",
95                                                        new Object JavaDoc[] {domainsList[i]}));
96             }
97         }
98         if (!allDomainsStarted)
99         {
100             throw new CommandException(getLocalizedString("CannotStartOneOrMoreDomains"));
101
102         }
103     }
104
105 }
106
Popular Tags