diff --git a/source/org/jivesoftware/smackx/packet/RemoteRosterEntry.java b/source/org/jivesoftware/smackx/RemoteRosterEntry.java
similarity index 84%
rename from source/org/jivesoftware/smackx/packet/RemoteRosterEntry.java
rename to source/org/jivesoftware/smackx/RemoteRosterEntry.java
index b6cc1a8a0..7c8829408 100644
--- a/source/org/jivesoftware/smackx/packet/RemoteRosterEntry.java
+++ b/source/org/jivesoftware/smackx/RemoteRosterEntry.java
@@ -50,7 +50,7 @@
* ====================================================================
*/
-package org.jivesoftware.smackx.packet;
+package org.jivesoftware.smackx;
import java.util.*;
@@ -67,18 +67,22 @@ public class RemoteRosterEntry {
private String user;
private String name;
- private List groupNames;
+ private List groupNames = new ArrayList();
/**
* Creates a new remote roster entry.
*
* @param user the user.
* @param name the user's name.
+ * @param groups the list of group names the entry will belong to, or null if the
+ * the roster entry won't belong to a group.
*/
- public RemoteRosterEntry(String user, String name) {
+ public RemoteRosterEntry(String user, String name, String [] groups) {
this.user = user;
this.name = name;
- groupNames = new ArrayList();
+ if (groups != null) {
+ groupNames = new ArrayList(Arrays.asList(groups));
+ }
}
/**
@@ -99,15 +103,6 @@ public class RemoteRosterEntry {
return name;
}
- /**
- * Sets the user's name.
- *
- * @param name the user's name.
- */
- public void setName(String name) {
- this.name = name;
- }
-
/**
* Returns an Iterator for the group names (as Strings) that the roster entry
* belongs to.
@@ -135,30 +130,6 @@ public class RemoteRosterEntry {
}
}
- /**
- * Adds a group name.
- *
- * @param groupName the group name.
- */
- public void addGroupName(String groupName) {
- synchronized (groupNames) {
- if (!groupNames.contains(groupName)) {
- groupNames.add(groupName);
- }
- }
- }
-
- /**
- * Removes a group name.
- *
- * @param groupName the group name.
- */
- public void removeGroupName(String groupName) {
- synchronized (groupNames) {
- groupNames.remove(groupName);
- }
- }
-
public String toXML() {
StringBuffer buf = new StringBuffer();
buf.append("-
@@ -106,14 +107,17 @@ public class RosterExchange implements PacketExtension {
* @param rosterEntry a roster entry to add.
*/
public void addRosterEntry(RosterEntry rosterEntry) {
- RosterGroup rosterGroup = null;
+ // Obtain a String[] from the roster entry groups name
+ ArrayList groupNamesList = new ArrayList();
+ String[] groupNames;
+ for (Iterator groups = rosterEntry.getGroups(); groups.hasNext();) {
+ groupNamesList.add(((RosterGroup) groups.next()).getName());
+ }
+ groupNames = (String[]) groupNamesList.toArray(new String[groupNamesList.size()]);
+
// Create a new Entry based on the rosterEntry and add it to the packet
- RemoteRosterEntry remoteRosterEntry = new RemoteRosterEntry(rosterEntry.getUser(), rosterEntry.getName());
- // Add the entry groups to the Entry
- for (Iterator groups = rosterEntry.getGroups(); groups.hasNext();) {
- rosterGroup = (RosterGroup) groups.next();
- remoteRosterEntry.addGroupName(rosterGroup.getName());
- }
+ RemoteRosterEntry remoteRosterEntry = new RemoteRosterEntry(rosterEntry.getUser(), rosterEntry.getName(), groupNames);
+
addRosterEntry(remoteRosterEntry);
}
diff --git a/source/org/jivesoftware/smackx/provider/RosterExchangeProvider.java b/source/org/jivesoftware/smackx/provider/RosterExchangeProvider.java
index 69ce09880..203961aea 100644
--- a/source/org/jivesoftware/smackx/provider/RosterExchangeProvider.java
+++ b/source/org/jivesoftware/smackx/provider/RosterExchangeProvider.java
@@ -52,8 +52,11 @@
package org.jivesoftware.smackx.provider;
+import java.util.ArrayList;
+
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.jivesoftware.smackx.*;
import org.jivesoftware.smackx.packet.*;
import org.xmlpull.v1.XmlPullParser;
@@ -84,21 +87,26 @@ public class RosterExchangeProvider implements PacketExtensionProvider {
RosterExchange rosterExchange = new RosterExchange();
boolean done = false;
RemoteRosterEntry remoteRosterEntry = null;
+ String jid = "";
+ String name = "";
+ ArrayList groupsName = new ArrayList();
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("item")) {
- String jid = parser.getAttributeValue("", "jid");
- String name = parser.getAttributeValue("", "name");
- // Create packet.
- remoteRosterEntry = new RemoteRosterEntry(jid, name);
+ // Reset this variable since they are optional for each item
+ groupsName = new ArrayList();
+ // Initialize the variables from the parsed XML
+ jid = parser.getAttributeValue("", "jid");
+ name = parser.getAttributeValue("", "name");
}
if (parser.getName().equals("group")) {
- String groupName = parser.nextText();
- remoteRosterEntry.addGroupName(groupName);
+ groupsName.add(parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("item")) {
+ // Create packet.
+ remoteRosterEntry = new RemoteRosterEntry(jid, name, (String[]) groupsName.toArray(new String[groupsName.size()]));
rosterExchange.addRosterEntry(remoteRosterEntry);
}
if (parser.getName().equals("x")) {
diff --git a/test/org/jivesoftware/smackx/RosterExchangeManagerTest.java b/test/org/jivesoftware/smackx/RosterExchangeManagerTest.java
index 2c54de44f..52b1fdc3e 100644
--- a/test/org/jivesoftware/smackx/RosterExchangeManagerTest.java
+++ b/test/org/jivesoftware/smackx/RosterExchangeManagerTest.java
@@ -57,7 +57,6 @@ import java.util.Iterator;
import junit.framework.TestCase;
import org.jivesoftware.smack.*;
-import org.jivesoftware.smackx.packet.RemoteRosterEntry;
/**
diff --git a/test/org/jivesoftware/smackx/packet/RosterExchangeTest.java b/test/org/jivesoftware/smackx/packet/RosterExchangeTest.java
index 03b720fb2..abb590a6b 100644
--- a/test/org/jivesoftware/smackx/packet/RosterExchangeTest.java
+++ b/test/org/jivesoftware/smackx/packet/RosterExchangeTest.java
@@ -9,6 +9,7 @@ import java.util.Iterator;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.filter.*;
import org.jivesoftware.smack.packet.*;
+import org.jivesoftware.smackx.*;
import junit.framework.TestCase;