KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Stops all the domains in the specified/default domaindir
35  * @version $Revision: 1.3 $
36  */

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

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

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