File Source: ProcessPart.java

         /* 
    P/P   *  Method: com.dmdirc.parser.irc.ProcessPart__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  /**
    26   * Process a channel part.
    27   */
    28  public class ProcessPart extends IRCProcessor {
    29  
    30  	/**
    31  	 * Process a channel part.
    32  	 *
    33  	 * @param sParam Type of line to process ("PART")
    34  	 * @param token IRCTokenised line to process
    35  	 */
    36  	@Override
    37  	public void process(final String sParam, final String[] token) {
    38  		// :nick!ident@host PART #Channel
    39  		// :nick!ident@host PART #Channel :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.hChannelList != null
        		  *    (soft) this.myParser.hClientList != null
        		  *    (soft) init'ed(this.myParser.lastLine)
        		  *    (soft) this.myParser.myCallbackManager != null
        		  *    (soft) this.myParser.myCallbackManager.callbackHash != null
        		  *    ...
        		  * 
        		  *  Presumptions:
        		  *    iChannel.hChannelUserList != null
        		  *    iChannel.myParser != null
        		  *    iChannel.myParser.hClientList != null
        		  *    iChannel.myParser.stringConverter.lowercase@68 != null
        		  *    iChannel.sName != null
        		  *    ...
        		  * 
        		  *  Postconditions:
        		  *    init'ed(this.myParser.stringConverter)
        		  *    new IRCStringConverter(getIRCStringConverter#1) num objects <= 1
        		  *    new IRCStringConverter(getIRCStringConverter#1) num objects == 0
        		  *    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)
        		  *    new char[](IRCStringConverter#1) num objects <= 1
        		  *    ...
        		  * 
        		  *  Test Vectors:
        		  *    this.myParser.removeAfterCallback: {0}, {1}
        		  *    token.length: {3}, {0..2}, {4..232}
        		  *    java.lang.String:isEmpty(...)@49: {0}, {1}
        		  */
    40  		if (token.length < 3) { return; }
    41  		ClientInfo iClient;
    42  		ChannelInfo iChannel;
    43  		ChannelClientInfo iChannelClient;
    44  		
    45  		iClient = getClientInfo(token[0]);
    46  		iChannel = getChannelInfo(token[2]);
    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  		if (iChannel == null) { 
    54  			if (iClient != myParser.getMyself()) {
    55  				callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got part for channel ("+token[2]+") that I am not on. [User: "+token[0]+"]", myParser.getLastLine()));
    56  			}
    57  			return;
    58  		} else {
    59  			String sReason = "";
    60  			if (token.length > 3) { sReason = token[token.length-1]; }
    61  			iChannelClient = iChannel.getUser(iClient);
    62  			if (iChannelClient == null) {
    63  				// callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got part for channel ("+token[2]+") for a non-existant user. [User: "+token[0]+"]", myParser.getLastLine()));
    64  				return;
    65  			}
    66  			if (myParser.removeAfterCallback) { callChannelPart(iChannel,iChannelClient,sReason); }
    67  			callDebugInfo(IRCParser.DEBUG_INFO, "Removing %s from %s",iClient.getNickname(),iChannel.getName());
    68  			iChannel.delClient(iClient);
    69  			if (!myParser.removeAfterCallback) { callChannelPart(iChannel,iChannelClient,sReason); }
    70  			if (iClient == myParser.getMyself()) {
    71  				iChannel.emptyChannel();
    72  				myParser.removeChannel(iChannel);
    73  			}
    74  		}
    75  	}
    76  	
    77  	/**
    78  	 * Callback to all objects implementing the ChannelPart Callback.
    79  	 *
    80  	 * @see IChannelPart
    81  	 * @param cChannel Channel that the user parted
    82  	 * @param cChannelClient Client that parted
    83  	 * @param sReason Reason given for parting (May be "")
    84  	 * @return true if a method was called, false otherwise
    85  	 */
    86  	protected boolean callChannelPart(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sReason) {
        		 /* 
    P/P 		  *  Method: bool callChannelPart(ChannelInfo, ChannelClientInfo, String)
        		  * 
        		  *  Preconditions:
        		  *    this.myParser != null
        		  *    this.myParser.myCallbackManager != null
        		  *    this.myParser.myCallbackManager.callbackHash != null
        		  * 
        		  *  Presumptions:
        		  *    getCallbackManager(...)@87 init'ed
        		  * 
        		  *  Postconditions:
        		  *    init'ed(return_value)
        		  */
    87  		return getCallbackManager().getCallbackType("OnChannelPart").call(cChannel, cChannelClient, sReason);
    88  	}
    89  	
    90  	/**
    91  	 * What does this IRCProcessor handle.
    92  	 *
    93  	 * @return String[] with the names of the tokens we handle.
    94  	 */
    95  	@Override
    96  	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;"PART"
        		  */
    97  		return new String[]{"PART"};
    98  	} 
    99  	
   100  	/**
   101  	 * Create a new instance of the IRCProcessor Object.
   102  	 *
   103  	 * @param parser IRCParser That owns this IRCProcessor
   104  	 * @param manager ProcessingManager that is in charge of this IRCProcessor
   105  	 */
        	 /* 
    P/P 	  *  Method: void com.dmdirc.parser.irc.ProcessPart(IRCParser, ProcessingManager)
        	  * 
        	  *  Postconditions:
        	  *    this.myManager == manager
        	  *    init'ed(this.myManager)
        	  *    this.myParser == parser
        	  *    init'ed(this.myParser)
        	  */
   106  	protected ProcessPart (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
   107  
   108  }








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