KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DISCOInfo


1 import org.jivesoftware.smackx.packet.*;
2
3 /** Represents information about a jabber service.*/
4 public final class DISCOInfo{
5     
6     final static public int JABBER_SERVER=0;
7     final static public int JUD=1;
8     final static public int MUC_SERVICE=2;
9     final static public int MUC_ROOM=3;
10     final static public int AIM_GATEWAY=4;
11     final static public int ICQ_GATEWAY=5;
12     final static public int IRC_GATEWAY=6;
13     final static public int MSN_GATEWAY=7;
14     final static public int YAHOO_GATEWAY=8;
15     final static public int OTHER_GATEWAY=17;
16     
17     final static private int MAX_TYPE=17;
18     final static public int OTHER=99;
19         
20     // category and type list
21
private static final String JavaDoc SERVICES="services";
22     private static final String JavaDoc SERVICE="service";
23     private static final String JavaDoc JABBER="jabber";
24     private static final String JavaDoc JUD_TYPE="jud";
25     private static final String JavaDoc CONFERENCE="conference";
26     private static final String JavaDoc GATEWAY="gateway";
27         private static final String JavaDoc YAHOO="yahoo";
28         private static final String JavaDoc MSN="msn";
29         private static final String JavaDoc ICQ="icq";
30         private static final String JavaDoc IRC="irc";
31         private static final String JavaDoc AIM="aim";
32     
33     // internal variables
34
private int type=OTHER;
35     private String JavaDoc name="";
36     private String JavaDoc jid="";
37     private String JavaDoc info=""; // comma sepertaed list, format is name:category/type eg chat rooms:conference/text
38
private boolean supportsVcard=false;
39     private boolean supportsSearch=false;
40     private boolean supportsRegister=false;
41     private boolean supportsBrowse=true;
42     
43     
44     public DISCOInfo(String JavaDoc jid,String JavaDoc name){
45         this.jid=jid;
46         this.name=name;
47     }
48     
49     public String JavaDoc getJID(){
50         return jid;
51     }
52     
53     public String JavaDoc getName(){
54         return name;
55     }
56     
57     public int getType(){
58         return type;
59     }
60     
61     public String JavaDoc getInfo(){
62         return info;
63     }
64     
65     public void addInfo(String JavaDoc i){
66         if(info.equals("")){
67             info=i;
68             return;
69         }
70         info=","+i;
71     }
72     
73     public void setType(int type){
74         if(type<0 || (type>MAX_TYPE && type!=OTHER)){
75             throw new IllegalArgumentException JavaDoc("Invalid type of "+type);
76         }
77         this.type=type;
78     }
79     
80     public boolean supportsVcard(){
81         return supportsVcard;
82     }
83     
84     public void setSupportsVcard(boolean b){
85         supportsVcard=b;
86     }
87     
88     public boolean supportsRegister(){
89         return supportsRegister;
90     }
91     
92     public void setSupportsRegister(boolean b){
93         supportsRegister=b;
94     }
95     
96     public boolean supportsSearch(){
97         return supportsSearch;
98     }
99     
100     public void setSupportsSearch(boolean b){
101         supportsSearch=b;
102     }
103     
104     public boolean supportsBrowse(){
105         return supportsBrowse;
106     }
107     
108     public void setSupportsBrowse(boolean b){
109         supportsBrowse=b;
110     }
111     
112     public static int determineType(DiscoverInfo.Identity i, String JavaDoc jid){
113         String JavaDoc c;
114         String JavaDoc t;
115         try{
116             c=i.getCategory().trim().toLowerCase();
117             t=i.getType().trim().toLowerCase();
118         }
119         catch(Exception JavaDoc e){
120             return DISCOInfo.OTHER; // incase we have null type and or category
121
}
122         if(c.equals(SERVICES) && t.equals(JABBER)){
123             return DISCOInfo.JABBER_SERVER;
124         }
125         if(c.equals(SERVICE) && t.equals(JUD_TYPE)){
126             return DISCOInfo.JUD;
127         }
128         if(c.equals(CONFERENCE)){
129             if(jid.indexOf("@")==-1){
130                 return DISCOInfo.MUC_SERVICE;
131             }
132             else{
133                 return DISCOInfo.MUC_ROOM;
134             }
135         }
136         if(c.equals(GATEWAY)){
137             if(t.equals(YAHOO)){
138                 return YAHOO_GATEWAY;
139             }
140             if(t.equals(ICQ)){
141                 return ICQ_GATEWAY;
142             }
143             if(t.equals(MSN)){
144                 return MSN_GATEWAY;
145             }
146             if(t.equals(AIM)){
147                 return AIM_GATEWAY;
148             }
149             if(t.equals(IRC)){
150                 return IRC_GATEWAY;
151             }
152             return DISCOInfo.OTHER_GATEWAY;
153         }
154             
155         return DISCOInfo.OTHER;
156     }
157 }
Popular Tags