File Source: ServerCommandParser.java

         /* 
    P/P   *  Method: com.dmdirc.commandparser.parsers.ServerCommandParser__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.Server;
    26  import com.dmdirc.ServerState;
    27  import com.dmdirc.commandparser.CommandArguments;
    28  import com.dmdirc.commandparser.CommandManager;
    29  import com.dmdirc.commandparser.CommandType;
    30  import com.dmdirc.commandparser.commands.Command;
    31  import com.dmdirc.commandparser.commands.GlobalCommand;
    32  import com.dmdirc.commandparser.commands.ServerCommand;
    33  import com.dmdirc.ui.interfaces.InputWindow;
    34  
    35  /**
    36   * A command parser used in the context of a server.
    37   * @author chris
    38   */
    39  public final class ServerCommandParser extends CommandParser {
    40      
    41      /**
    42       * A version number for this class. It should be changed whenever the class
    43       * structure is changed (or anything else that would prevent serialized
    44       * objects being unserialized with the new class).
    45       */
    46      private static final long serialVersionUID = 1;
    47      
    48      /**
    49       * The server instance that this parser is attached to.
    50       */
    51      private final Server server;
    52      
    53      /**
    54       * Creates a new instance of ServerCommandParser.
    55       * @param newServer The server instance that this parser is attached to
    56       */
    57      public ServerCommandParser(final Server newServer) {
                 /* 
    P/P           *  Method: void com.dmdirc.commandparser.parsers.ServerCommandParser(Server)
                  * 
                  *  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)
                  *    this.server == newServer
                  *    init'ed(this.server)
                  *    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
                  *    ...
                  */
    58          super();
    59          
    60          server = newServer;
    61      }
    62      
    63      /** Loads the relevant commands into the parser. */
    64      @Override
    65      protected void loadCommands() {
                 /* 
    P/P           *  Method: void loadCommands()
                  * 
                  *  Preconditions:
                  *    (soft) this.commands != null
                  */
    66          CommandManager.loadCommands(this, CommandType.TYPE_GLOBAL, CommandType.TYPE_SERVER);
    67      }
    68      
    69      /** {@inheritDoc} */
    70      @Override
    71      protected void executeCommand(final InputWindow origin,
    72              final boolean isSilent, final Command command, final CommandArguments args) {
                 /* 
    P/P           *  Method: void executeCommand(InputWindow, bool, Command, CommandArguments)
                  * 
                  *  Preconditions:
                  *    command != null
                  *    (soft) origin != null
                  *    (soft) this.server != null
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.ServerState.CONNECTED)
                  *    init'ed(com.dmdirc.ServerState.CONNECTING)
                  *    java.lang.Class:getAnnotation(...)@286 != null
                  * 
                  *  Test Vectors:
                  *    isSilent: {1}, {0}
                  *    allowOffline(...)@74: {1}, {0}
                  *    com.dmdirc.Server:getParser(...)@74: Inverse{null}, Addr_Set{null}
                  *    java.lang.Class:isAnnotationPresent(...)@275: {0}, {1}
                  */
    73          if (command instanceof ServerCommand) {
    74              if (hasCommandOptions(command) && !getCommandOptions(command).allowOffline()
    75                      && ((server.getState() != ServerState.CONNECTED
    76                      && server.getState() != ServerState.CONNECTING)
    77                      || server.getParser() == null)) {
    78                  if (!isSilent) {
    79                      origin.addLine("commandError", "You must be connected to use this command");
    80                  }
    81              } else {
    82                  ((ServerCommand) command).execute(origin, server, isSilent, args);
    83              }
    84          } else {
    85              ((GlobalCommand) command).execute(origin, isSilent, args);
    86          }
    87      }
    88      
    89      /**
    90       * Called when the input was a line of text that was not a command. This normally
    91       * means it is sent to the server/channel/user as-is, with no further processing.
    92       * @param origin The window in which the command was typed
    93       * @param line The line input by the user
    94       */
    95      @Override
    96      protected void handleNonCommand(final InputWindow origin, final String line) {
                 /* 
    P/P           *  Method: void handleNonCommand(InputWindow, String)
                  * 
                  *  Preconditions:
                  *    this.server != null
                  */
    97          server.sendLine(line);
    98      }
    99      
   100  }








SofCheck Inspector Build Version : 2.17854
ServerCommandParser.java 2009-Jun-25 01:54:24
ServerCommandParser.class 2009-Sep-02 17:04:15