File Source: ChannelCommandParser.java

         /* 
    P/P   *  Method: com.dmdirc.commandparser.parsers.ChannelCommandParser__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.Channel;
    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.ChannelCommand;
    31  import com.dmdirc.commandparser.commands.ChatCommand;
    32  import com.dmdirc.commandparser.commands.Command;
    33  import com.dmdirc.commandparser.commands.GlobalCommand;
    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 channel environment. Handles
    39   * both channel and server commands.
    40   * @author chris
    41   */
    42  public final class ChannelCommandParser 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 channel instance that this parser is attached to.
    57       */
    58      private final Channel channel;
    59      
    60      /**
    61       * Creates a new instance of ChannelCommandParser.
    62       * @param newServer The server instance that this parser is attached to
    63       * @param newChannel The channel instance that this parser is attached to
    64       */
    65      public ChannelCommandParser(final Server newServer, final Channel newChannel) {
                 /* 
    P/P           *  Method: void com.dmdirc.commandparser.parsers.ChannelCommandParser(Server, Channel)
                  * 
                  *  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.channel == newChannel
                  *    init'ed(this.channel)
                  *    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
                  *    ...
                  */
    66          super();
    67          
    68          this.server = newServer;
    69          this.channel = newChannel;
    70      }
    71      
    72      /** {@inheritDoc} */
    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_CHANNEL);
    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.channel != 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 ChannelCommand) {
    84              ((ChannelCommand) command).execute(origin, server, channel, isSilent, args);
    85          } else if (command instanceof ChatCommand) {
    86              ((ChatCommand) command).execute(origin, server, channel, 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       *
    98       * @param origin The window in which the command was typed
    99       * @param line The line input by the user
   100       */
   101      @Override
   102      protected void handleNonCommand(final InputWindow origin, final String line) {
                 /* 
    P/P           *  Method: void handleNonCommand(InputWindow, String)
                  * 
                  *  Preconditions:
                  *    this.channel != null
                  */
   103          channel.sendLine(line);
   104      }
   105      
   106  }








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