KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > framework > HelpException


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.framework;
25
26 /**
27  * Whenever the HelpException is thrown, it will use the helpclass defined
28  * in the xml to display the usage text or manpage.
29  * @author <a HREF="mailto:jane.young@sun.com">Jane Young</a>
30  * @version $Revision: 1.3 $
31  */

32 public class HelpException extends java.lang.Exception JavaDoc
33 {
34     private String JavaDoc command = null;
35     private boolean isShell = false;
36
37     /**
38      * Creates new <code>HelpException</code> without detail message.
39      */

40     public HelpException()
41     {
42     }
43
44     /**
45      * Creates new <code>HelpException</code> with the command name to display the help
46      */

47     public HelpException(String JavaDoc commandName)
48     {
49         command = commandName;
50     }
51
52     public HelpException(String JavaDoc[] args)
53     {
54         if (args.length<2) {
55             command = null;
56         }
57         else {
58                 //help, help --shell, help command --shell
59
int next = 1;
60             if(!args[next].startsWith("--"))
61                 command = args[next++];
62             if(args.length>next && args[next].equals("--shell"))
63                 isShell = true;
64         }
65     }
66
67     /**
68      * Returns the help class to invoke.
69      */

70     public String JavaDoc getHelpClassName()
71     {
72         //read CLI descriptor
73
final CLIDescriptorsReader cliDescriptorsReader = CLIDescriptorsReader.getInstance();
74     return cliDescriptorsReader.getHelpClass();
75     }
76     
77     /**
78      * Returns the command to display the help.
79      */

80     public String JavaDoc getCommandName()
81     {
82         return command;
83     }
84
85     /**
86      * Returns the usage text of the command.
87      */

88     public String JavaDoc getUsageText()
89     {
90         try
91         {
92                 //read CLI descriptor
93
final CLIDescriptorsReader cliDescriptorsReader = CLIDescriptorsReader.getInstance();
94                 //get the validCommand object from CLI descriptor
95
final ValidCommand validCommand = cliDescriptorsReader.getCommand(command);
96             return validCommand.getUsageText();
97         }
98         catch (Exception JavaDoc e)
99         {
100             return null;
101         }
102     }
103     
104     public boolean isShell(){
105         return isShell;
106     }
107 }
108
109
110
Popular Tags