KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
25  * $Id: ListDomainsCommand.java,v 1.3 2005/12/25 03:46:31 tcfujii Exp $
26  */

27
28 package com.sun.enterprise.cli.commands;
29
30 import com.sun.enterprise.cli.framework.*;
31
32 import com.sun.enterprise.admin.servermgmt.DomainConfig;
33 import com.sun.enterprise.admin.servermgmt.DomainsManager;
34
35 // jdk imports
36

37 /**
38  * This is a local command that creates a new domain
39  * @version $Revision: 1.3 $
40  */

41 public class ListDomainsCommand extends BaseLifeCycleCommand
42 {
43
44     /** Creates new CreateDomainCommand */
45     public ListDomainsCommand()
46     {
47     }
48
49
50     /**
51      * An abstract method that validates the options
52      * on the specification in the xml properties file
53      * @return true if successfull
54      */

55     public boolean validateOptions() throws CommandValidationException
56     {
57         return super.validateOptions();
58     }
59
60     
61     /**
62      * An abstract method that executes the command
63      * @throws CommandException
64      */

65     public void runCommand()
66             throws CommandException, CommandValidationException
67     {
68         if (!validateOptions())
69            throw new CommandValidationException("Validation failed");
70         try {
71             DomainConfig domainConfig = new DomainConfig(null,
72                 getDomainsRoot());
73             DomainsManager manager = getFeatureFactory().getDomainsManager();
74             String JavaDoc[] domainsList = manager.listDomainsAndStatus(domainConfig);
75             if (domainsList.length > 0) {
76                 //*bug fix for #6158809*
77
//CLILogger.getInstance().printDetailMessage(
78
// getLocalizedString("ListOfDomains"));
79
//*end of bug fix*
80
for (int i = 0; i < domainsList.length; i++) {
81                     CLILogger.getInstance().printMessage(domainsList[i]);
82                 }
83             } else {
84                 CLILogger.getInstance().printDetailMessage(
85                    getLocalizedString("NoDomainsToList"));
86             }
87             CLILogger.getInstance().printDetailMessage(getLocalizedString(
88                                                        "CommandSuccessful",
89                                                        new Object JavaDoc[] {name}));
90         } catch (Exception JavaDoc ex) {
91             CLILogger.getInstance().printDetailMessage(ex.getLocalizedMessage());
92             throw new CommandException(getLocalizedString("CommandUnSuccessful",
93                              new Object JavaDoc[] {name} ), ex);
94         }
95     }
96
97
98 }
99
Popular Tags