View Javadoc

1   //////////////////////////////////////////////////////////////////////////////
2   // dexterIM - Instant Messaging Framework
3   // Copyright (C) 2003 Christoph Walcher
4   //
5   // This program is free software; you can redistribute it and/or modify
6   // it under the terms of the GNU General Public License as published by
7   // the Free Software Foundation; either version 2 of the License, or
8   // (at your option) any later version.
9   //
10  // This program is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  // GNU General Public License for more details.
14  //
15  // You should have received a copy of the GNU General Public License
16  // along with this program; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  //////////////////////////////////////////////////////////////////////////////
19  package net.sf.dexterim.oscar.io;
20  
21  import net.sf.dexterim.oscar.entity.Snac;
22  import net.sf.dexterim.oscar.entity.SnacFamiliesVersions;
23  import net.sf.dexterim.oscar.server.GenericSnacResponse;
24  import net.sf.dexterim.oscar.server.MessageOfTheDayResponse;
25  import net.sf.dexterim.oscar.server.RateInfoResponse;
26  import net.sf.dexterim.oscar.server.Response;
27  import net.sf.dexterim.oscar.server.SupportedSnacFamilies;
28  
29  import org.apache.commons.logging.Log;
30  import org.apache.commons.logging.LogFactory;
31  
32  /***
33   * @author christoph
34   */
35  public class GenericServiceControlsParser implements SnacParserDelegate {
36  
37  	private static final int SNAC_FAMILIES = 0x0003;
38  	private static final int SNAC_FAMILIES_VERSIONS = 0x0018;
39  	private static final int SNAC_MOTD = 0x0013;
40  	private static final int SNAC_RATE_INFO_RESPONSE = 0x0007;
41  
42  	private Log log;
43  
44  	public GenericServiceControlsParser() {
45  		log = LogFactory.getLog(getClass());
46  	}
47  
48  	/*
49  	 * (non-Javadoc)
50  	 * 
51  	 * @see net.sf.dexterim.oscar.io.SnacParserDelegate#parse(net.sf.dexterim.oscar.entity.Snac)
52  	 */
53  	public Response parse(Snac snac) throws ParserException {
54  		switch (snac.getType()) {
55  			case SNAC_FAMILIES:
56  				return SupportedSnacFamilies.create(snac);
57  			
58  			case SNAC_FAMILIES_VERSIONS:
59  				return SnacFamiliesVersions.create(snac);
60  				
61  			case SNAC_MOTD:
62  				return MessageOfTheDayResponse.create(snac);
63  			
64  			case SNAC_RATE_INFO_RESPONSE:
65  				return RateInfoResponse.create(snac);
66  				
67  			default:
68  				if (log.isDebugEnabled()) {
69  					log.debug("No Parser for subType " + snac.getType() + " available");
70  				}
71  				
72  				return new GenericSnacResponse(snac);
73  		}
74  	}
75  
76  }