File Source: ProcessQuit.java

         /* 
    P/P   *  Method: com.dmdirc.parser.irc.ProcessQuit__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.parser.irc;
    24  
    25  import java.util.ArrayList;
    26  
    27  /**
    28   * Process a Quit message.
    29   */
    30  public class ProcessQuit extends IRCProcessor {
    31  
    32  	/**
    33  	 * Process a Quit message.
    34  	 *
    35  	 * @param sParam Type of line to process ("QUIT")
    36  	 * @param token IRCTokenised line to process
    37  	 */
    38  	@Override
    39  	public void process(final String sParam, final String[] token) {
    40  		// :nick!ident@host QUIT
    41  		// :nick!ident@host QUIT :reason
        		 /* 
    P/P 		  *  Method: void process(String, String[])
        		  * 
        		  *  Preconditions:
        		  *    token != null
        		  *    token.length <= 232
        		  *    (soft) init'ed(this.myParser.stringConverter)
        		  *    (soft) this.myParser != null
        		  *    (soft) init'ed(this.myParser.cMyself)
        		  *    (soft) this.myParser.cMyself.sNickname != null
        		  *    (soft) this.myParser.hChannelList != null
        		  *    (soft) this.myParser.hClientList != null
        		  *    (soft) this.myParser.myCallbackManager != null
        		  *    (soft) this.myParser.myCallbackManager.callbackHash != null
        		  *    ...
        		  * 
        		  *  Presumptions:
        		  *    iChannel.hChannelUserList@57 != null
        		  *    iChannel.myParser.hClientList@57 != null
        		  *    iChannel.myParser.stringConverter.lowercase@58 != null
        		  *    iChannel.myParser@57 != null
        		  *    iChannel.sName@57 != null
        		  *    ...
        		  * 
        		  *  Postconditions:
        		  *    init'ed(this.myParser.stringConverter)
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1) num objects)
        		  *    new IRCStringConverter(getIRCStringConverter#1) num objects <= 1
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).limit)
        		  *    new IRCStringConverter(getIRCStringConverter#1).limit == 4
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).lowercase)
        		  *    new IRCStringConverter(getIRCStringConverter#1).lowercase == &amp;new char[](IRCStringConverter#1)
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).uppercase)
        		  *    new IRCStringConverter(getIRCStringConverter#1).uppercase == &amp;new char[](IRCStringConverter#2)
        		  *    init'ed(new char[](IRCStringConverter#1) num objects)
        		  *    ...
        		  * 
        		  *  Test Vectors:
        		  *    this.myParser.removeAfterCallback: {0}, {1}
        		  *    token.length: {2}, {0,1}, {3..232}
        		  *    java.lang.String:isEmpty(...)@49: {0}, {1}
        		  *    java.util.Iterator:hasNext(...)@57: {0}, {1}
        		  */
    42  		if (token.length < 2) { return; }
    43  		ClientInfo iClient;
    44  		ChannelClientInfo iChannelClient;
    45  		
    46  		iClient = getClientInfo(token[0]);
    47  		
    48  		if (iClient == null) { return; }
    49  		if (IRCParser.ALWAYS_UPDATECLIENT && iClient.getHost().isEmpty()) {
    50  			// This may seem pointless - updating before they leave - but the formatter needs it!
    51  			iClient.setUserBits(token[0],false);
    52  		}
    53  		String sReason = "";
    54  		if (token.length > 2) { sReason = token[token.length-1]; }
    55  		
    56  		ArrayList<ChannelInfo> channelList = new ArrayList<ChannelInfo>(myParser.getChannels());
    57  		for (ChannelInfo iChannel : channelList) {
    58  			iChannelClient = iChannel.getUser(iClient);
    59  			if (iChannelClient != null) {
    60  				if (myParser.removeAfterCallback) { callChannelQuit(iChannel,iChannelClient,sReason); }
    61  				if (iClient == myParser.getMyself()) {
    62  					iChannel.emptyChannel();
    63  					myParser.removeChannel(iChannel);
    64  				} else {
    65  					iChannel.delClient(iClient);
    66  				}
    67  				if (!myParser.removeAfterCallback) { callChannelQuit(iChannel,iChannelClient,sReason); }
    68  			}
    69  		}
    70  
    71  		if (myParser.removeAfterCallback) { callQuit(iClient,sReason); }
    72  		if (iClient == myParser.getMyself()) {
    73  			myParser.clearClients();
    74  		} else {
    75  			myParser.removeClient(iClient);
    76  		}
    77  		if (!myParser.removeAfterCallback) { callQuit(iClient,sReason); }
    78  	}	
    79  	
    80  	/**
    81  	 * Callback to all objects implementing the ChannelQuit Callback.
    82  	 *
    83  	 * @see IChannelQuit
    84  	 * @param cChannel Channel that user was on
    85  	 * @param cChannelClient User thats quitting
    86  	 * @param sReason Quit reason
    87  	 * @return true if a method was called, false otherwise
    88  	 */
    89  	protected boolean callChannelQuit(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sReason) {
        		 /* 
    P/P 		  *  Method: bool callChannelQuit(ChannelInfo, ChannelClientInfo, String)
        		  * 
        		  *  Preconditions:
        		  *    this.myParser != null
        		  *    this.myParser.myCallbackManager != null
        		  *    this.myParser.myCallbackManager.callbackHash != null
        		  * 
        		  *  Presumptions:
        		  *    getCallbackManager(...)@90 init'ed
        		  * 
        		  *  Postconditions:
        		  *    init'ed(return_value)
        		  */
    90  		return getCallbackManager().getCallbackType("OnChannelQuit").call(cChannel, cChannelClient, sReason);
    91  	}
    92  	
    93  	/**
    94  	 * Callback to all objects implementing the Quit Callback.
    95  	 *
    96  	 * @see IQuit
    97  	 * @param cClient Client Quitting
    98  	 * @param sReason Reason for quitting (may be "")
    99  	 * @return true if a method was called, false otherwise
   100  	 */
   101  	protected boolean callQuit(final ClientInfo cClient, final String sReason) {
        		 /* 
    P/P 		  *  Method: bool callQuit(ClientInfo, String)
        		  * 
        		  *  Preconditions:
        		  *    this.myParser != null
        		  *    this.myParser.myCallbackManager != null
        		  *    this.myParser.myCallbackManager.callbackHash != null
        		  * 
        		  *  Presumptions:
        		  *    getCallbackManager(...)@102 init'ed
        		  * 
        		  *  Postconditions:
        		  *    init'ed(return_value)
        		  */
   102  		return getCallbackManager().getCallbackType("OnQuit").call(cClient, sReason);
   103  	}
   104  	
   105  	/**
   106  	 * What does this IRCProcessor handle.
   107  	 *
   108  	 * @return String[] with the names of the tokens we handle.
   109  	 */
   110  	@Override
   111  	public String[] handles() {
        		 /* 
    P/P 		  *  Method: String[] handles()
        		  * 
        		  *  Postconditions:
        		  *    return_value == &amp;new String[](handles#1)
        		  *    new String[](handles#1) num objects == 1
        		  *    return_value.length == 1
        		  *    return_value[0] == &amp;"QUIT"
        		  */
   112  		return new String[]{"QUIT"};
   113  	} 
   114  	
   115  	/**
   116  	 * Create a new instance of the IRCProcessor Object.
   117  	 *
   118  	 * @param parser IRCParser That owns this IRCProcessor
   119  	 * @param manager ProcessingManager that is in charge of this IRCProcessor
   120  	 */
        	 /* 
    P/P 	  *  Method: void com.dmdirc.parser.irc.ProcessQuit(IRCParser, ProcessingManager)
        	  * 
        	  *  Postconditions:
        	  *    this.myManager == manager
        	  *    init'ed(this.myManager)
        	  *    this.myParser == parser
        	  *    init'ed(this.myParser)
        	  */
   121  	protected ProcessQuit (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
   122  
   123  }








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