KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > smackx > RemoteRosterEntry


1 /**
2  * $RCSfile$
3  * $Revision: 2407 $
4  * $Date: 2004-11-02 20:37:00 -0300 (Tue, 02 Nov 2004) $
5  *
6  * Copyright 2003-2004 Jive Software.
7  *
8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */

20
21 package org.jivesoftware.smackx;
22
23 import java.util.*;
24
25 /**
26  * Represents a roster item, which consists of a JID and , their name and
27  * the groups the roster item belongs to. This roster item does not belong
28  * to the local roster. Therefore, it does not persist in the server.<p>
29  *
30  * The idea of a RemoteRosterEntry is to be used as part of a roster exchange.
31  *
32  * @author Gaston Dombiak
33  */

34 public class RemoteRosterEntry {
35
36     private String JavaDoc user;
37     private String JavaDoc name;
38     private List groupNames = new ArrayList();
39
40     /**
41      * Creates a new remote roster entry.
42      *
43      * @param user the user.
44      * @param name the user's name.
45      * @param groups the list of group names the entry will belong to, or <tt>null</tt> if the
46      * the roster entry won't belong to a group.
47      */

48     public RemoteRosterEntry(String JavaDoc user, String JavaDoc name, String JavaDoc [] groups) {
49         this.user = user;
50         this.name = name;
51         if (groups != null) {
52             groupNames = new ArrayList(Arrays.asList(groups));
53         }
54     }
55
56     /**
57      * Returns the user.
58      *
59      * @return the user.
60      */

61     public String JavaDoc getUser() {
62         return user;
63     }
64
65     /**
66      * Returns the user's name.
67      *
68      * @return the user's name.
69      */

70     public String JavaDoc getName() {
71         return name;
72     }
73
74     /**
75      * Returns an Iterator for the group names (as Strings) that the roster entry
76      * belongs to.
77      *
78      * @return an Iterator for the group names.
79      */

80     public Iterator getGroupNames() {
81         synchronized (groupNames) {
82             return Collections.unmodifiableList(groupNames).iterator();
83         }
84     }
85
86     /**
87      * Returns a String array for the group names that the roster entry
88      * belongs to.
89      *
90      * @return a String[] for the group names.
91      */

92     public String JavaDoc[] getGroupArrayNames() {
93         synchronized (groupNames) {
94             return (String JavaDoc[])
95                 (Collections
96                     .unmodifiableList(groupNames)
97                     .toArray(new String JavaDoc[groupNames.size()]));
98         }
99     }
100
101     public String JavaDoc toXML() {
102         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
103         buf.append("<item jid=\"").append(user).append("\"");
104         if (name != null) {
105             buf.append(" name=\"").append(name).append("\"");
106         }
107         buf.append(">");
108         synchronized (groupNames) {
109             for (int i = 0; i < groupNames.size(); i++) {
110                 String JavaDoc groupName = (String JavaDoc) groupNames.get(i);
111                 buf.append("<group>").append(groupName).append("</group>");
112             }
113         }
114         buf.append("</item>");
115         return buf.toString();
116     }
117
118 }
119
Popular Tags