Added uniformity rules to generating account uid strings. These rules are relied upon by the meta contact list service.

cusax-fix
Emil Ivov 20 years ago
parent d0d4376340
commit 86efaf6f93

@ -66,41 +66,41 @@ public ServiceReference getProviderForAccount(AccountID accountID)
*
* @param context the BundleContext parameter where the newly created
* ProtocolProviderService would have to be registered.
* @param accountIDStr the user identifier for the new account
* @param userIDStr the user identifier for the new account
* @param accountProperties a set of protocol (or implementation)
* specific properties defining the new account.
* @return the AccountID of the newly created account
*/
public AccountID installAccount( BundleContext context,
String accountIDStr,
String userIDStr,
Map accountProperties)
{
if(context == null)
throw new NullPointerException("The specified BundleContext was null");
if(accountIDStr == null)
if(userIDStr == null)
throw new NullPointerException("The specified AccountID was null");
if(accountIDStr == null)
if(accountProperties == null)
throw new NullPointerException("The specified property map was null");
AccountID accountID = new IcqAccountID(accountIDStr, accountProperties);
AccountID accountID = new IcqAccountID(userIDStr, accountProperties);
//make sure we haven't seen this account id before.
if( registeredAccounts.containsKey(accountID) )
throw new IllegalStateException(
"An account for id " + accountIDStr + " was already installed!");
"An account for id " + userIDStr + " was already installed!");
Hashtable properties = new Hashtable();
properties.put(
AccountManager.PROTOCOL_PROPERTY_NAME, ProtocolNames.ICQ);
properties.put(
AccountManager.ACCOUNT_ID_PROPERTY_NAME, accountIDStr);
AccountManager.ACCOUNT_ID_PROPERTY_NAME, userIDStr);
ProtocolProviderServiceIcqImpl icqProtocolProvider
= new ProtocolProviderServiceIcqImpl();
icqProtocolProvider.initialize(accountIDStr, accountProperties);
icqProtocolProvider.initialize(userIDStr, accountProperties, accountID);
ServiceRegistration registration
= context.registerService( ProtocolProviderService.class.getName(),

@ -12,8 +12,8 @@
public class IcqAccountID
extends AccountID
{
IcqAccountID(String accountID, Map accountProperties)
IcqAccountID(String accountID, Map accountProperties )
{
super(accountID, accountProperties);
super(accountID, accountProperties, ProtocolNames.ICQ, "icq.com");
}
}

@ -9,12 +9,22 @@
import java.util.*;
/**
* The AccountID is an account identifier that, combined with the protocol
* itself, uniquely represents a specific user account. The class needs to be
* extended by every protocol implementation because of its protected
* The AccountID is an account identifier that, uniquely represents a specific
* user account over a specific protocol. The class needs to be extended by
* every protocol implementation because of its protected
* constructor. The reason why this constructor is protected is mostly avoiding
* confusion and letting people (using the protocol provider service) believe
* that they are the ones who are supposed to instantiate the accountid class.
* <p>
* Every instance of teh <tt>ProtocolProviderService</tt>, created through the
* account manager is assigned an AccountID instance, that uniquely represents
* it and whose string representation (obtainted through the getAccountUID()
* method) can be used for identification of persistently stored account details.
* <p>
* Account id's are guaranteed to be different for different accounts and in the
* same time are bound to be equal for multiple installations of the same
* account.
*
* @author Emil Ivov
*/
@ -28,35 +38,66 @@ public abstract class AccountID
protected Map accountProperties = null;
/**
* A String uniquely identyfying the user for this particular service.
* A String uniquely identifying the user for this particular account.
*/
protected String userID = null;
/**
* A String uniquely identifying this account, that can also be used for
* storing and unambiguously retrieving details concerning it.
*/
protected String accountID = null;
protected String accountUID = null;
/**
* Creates an account id for the specified provider userid and
* accountProperties
* @param accountID a String that uniquely identifies the user.
* accountProperties.
* @param userID a String that uniquely identifies the user.
* @param accountProperties a Map containing any other protocol and
* implementation specific account initialization properties
* @param protocolName the name of the protocol implemented by the provider
* that this id is meant for.
* @param serviceName the name of the service (e.g. iptel.org, jabber.org,
* icq.com) that this account is registered with.
*/
protected AccountID( String accountID,
Map accountProperties)
protected AccountID( String userID,
Map accountProperties,
String protocolName,
String serviceName)
{
super();
this.accountID = String.copyValueOf(accountID.toCharArray());
this.userID = userID;
this.accountProperties = new Hashtable(accountProperties);
//create a unique identifier string
//NOTE: the service name is most probably already present in the userID
//(e.g. in sip or jabber uris) but since this string is not meant to be
//seen by the user, it won't hurt adding it again. It could avoid
//duplicate IDs with protocols that are not meant to work accross
//servers (e.g. imagine some weird case where you have the same icq id
//with both the AIM server and some private ICQ server).
this.accountUID = protocolName + ":" + userID + "@" + serviceName;
}
/**
* Returns the user id of this class.
* Returns the user id associated with this account.
*
* @return A String uniquely identyfying the user inside this particular
* service.
* @return A String identyfying the user inside this particular service.
*/
public String getAccountUserID()
{
return userID;
}
/**
* Returns a String uniquely idnetifying this account, guaranteed to remain
* the same accross multiple installations of the same account and to always
* be unique for differing accounts.
* @return String
*/
public String getAccountID()
public String getAccountUID()
{
return accountID;
return accountUID;
}
/**
@ -81,7 +122,7 @@ public Map getAccountProperties()
*/
public int hashCode()
{
return accountID == null? 0 : accountID.hashCode();
return accountUID == null? 0 : accountUID.hashCode();
}
/**
@ -95,13 +136,16 @@ public int hashCode()
*/
public boolean equals(Object obj)
{
if (this == obj)
return true;
if( obj == null
|| ! (getClass().isInstance(obj))
|| ! (accountID.equals(((AccountID)obj).accountID))
|| ! (accountProperties.equals(((AccountID)obj).accountProperties)))
|| ! (userID.equals(((AccountID)obj).userID)))
return false;
return true;
}
}

Loading…
Cancel
Save