1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +02:00

SMACK-441 ServiceDiscoveryManager identities should be non-static and kept in a Set to allow multiple identities as per XEP-0030

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@13783 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Florian Schmaus 2013-10-22 14:43:23 +00:00 committed by flow
parent 5f793d4f44
commit c4014b8ba9
4 changed files with 49 additions and 34 deletions

View file

@ -54,7 +54,8 @@ public class ServiceDiscoveryManager {
private static final String DEFAULT_IDENTITY_CATEGORY = "client";
private static final String DEFAULT_IDENTITY_TYPE = "pc";
private static List<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();
private Set<DiscoverInfo.Identity> identities = new HashSet<DiscoverInfo.Identity>();
private DiscoverInfo.Identity identity = new Identity(DEFAULT_IDENTITY_CATEGORY, DEFAULT_IDENTITY_NAME, DEFAULT_IDENTITY_TYPE);
private EntityCapsManager capsManager;
@ -74,7 +75,6 @@ public class ServiceDiscoveryManager {
new ServiceDiscoveryManager(connection);
}
});
identities.add(new Identity(DEFAULT_IDENTITY_CATEGORY, DEFAULT_IDENTITY_NAME, DEFAULT_IDENTITY_TYPE));
}
/**
@ -86,6 +86,7 @@ public class ServiceDiscoveryManager {
*/
public ServiceDiscoveryManager(Connection connection) {
this.connection = connection;
identities.add(identity);
init();
}
@ -107,13 +108,8 @@ public class ServiceDiscoveryManager {
* @return the name of the client that will be returned when asked for the client identity
* in a disco request.
*/
public static String getIdentityName() {
DiscoverInfo.Identity identity = identities.get(0);
if (identity != null) {
return identity.getName();
} else {
return null;
}
public String getIdentityName() {
return identity.getName();
}
/**
@ -123,10 +119,8 @@ public class ServiceDiscoveryManager {
* @param name the name of the client that will be returned when asked for the client identity
* in a disco request.
*/
public static void setIdentityName(String name) {
DiscoverInfo.Identity identity = identities.remove(0);
identity = new DiscoverInfo.Identity(DEFAULT_IDENTITY_CATEGORY, name, DEFAULT_IDENTITY_TYPE);
identities.add(identity);
public void setIdentityName(String name) {
identity.setName(name);
}
/**
@ -137,13 +131,8 @@ public class ServiceDiscoveryManager {
* @return the type of client that will be returned when asked for the client identity in a
* disco request.
*/
public static String getIdentityType() {
DiscoverInfo.Identity identity = identities.get(0);
if (identity != null) {
return identity.getType();
} else {
return null;
}
public String getIdentityType() {
return identity.getType();
}
/**
@ -154,14 +143,30 @@ public class ServiceDiscoveryManager {
* @param type the type of client that will be returned when asked for the client identity in a
* disco request.
*/
public static void setIdentityType(String type) {
DiscoverInfo.Identity identity = identities.get(0);
if (identity != null) {
identity.setType(type);
} else {
identity = new DiscoverInfo.Identity(DEFAULT_IDENTITY_CATEGORY, DEFAULT_IDENTITY_NAME, type);
identities.add(identity);
}
public void setIdentityType(String type) {
identity.setType(type);
}
/**
* Add an identity to the client.
*
* @param identity
*/
public void addIdentity(DiscoverInfo.Identity identity) {
identities.add(identity);
}
/**
* Remove an identity from the client. Note that the client needs at least one identity, the default identity, which
* can not be removed.
*
* @param identity
* @return true, if successful. Otherwise the default identity was given.
*/
public boolean removeIdentity(DiscoverInfo.Identity identity) {
if (identity.equals(this.identity)) return false;
identities.remove(identity);
return true;
}
/**
@ -169,8 +174,8 @@ public class ServiceDiscoveryManager {
*
* @return
*/
public static List<DiscoverInfo.Identity> getIdentities() {
return Collections.unmodifiableList(identities);
public Set<DiscoverInfo.Identity> getIdentities() {
return Collections.unmodifiableSet(identities);
}
/**