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.msn.message;
20  
21  import java.util.StringTokenizer;
22  
23  import net.sf.dexterim.msn.MsnConnection;
24  import net.sf.dexterim.msn.entity.SwitchBoardServer;
25  
26  /***
27   *  Description of the Class
28   *
29   *@author     christoph
30   */
31  public class SwitchBoardMessage extends SingleLineMessage {
32    private String ip;
33    private int port;
34    private String cki;
35    private String id;
36  
37    /***
38     *  Constructor for the SwitchBoardMessage object
39     */
40    public SwitchBoardMessage() {
41    }
42  
43    public SwitchBoardMessage(String ip, int port, String cki) {
44      this.ip = ip;
45      this.port = port;
46      this.cki = cki;
47    }
48  
49    /***
50     *  Gets the messageCommand attribute of the SwitchBoardMessage object
51     *
52     *@return    The messageCommand value
53     */
54    public String getMessageCommand() {
55      return MsnMessageFactory.CMD_REFER;
56    }
57  
58    public SwitchBoardServer getSwitchBoardServer() {
59      return new SwitchBoardServer(ip, port, cki);
60    }
61  
62    /***
63     *  Adds a feature to the Line attribute of the SwitchBoardMessage object
64     *
65     *@param  line                        The feature to be added to the Line
66     *      attribute
67     *@return                             Description of the Return Value
68     *@exception  MessageFormatException  Description of the Exception
69     */
70    public MsnMessage addLine(String line) throws MessageFormatException {
71      try {
72        StringTokenizer st = new StringTokenizer(line);
73  
74        st.nextToken();
75  
76        this.id = st.nextToken();
77  
78        st.nextToken();
79  
80        String s = st.nextToken();
81  
82        int i = s.indexOf(":");
83  
84        if (i < 0) {
85          throw new MessageFormatException("Unexpected Reply, switchboard port and IP are missing");
86        }
87  
88        this.ip = s.substring(0, i);
89  
90        this.port = Integer.parseInt(s.substring(i + 1));
91  
92        st.nextToken();
93  
94        this.cki = st.nextToken();
95  
96        return this;
97      }
98      catch (Exception ex) {
99        throw new MessageFormatException(ex);
100     }
101   }
102 
103   /*** Getter for property id.
104    * @return Value of property id.
105    *
106    */
107   public java.lang.String getId() {
108     return id;
109   }
110 
111   /* (non-Javadoc)
112    * @see net.sf.dexterim.msn.message.MsnMessage#process(net.sf.dexterim.msn.MsnConnection)
113    */
114   public void process(MsnConnection connection) {
115     // TODO Auto-generated method stub
116     
117   }
118 }