File Source: GlobalCommandParser.java
/*
P/P * Method: com.dmdirc.commandparser.parsers.GlobalCommandParser__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.commandparser.parsers;
24
25 import com.dmdirc.commandparser.CommandArguments;
26 import com.dmdirc.commandparser.CommandManager;
27 import com.dmdirc.commandparser.CommandType;
28 import com.dmdirc.commandparser.commands.Command;
29 import com.dmdirc.commandparser.commands.GlobalCommand;
30 import com.dmdirc.logger.ErrorLevel;
31 import com.dmdirc.logger.Logger;
32 import com.dmdirc.ui.interfaces.InputWindow;
33
34 /**
35 * The command parser used for global commands.
36 * @author chris
37 */
38 public final class GlobalCommandParser extends CommandParser {
39
40 /**
41 * A version number for this class. It should be changed whenever the class
42 * structure is changed (or anything else that would prevent serialized
43 * objects being unserialized with the new class).
44 */
45 private static final long serialVersionUID = 1;
46
47 /**
48 * The singleton instance of this command parser.
49 */
50 private static GlobalCommandParser me;
51
52 /**
53 * Creates a new instance of the GlobalCommandParser.
54 */
55 private GlobalCommandParser() {
/*
P/P * Method: void com.dmdirc.commandparser.parsers.GlobalCommandParser()
*
* Preconditions:
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
*
* Postconditions:
* com/dmdirc/config/IdentityManager.globalconfig == One-of{old com/dmdirc/config/IdentityManager.globalconfig, &new ConfigManager(getGlobalConfig#1)}
* com/dmdirc/config/IdentityManager.globalconfig != null
* java.lang.StringBuilder:toString(...)._tainted == 0
* this.commands == &new Hashtable(CommandParser#1)
* this.history == &new RollingList(CommandParser#2)
* new ArrayList(getSources#1) num objects <= 1
* new ConfigManager(getGlobalConfig#1) num objects == new ArrayList(getSources#1) num objects
* new MapList(ConfigManager#1) num objects == new ArrayList(getSources#1) num objects
* new ConfigManager(getGlobalConfig#1).channel == &java.lang.StringBuilder:toString(...)
* init'ed(new ConfigManager(getGlobalConfig#1).file)
* ...
*/
56 super();
57 }
58
59 /**
60 * Retrieves a singleton instance of the global command parser.
61 * @return A GlobalCommandParser
62 */
63 public static synchronized GlobalCommandParser getGlobalCommandParser() {
/*
P/P * Method: GlobalCommandParser getGlobalCommandParser()
*
* Preconditions:
* init'ed(me)
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
* (soft) init'ed(com/dmdirc/config/IdentityManager.globalconfig)
*
* Postconditions:
* com/dmdirc/config/IdentityManager.globalconfig == One-of{old com/dmdirc/config/IdentityManager.globalconfig, &new ConfigManager(getGlobalConfig#1)}
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* java.lang.StringBuilder:toString(...)._tainted == 0
* me == One-of{old me, &new GlobalCommandParser(getGlobalCommandParser#1)}
* me != null
* return_value == me
* new ArrayList(getSources#1) num objects <= 1
* new ConfigManager(getGlobalConfig#1) num objects <= 1
* new ConfigManager(getGlobalConfig#1).channel == &java.lang.StringBuilder:toString(...)
* init'ed(new ConfigManager(getGlobalConfig#1).file)
* ...
*
* Test Vectors:
* me: Inverse{null}, Addr_Set{null}
*/
64 if (me == null) {
65 me = new GlobalCommandParser();
66 }
67
68 return me;
69 }
70
71 /** Loads the relevant commands into the parser. */
72 @Override
73 protected void loadCommands() {
/*
P/P * Method: void loadCommands()
*
* Preconditions:
* (soft) this.commands != null
*/
74 CommandManager.loadCommands(this, CommandType.TYPE_GLOBAL);
75 }
76
77 /** {@inheritDoc} */
78 @Override
79 protected void executeCommand(final InputWindow origin,
80 final boolean isSilent, final Command command, final CommandArguments args) {
/*
P/P * Method: void executeCommand(InputWindow, bool, Command, CommandArguments)
*
* Preconditions:
* command != null
*/
81 ((GlobalCommand) command).execute(origin, isSilent, args);
82 }
83
84 /**
85 * Called when the input was a line of text that was not a command. This normally
86 * means it is sent to the server/channel/user as-is, with no further processing.
87 * @param origin The window in which the command was typed
88 * @param line The line input by the user
89 */
90 @Override
91 protected void handleNonCommand(final InputWindow origin, final String line) {
/*
P/P * Method: void handleNonCommand(InputWindow, String)
*
* Presumptions:
* init'ed(com.dmdirc.logger.ErrorLevel.MEDIUM)
*
* Test Vectors:
* origin: Inverse{null}, Addr_Set{null}
*/
92 if (origin == null) {
93 Logger.userError(ErrorLevel.MEDIUM, "Invalid global command: " + line);
94 } else {
95 origin.addLine("commandError", "Invalid global command: " + line);
96 }
97 }
98
99 }
SofCheck Inspector Build Version : 2.17854
| GlobalCommandParser.java |
2009-Jun-25 01:54:24 |
| GlobalCommandParser.class |
2009-Sep-02 17:04:16 |