Source Code Cross Referenced for HelpCommand.java in  » Database-Client » Henplus » henplus » commands » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » Henplus » henplus.commands 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This is free software, licensed under the Gnu Public License (GPL)
003:         * get a copy from <http://www.gnu.org/licenses/gpl.html>
004:         * 
005:         * author: Henner Zeller <H.Zeller@acm.org>
006:         */
007:        package henplus.commands;
008:
009:        import java.util.StringTokenizer;
010:        import java.util.Iterator;
011:
012:        import henplus.HenPlus;
013:        import henplus.SQLSession;
014:        import henplus.CommandDispatcher;
015:        import henplus.Command;
016:        import henplus.AbstractCommand;
017:        import henplus.view.util.SortedMatchIterator;
018:
019:        /**
020:         * document me.
021:         */
022:        public class HelpCommand extends AbstractCommand {
023:            final static int INDENT = 42;
024:
025:            /**
026:             * returns the command-string this command can handle.
027:             */
028:            public String[] getCommandList() {
029:                return new String[] { "help", "?" };
030:            }
031:
032:            public boolean requiresValidSession(String cmd) {
033:                return false;
034:            }
035:
036:            /**
037:             * Returns a list of strings that are possible at this stage.
038:             */
039:            public Iterator complete(final CommandDispatcher disp,
040:                    String partialCommand, final String lastWord) {
041:                // if we already have one arguemnt and try to expand the next: no.
042:                int argc = argumentCount(partialCommand);
043:                if (argc > 2 || (argc == 2 && lastWord.length() == 0)) {
044:                    return null;
045:                }
046:
047:                final Iterator it = disp.getRegisteredCommandNames(lastWord);
048:                return new SortedMatchIterator(lastWord, it) {
049:                    protected boolean exclude(String cmdName) {
050:                        Command cmd = disp.getCommandFrom(cmdName);
051:                        return (cmd.getLongDescription(cmdName) == null);
052:                    }
053:                };
054:            }
055:
056:            /**
057:             * execute the command given.
058:             */
059:            public int execute(SQLSession session, String cmdstr, String param) {
060:                StringTokenizer st = new StringTokenizer(param);
061:                if (st.countTokens() > 1)
062:                    return SYNTAX_ERROR;
063:                param = (st.hasMoreElements()) ? (String) st.nextElement()
064:                        : null;
065:                /*
066:                 * nothing given: provide generic help.
067:                 */
068:                if (param == null) {
069:                    Iterator it = HenPlus.getInstance().getDispatcher()
070:                            .getRegisteredCommands();
071:                    while (it.hasNext()) {
072:                        Command cmd = (Command) it.next();
073:                        String description = cmd.getShortDescription();
074:                        if (description == null) // no description ..
075:                            continue;
076:
077:                        StringBuffer cmdPrint = new StringBuffer(" ");
078:                        String[] cmds = cmd.getCommandList();
079:                        String firstSynopsis = cmd.getSynopsis(cmds[0]);
080:                        /*
081:                         * either print a list of known commands or the complete
082:                         * synopsis, if there is only one command.
083:                         */
084:                        if (cmds.length > 1 || firstSynopsis == null) {
085:                            for (int i = 0; i < cmds.length; ++i) {
086:                                if (i != 0)
087:                                    cmdPrint.append(" | ");
088:                                cmdPrint.append(cmds[i]);
089:                            }
090:                        } else {
091:                            cmdPrint
092:                                    .append(firstSynopsis.length() < INDENT ? firstSynopsis
093:                                            : cmds[0]);
094:                        }
095:                        HenPlus.msg().print(cmdPrint.toString());
096:                        for (int i = cmdPrint.length(); i < INDENT; ++i) {
097:                            HenPlus.msg().print(" ");
098:                        }
099:                        HenPlus.msg().print(": ");
100:                        HenPlus.msg().println(description);
101:                    }
102:                    HenPlus.msg().println(
103:                            "config read from ["
104:                                    + HenPlus.getInstance()
105:                                            .getConfigurationDirectoryInfo()
106:                                    + "]");
107:                } else {
108:                    CommandDispatcher disp = HenPlus.getInstance()
109:                            .getDispatcher();
110:                    String cmdString = disp.getCommandNameFrom(param);
111:                    Command c = disp.getCommandFrom(param);
112:                    if (c == null) {
113:                        HenPlus.msg().println(
114:                                "Help: unknown command '" + param + "'");
115:                        return EXEC_FAILED;
116:                    }
117:                    printDescription(cmdString, c);
118:                }
119:                return SUCCESS;
120:            }
121:
122:            private void printDescription(String cmdStr, Command c) {
123:                String desc = c.getLongDescription(cmdStr);
124:                if (desc == null) {
125:                    if (c.getShortDescription() != null) {
126:                        desc = "\t[short description]: "
127:                                + c.getShortDescription();
128:                    }
129:                }
130:                String synopsis = c.getSynopsis(cmdStr);
131:
132:                if (synopsis != null) {
133:                    HenPlus.msg().attributeBold();
134:                    HenPlus.msg().println("SYNOPSIS");
135:                    HenPlus.msg().attributeReset();
136:                    HenPlus.msg().println("\t" + synopsis);
137:                    HenPlus.msg().println();
138:                }
139:                if (desc != null) {
140:                    HenPlus.msg().attributeBold();
141:                    HenPlus.msg().println("DESCRIPTION");
142:                    HenPlus.msg().attributeReset();
143:                    HenPlus.msg().println(desc);
144:                    if (c.requiresValidSession(cmdStr)) {
145:                        HenPlus.msg().println("\tRequires valid session.");
146:                    }
147:                }
148:                if (desc == null && synopsis == null) {
149:                    HenPlus.msg().println(
150:                            "no detailed help for '" + cmdStr + "'");
151:                }
152:            }
153:
154:            /**
155:             * return a descriptive string.
156:             */
157:            public String getShortDescription() {
158:                return "provides help for commands";
159:            }
160:
161:            public String getSynopsis(String cmd) {
162:                return cmd + " [command]";
163:            }
164:
165:            public String getLongDescription(String cmd) {
166:                String dsc;
167:                dsc = "\tProvides help for the given command.   If invoked without a\n"
168:                        + "\tcommand name as parameter, a list of all available commands\n"
169:                        + "\tis shown.";
170:                return dsc;
171:            }
172:        }
173:
174:        /*
175:         * Local variables:
176:         * c-basic-offset: 4
177:         * compile-command: "ant -emacs -find build.xml"
178:         * End:
179:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.