KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > model > InstantMessagingModel


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.addressbook.model;
19
20 public class InstantMessagingModel {
21
22     public final static int TYPE_JABBER = 0;
23     public final static int TYPE_AIM = 1;
24     public final static int TYPE_YAHOO = 2;
25     public final static int TYPE_MSN = 3;
26     public final static int TYPE_ICQ = 4;
27     
28     public static final String JavaDoc[] NAMES = new String JavaDoc[] { "Jabber", "AIM",
29             "Yahoo", "MSN", "ICQ" };
30
31     private String JavaDoc userId;
32
33     private int type;
34
35     public InstantMessagingModel(String JavaDoc userId, String JavaDoc type) {
36         if (userId == null)
37             throw new IllegalArgumentException JavaDoc("userId == null");
38         if (type == null)
39             throw new IllegalArgumentException JavaDoc("type == null");
40
41         this.userId = userId;
42
43         boolean foundMatch = false;
44         for (int i = 0; i < NAMES.length; i++) {
45             if (type.equals(NAMES[i])) {
46                 foundMatch = true;
47                 this.type = i;
48             }
49         }
50
51         if (!foundMatch)
52             throw new IllegalArgumentException JavaDoc("unsupported type= " + type);
53     }
54
55     public InstantMessagingModel(String JavaDoc userId, int type) {
56         if (userId == null)
57             throw new IllegalArgumentException JavaDoc("userId == null");
58         if (type < 0 || type >= NAMES.length)
59             throw new IllegalArgumentException JavaDoc("unsupported type= " + type);
60
61         this.userId = userId;
62         this.type = type;
63     }
64
65     /**
66      * @return Returns the type.
67      */

68     public int getType() {
69         return type;
70     }
71
72     /**
73      * @return Returns the userId.
74      */

75     public String JavaDoc getUserId() {
76         return userId;
77     }
78
79     public String JavaDoc getTypeString() {
80         return NAMES[type];
81     }
82
83 }
84
Popular Tags