File Source: QueryCommandParser.java

         /* 
    P/P   *  Method: com.dmdirc.commandparser.parsers.QueryCommandParser__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.Query;
    26  import com.dmdirc.Server;
    27  import com.dmdirc.commandparser.CommandArguments;
    28  import com.dmdirc.commandparser.CommandManager;
    29  import com.dmdirc.commandparser.CommandType;
    30  import com.dmdirc.commandparser.commands.ChatCommand;
    31  import com.dmdirc.commandparser.commands.Command;
    32  import com.dmdirc.commandparser.commands.GlobalCommand;
    33  import com.dmdirc.commandparser.commands.QueryCommand;
    34  import com.dmdirc.commandparser.commands.ServerCommand;
    35  import com.dmdirc.ui.interfaces.InputWindow;
    36  
    37  /**
    38   * A command parser that is tailored for use in a query environment. Handles
    39   * both query and server commands.
    40   * @author chris
    41   */
    42  public final class QueryCommandParser extends CommandParser {
    43      
    44      /**
    45       * A version number for this class. It should be changed whenever the class
    46       * structure is changed (or anything else that would prevent serialized
    47       * objects being unserialized with the new class).
    48       */
    49      private static final long serialVersionUID = 1;
    50      
    51      /**
    52       * The server instance that this parser is attached to.
    53       */
    54      private final Server server;
    55      /**
    56       * The query instance that this parser is attached to.
    57       */
    58      private final Query query;
    59      
    60      /**
    61       * Creates a new instance of QueryCommandParser.
    62       * @param newServer The server instance that this parser is attached to
    63       * @param newQuery The query instance that this parser is attached to
    64       */
    65      public QueryCommandParser(final Server newServer, final Query newQuery) {
                 /* 
    P/P           *  Method: void com.dmdirc.commandparser.parsers.QueryCommandParser(Server, Query)
                  * 
                  *  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.query == newQuery
                  *    init'ed(this.query)
                  *    this.server == newServer
                  *    init'ed(this.server)
                  *    new ArrayList(getSources#1) num objects <= 1
                  *    ...
                  */
    66          super();
    67          
    68          server = newServer;
    69          query = newQuery;
    70      }
    71      
    72      /** Loads the relevant commands into the parser. */
    73      @Override
    74      protected void loadCommands() {
                 /* 
    P/P           *  Method: void loadCommands()
                  * 
                  *  Preconditions:
                  *    (soft) this.commands != null
                  */
    75          CommandManager.loadCommands(this, CommandType.TYPE_GLOBAL,
    76                  CommandType.TYPE_SERVER, CommandType.TYPE_QUERY);
    77      }
    78      
    79      /** {@inheritDoc} */
    80      @Override
    81      protected void executeCommand(final InputWindow origin,
    82              final boolean isSilent, final Command command, final CommandArguments args) {
                 /* 
    P/P           *  Method: void executeCommand(InputWindow, bool, Command, CommandArguments)
                  * 
                  *  Preconditions:
                  *    command != null
                  *    (soft) args != null
                  *    (soft) args.line != null
                  *    (soft) init'ed(com/dmdirc/commandparser/CommandManager.commandChar)
                  *    (soft) init'ed(args.words)
                  *    (soft) this.query != null
                  * 
                  *  Postconditions:
                  *    init'ed(args.words)
                  *    init'ed(java.lang.String:split(...)._tainted)
                  *    java.lang.String:split(...)._tainted == 0
                  *    init'ed(java.lang.String:split(...).length)
                  */
    83          if (command instanceof QueryCommand) {
    84              ((QueryCommand) command).execute(origin, server, query, isSilent, args);
    85          } else if (command instanceof ChatCommand) {
    86              ((ChatCommand) command).execute(origin, server, query, isSilent, args);
    87          } else if (command instanceof ServerCommand) {
    88              ((ServerCommand) command).execute(origin, server, isSilent, args);
    89          } else {
    90              ((GlobalCommand) command).execute(origin, isSilent, args);
    91          }
    92      }
    93      
    94      /**
    95       * Called when the input was a line of text that was not a command. This normally
    96       * means it is sent to the server/channel/user as-is, with no further processing.
    97       * @param origin The window in which the command was typed
    98       * @param line The line input by the user
    99       */
   100      @Override
   101      protected void handleNonCommand(final InputWindow origin, final String line) {
                 /* 
    P/P           *  Method: void handleNonCommand(InputWindow, String)
                  * 
                  *  Preconditions:
                  *    this.query != null
                  */
   102          query.sendLine(line);
   103      }
   104      
   105  }








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