Renamed AccountManager to ProtocolProviderFactory

cusax-fix
Emil Ivov 20 years ago
parent cd5b2570f7
commit b61ee81674

@ -20,7 +20,7 @@
import net.java.sip.communicator.impl.gui.main.i18n.Messages;
import net.java.sip.communicator.impl.gui.utils.Constants;
import net.java.sip.communicator.service.protocol.AccountID;
import net.java.sip.communicator.service.protocol.AccountManager;
import net.java.sip.communicator.service.protocol.ProtocolProviderFactory;
import net.java.sip.communicator.service.protocol.AccountProperties;
import net.java.sip.communicator.service.protocol.ProtocolNames;
import net.java.sip.communicator.service.protocol.ProtocolProviderService;
@ -42,7 +42,7 @@ public class LoginManager implements RegistrationStateChangeListener {
private BundleContext bc;
private Hashtable accountManagersMap = new Hashtable();
private Hashtable providerFactoriesMap = new Hashtable();
private Hashtable loginWindows = new Hashtable();
@ -58,8 +58,8 @@ public LoginManager(BundleContext bc) {
ServiceReference[] serRefs = null;
try {
//get all registered account managers
serRefs = this.bc.getServiceReferences(AccountManager.class
//get all registered provider factories
serRefs = this.bc.getServiceReferences(ProtocolProviderFactory.class
.getName(), null);
} catch (InvalidSyntaxException e) {
@ -69,38 +69,38 @@ public LoginManager(BundleContext bc) {
for (int i = 0; i < serRefs.length; i++) {
AccountManager accountManager = (AccountManager) this.bc
ProtocolProviderFactory providerFactory = (ProtocolProviderFactory) this.bc
.getService(serRefs[i]);
this.accountManagersMap.put(serRefs[i]
.getProperty(AccountManager.PROTOCOL_PROPERTY_NAME),
accountManager);
this.providerFactoriesMap.put(serRefs[i]
.getProperty(ProtocolProviderFactory.PROTOCOL_PROPERTY_NAME),
providerFactory);
}
}
/**
* Implements the login. Installs the account and registers
* the appropriate protocol provider.
*
* @param accountManager The AccountManager where the account
*
* @param providerFactory The ProtocolProviderFactory where the account
* should be installed.
* @param user The user identifier.
* @param passwd The password.
*/
public void login(AccountManager accountManager,
String user,
public void login(ProtocolProviderFactory providerFactory,
String user,
String passwd) {
Hashtable accountProperties = new Hashtable();
accountProperties.put(AccountProperties.PASSWORD, passwd);
this.accountID = accountManager.installAccount(this.bc, user,
this.accountID = providerFactory.installAccount(this.bc, user,
accountProperties);
ServiceReference serRef = accountManager
ServiceReference serRef = providerFactory
.getProviderForAccount(this.accountID);
ProtocolProviderService protocolProvider
ProtocolProviderService protocolProvider
= (ProtocolProviderService) this.bc.getService(serRef);
this.mainFrame.addAccount(protocolProvider);
@ -116,31 +116,31 @@ public void login(AccountManager accountManager,
*/
public void showLoginWindows(MainFrame parent) {
Set set = this.accountManagersMap.entrySet();
Set set = this.providerFactoriesMap.entrySet();
Iterator iter = set.iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
AccountManager accountManager = (AccountManager) entry.getValue();
ProtocolProviderFactory providerFactory = (ProtocolProviderFactory) entry.getValue();
String protocolName = (String) entry.getKey();
showLoginWindow(parent, protocolName, accountManager);
showLoginWindow(parent, protocolName, providerFactory);
//TEST SUPPORT FOR MORE ACCOUNTS!!!!!
//showLoginWindow(parent, protocolName, accountManager);
}
//showLoginWindow(parent, protocolName, providerFactory);
}
}
/**
* Shows the login window for the given protocol and accountManager.
* Shows the login window for the given protocol and providerFactory.
* @param parent The parent MainFrame window.
* @param protocolName The protocolName.
* @param accoundManager The AccountManager.
* @param accoundManager The ProtocolProviderFactory to use.
*/
private void showLoginWindow(MainFrame parent,
private void showLoginWindow(MainFrame parent,
String protocolName,
AccountManager accoundManager) {
ProtocolProviderFactory accoundManager) {
LoginWindow loginWindow = new LoginWindow(parent, protocolName,
accoundManager);
@ -185,11 +185,11 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) {
if (evt.getReasonCode() == RegistrationStateChangeEvent
.REASON_RECONNECTION_RATE_LIMIT_EXCEEDED) {
SIPCommMsgTextArea msgText
SIPCommMsgTextArea msgText
= new SIPCommMsgTextArea(Messages.getString(
"reconnectionLimitExceeded", protocolProvider
.getAccountID().getAccountUserID()));
JOptionPane.showMessageDialog(null, msgText, Messages
.getString("error"), JOptionPane.ERROR_MESSAGE);
} else if (evt.getReasonCode() == RegistrationStateChangeEvent
@ -197,14 +197,14 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) {
SIPCommMsgTextArea msgText = new SIPCommMsgTextArea(Messages
.getString("nonExistingUserId", protocolProvider
.getProtocolName()));
JOptionPane.showMessageDialog(null, msgText, Messages
.getString("error"), JOptionPane.ERROR_MESSAGE);
} else if (evt.getReasonCode() == RegistrationStateChangeEvent
.REASON_AUTHENTICATION_FAILED) {
SIPCommMsgTextArea msgText = new SIPCommMsgTextArea(Messages
.getString("authenticationFailed"));
JOptionPane.showMessageDialog(null, msgText, Messages
.getString("error"), JOptionPane.ERROR_MESSAGE);
}
@ -221,47 +221,47 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) {
evt.getProvider(),
Constants.OFFLINE_STATUS);
SIPCommMsgTextArea msgText
SIPCommMsgTextArea msgText
= new SIPCommMsgTextArea(
Messages.getString("connectionFailedMessage"));
JOptionPane.showMessageDialog(null, msgText, Messages
.getString("error"), JOptionPane.ERROR_MESSAGE);
} else if (evt.getNewState().equals(RegistrationState.EXPIRED)) {
SIPCommMsgTextArea msgText
SIPCommMsgTextArea msgText
= new SIPCommMsgTextArea(Messages.getString(
"connectionExpiredMessage", protocolProvider
.getProtocolName()));
JOptionPane.showMessageDialog(null, msgText,
JOptionPane.showMessageDialog(null, msgText,
Messages.getString("error"),
JOptionPane.ERROR_MESSAGE);
} else if (evt.getNewState().equals(RegistrationState.UNREGISTERED)) {
if (evt.getReasonCode() == RegistrationStateChangeEvent
.REASON_MULTIPLE_LOGINS) {
SIPCommMsgTextArea msgText
SIPCommMsgTextArea msgText
= new SIPCommMsgTextArea(Messages.getString(
"multipleLogins", protocolProvider.getAccountID()
.getAccountUserID()));
JOptionPane.showMessageDialog(null, msgText, Messages
.getString("error"), JOptionPane.ERROR_MESSAGE);
} else if (evt.getReasonCode() == RegistrationStateChangeEvent
.REASON_CLIENT_LIMIT_REACHED_FOR_IP) {
SIPCommMsgTextArea msgText
SIPCommMsgTextArea msgText
= new SIPCommMsgTextArea(Messages
.getString("limitReachedForIp", protocolProvider
.getProtocolName()));
JOptionPane.showMessageDialog(null, msgText, Messages
.getString("error"), JOptionPane.ERROR_MESSAGE);
} else {
SIPCommMsgTextArea msgText
SIPCommMsgTextArea msgText
= new SIPCommMsgTextArea(Messages.getString(
"unregisteredMessage", protocolProvider
.getProtocolName()));
JOptionPane.showMessageDialog(null, msgText, Messages
.getString("error"), JOptionPane.ERROR_MESSAGE);
}

@ -36,10 +36,10 @@
import net.java.sip.communicator.impl.gui.utils.AntialiasingManager;
import net.java.sip.communicator.impl.gui.utils.Constants;
import net.java.sip.communicator.impl.gui.utils.ImageLoader;
import net.java.sip.communicator.service.protocol.AccountManager;
import net.java.sip.communicator.service.protocol.ProtocolProviderFactory;
/**
* The LoginWindow is the window where the user should type his
* user identifier and password to login.
* user identifier and password to login.
* @author Yana Stamcheva
*/
public class LoginWindow extends JDialog implements ActionListener {
@ -66,7 +66,7 @@ public class LoginWindow extends JDialog implements ActionListener {
private LoginWindowBackground backgroundPanel = new LoginWindowBackground();
private AccountManager accountManager;
private ProtocolProviderFactory providerFactory;
private LoginManager loginManager;
@ -74,13 +74,13 @@ public class LoginWindow extends JDialog implements ActionListener {
* Creates an instance of the LoginWindow.
* @param mainFrame The parent MainFrame window.
* @param protocolName The name of the protocol.
* @param accountManager The account manager.
* @param providerFactory The provider factory.
*/
public LoginWindow(MainFrame mainFrame, String protocolName,
AccountManager accountManager) {
ProtocolProviderFactory providerFactory) {
super(mainFrame);
this.accountManager = accountManager;
this.providerFactory = providerFactory;
this.setModal(true);
@ -104,7 +104,7 @@ public LoginWindow(MainFrame mainFrame, String protocolName,
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
this.setTitle(Messages.getString("loginWindowTitle", protocolName));
this.enableKeyActions();
}
@ -112,10 +112,10 @@ public LoginWindow(MainFrame mainFrame, String protocolName,
* Constructs the LoginWindow.
*/
private void init() {
this.uinLabel.setFont(Constants.FONT.deriveFont(Font.BOLD));
this.passwdLabel.setFont(Constants.FONT.deriveFont(Font.BOLD));
this.uinComboBox = new JComboBox();
this.uinComboBox.setEditable(true);
@ -183,11 +183,11 @@ private void setWindowLocation() {
}
/**
* Returns the account manager for this login window.
* @return The account manager for this login window.
* Returns the provider factory for this login window.
* @return The provider factory for this login window.
*/
public AccountManager getAccountManager() {
return accountManager;
public ProtocolProviderFactory getProviderFactory() {
return providerFactory;
}
public void actionPerformed(ActionEvent e) {
@ -199,7 +199,7 @@ public void actionPerformed(ActionEvent e) {
this.dispose();
this.loginManager.login(accountManager, uinComboBox
this.loginManager.login(providerFactory, uinComboBox
.getSelectedItem().toString(), new String(passwdField
.getPassword()));
} else {
@ -242,7 +242,7 @@ protected void paintComponent(Graphics g) {
}
/**
* Enables the actions when a key is pressed, for now
* Enables the actions when a key is pressed, for now
* closes the window when esc is pressed.
*/
private void enableKeyActions() {

@ -16,10 +16,11 @@
* 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.
* Every instance of the <tt>ProtocolProviderService</tt>, created through the
* ProtocolProviderFactory 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

@ -22,7 +22,7 @@
* modifying contact lists, receiving calls)would pertain to this particular
* user account.
*<p>
* ProtocolProviderService instances are created through the account manager.
* ProtocolProviderService instances are created through the provider factory.
* Each protocol provider is assigned a unique AccountID instance that uniquely
* identifies it. Account id's for different accounts are guaranteed to be
* different and in the same time the ID of a particular account against a given

@ -15,7 +15,7 @@
import net.java.sip.communicator.util.Logger;
/**
* Tests basic account manager functionalitites
* Tests basic provider factory functionalitites
* @author Emil Ivov
* @author Damian Minkov
*/
@ -28,7 +28,7 @@ public class TestAccountInstallation extends TestCase
*/
private Object registrationLock = new Object();
AccountManager icqAccountManager = null;
ProtocolProviderFactory icqProviderFactory = null;
public TestAccountInstallation(String name)
{
@ -68,11 +68,11 @@ public static Test suite()
public void testRegisterWrongUsername()
{
ServiceReference[] serRefs = null;
String osgiFilter = "(" + AccountManager.PROTOCOL_PROPERTY_NAME
String osgiFilter = "(" + ProtocolProviderFactory.PROTOCOL_PROPERTY_NAME
+ "="+ProtocolNames.ICQ+")";
try{
serRefs = IcqSlickFixture.bc.getServiceReferences(
AccountManager.class.getName(), osgiFilter);
ProtocolProviderFactory.class.getName(), osgiFilter);
}
catch (InvalidSyntaxException ex){
//this really shouldhn't occur as the filter expression is static.
@ -80,12 +80,12 @@ public void testRegisterWrongUsername()
}
assertTrue(
"Failed to find an account manager service for protocol ICQ",
"Failed to find an provider factory service for protocol ICQ",
serRefs != null || serRefs.length > 0);
//Keep the reference for later usage.
AccountManager icqAccountManager =
(AccountManager)IcqSlickFixture.bc.getService(serRefs[0]);
ProtocolProviderFactory icqProviderFactory =
(ProtocolProviderFactory)IcqSlickFixture.bc.getService(serRefs[0]);
//Prepare the properties of the icq account.
@ -100,7 +100,7 @@ public void testRegisterWrongUsername()
Hashtable icqAccountProperties = new Hashtable();
icqAccountProperties.put(AccountProperties.PASSWORD, passwd);
AccountID icqAccountID = icqAccountManager.installAccount(
AccountID icqAccountID = icqProviderFactory.installAccount(
IcqSlickFixture.bc, uin, icqAccountProperties);
//find the protocol provider service
@ -111,9 +111,9 @@ public void testRegisterWrongUsername()
= IcqSlickFixture.bc.getServiceReferences(
ProtocolProviderService.class.getName(),
"(&"
+ "(" + AccountManager.PROTOCOL_PROPERTY_NAME + "=" +
+ "(" + ProtocolProviderFactory.PROTOCOL_PROPERTY_NAME + "=" +
ProtocolNames.ICQ + ")"
+ "(" + AccountManager.ACCOUNT_ID_PROPERTY_NAME + "="
+ "(" + ProtocolProviderFactory.ACCOUNT_ID_PROPERTY_NAME + "="
+ uin + ")"
+ ")");
}
@ -176,7 +176,7 @@ public void testRegisterWrongUsername()
provider.removeRegistrationStateChangeListener(regFailedEvtCollector);
icqAccountManager.uninstallAccount(icqAccountID);
icqProviderFactory.uninstallAccount(icqAccountID);
}
@ -189,11 +189,11 @@ public void testRegisterWrongUsername()
public void testRegisterWrongPassword()
{
ServiceReference[] serRefs = null;
String osgiFilter = "(" + AccountManager.PROTOCOL_PROPERTY_NAME
String osgiFilter = "(" + ProtocolProviderFactory.PROTOCOL_PROPERTY_NAME
+ "="+ProtocolNames.ICQ+")";
try{
serRefs = IcqSlickFixture.bc.getServiceReferences(
AccountManager.class.getName(), osgiFilter);
ProtocolProviderFactory.class.getName(), osgiFilter);
}
catch (InvalidSyntaxException ex){
//this really shouldhn't occur as the filter expression is static.
@ -201,12 +201,12 @@ public void testRegisterWrongPassword()
}
assertTrue(
"Failed to find an account manager service for protocol ICQ",
"Failed to find an provider factory service for protocol ICQ",
serRefs != null || serRefs.length > 0);
//Keep the reference for later usage.
AccountManager icqAccountManager =
(AccountManager)IcqSlickFixture.bc.getService(serRefs[0]);
ProtocolProviderFactory icqProviderFactory =
(ProtocolProviderFactory)IcqSlickFixture.bc.getService(serRefs[0]);
//Prepare the properties of the icq account.
@ -220,7 +220,7 @@ public void testRegisterWrongPassword()
Hashtable icqAccountProperties = new Hashtable();
icqAccountProperties.put(AccountProperties.PASSWORD, passwd);
AccountID icqAccountID = icqAccountManager.installAccount(
AccountID icqAccountID = icqProviderFactory.installAccount(
IcqSlickFixture.bc, uin, icqAccountProperties);
//find the protocol provider service
@ -231,9 +231,9 @@ public void testRegisterWrongPassword()
= IcqSlickFixture.bc.getServiceReferences(
ProtocolProviderService.class.getName(),
"(&"
+ "(" + AccountManager.PROTOCOL_PROPERTY_NAME + "=" +
+ "(" + ProtocolProviderFactory.PROTOCOL_PROPERTY_NAME + "=" +
ProtocolNames.ICQ + ")"
+ "(" + AccountManager.ACCOUNT_ID_PROPERTY_NAME + "="
+ "(" + ProtocolProviderFactory.ACCOUNT_ID_PROPERTY_NAME + "="
+ icqAccountID.getAccountUserID() + ")"
+ ")");
}
@ -295,7 +295,7 @@ public void testRegisterWrongPassword()
provider.removeRegistrationStateChangeListener(regFailedEvtCollector);
icqAccountManager.uninstallAccount(icqAccountID);
icqProviderFactory.uninstallAccount(icqAccountID);
}
/**
@ -303,13 +303,13 @@ public void testRegisterWrongPassword()
*/
public void testInstallAccount()
{
// first obtain a reference to the account manager
// first obtain a reference to the provider factory
ServiceReference[] serRefs = null;
String osgiFilter = "(" + AccountManager.PROTOCOL_PROPERTY_NAME
String osgiFilter = "(" + ProtocolProviderFactory.PROTOCOL_PROPERTY_NAME
+ "="+ProtocolNames.ICQ+")";
try{
serRefs = IcqSlickFixture.bc.getServiceReferences(
AccountManager.class.getName(), osgiFilter);
ProtocolProviderFactory.class.getName(), osgiFilter);
}
catch (InvalidSyntaxException ex){
//this really shouldhn't occur as the filter expression is static.
@ -317,17 +317,17 @@ public void testInstallAccount()
}
assertTrue(
"Failed to find an account manager service for protocol ICQ",
"Failed to find an provider factory service for protocol ICQ",
serRefs != null || serRefs.length > 0);
//Keep the reference for later usage.
icqAccountManager = (AccountManager)
icqProviderFactory = (ProtocolProviderFactory)
IcqSlickFixture.bc.getService(serRefs[0]);
//make sure the account is empty
assertTrue("There was an account registered with the account mananger "
+"before we've installed any",
icqAccountManager.getRegisteredAccounts().size() == 0);
icqProviderFactory.getRegisteredAccounts().size() == 0);
//Prepare the properties of the icq account.
@ -356,7 +356,7 @@ public void testInstallAccount()
//try to install an account with a null bundle context
try{
icqAccountManager.installAccount( null, uin, icqAccountProperties);
icqProviderFactory.installAccount( null, uin, icqAccountProperties);
fail("installing an account with a null BundleContext must result "
+"in a NullPointerException");
}catch(NullPointerException exc){
@ -365,7 +365,7 @@ public void testInstallAccount()
//try to install an account with a null account id
try{
icqAccountManager.installAccount(
icqProviderFactory.installAccount(
IcqSlickFixture.bc, null, icqAccountProperties);
fail("installing an account with a null account id must result "
+"in a NullPointerException");
@ -374,13 +374,13 @@ public void testInstallAccount()
}
//now really install the account
IcqSlickFixture.icqAccountID = icqAccountManager.installAccount(
IcqSlickFixture.icqAccountID = icqProviderFactory.installAccount(
IcqSlickFixture.bc, uin, icqAccountProperties);
//try to install the account one more time and verify that an excepion
//is thrown.
try{
IcqSlickFixture.icqAccountID = icqAccountManager.installAccount(
IcqSlickFixture.icqAccountID = icqProviderFactory.installAccount(
IcqSlickFixture.bc, uin, icqAccountProperties);
fail("An IllegalStateException must be thrown when trying to "+
"install a duplicate account");
@ -390,18 +390,18 @@ public void testInstallAccount()
//that's what supposed to happen.
}
//Verify that the account manager is aware of our installation
//Verify that the provider factory is aware of our installation
assertTrue(
"The newly installed account was not in the acc man's "
+"registered accounts!",
icqAccountManager.getRegisteredAccounts().size() == 1);
icqProviderFactory.getRegisteredAccounts().size() == 1);
//Verify that the protocol provider corresponding to the new account has
//been properly registered with the osgi framework.
osgiFilter =
"(&("+AccountManager.PROTOCOL_PROPERTY_NAME +"="+ProtocolNames.ICQ+")"
+"(" + AccountManager.ACCOUNT_ID_PROPERTY_NAME
"(&("+ProtocolProviderFactory.PROTOCOL_PROPERTY_NAME +"="+ProtocolNames.ICQ+")"
+"(" + ProtocolProviderFactory.ACCOUNT_ID_PROPERTY_NAME
+ "=" + IcqSlickFixture.icqAccountID.getAccountUserID() + "))";
try

@ -147,8 +147,8 @@ public void testUninstallAccount()
icqProviderRefs = fixture.bc.getServiceReferences(
ProtocolProviderService.class.getName(),
"(&"
+ "(" + AccountManager.PROTOCOL_PROPERTY_NAME + "=" +ProtocolNames.ICQ + ")"
+ "(" + AccountManager.ACCOUNT_ID_PROPERTY_NAME + "="+ fixture.icqAccountID + ")"
+ "(" + ProtocolProviderFactory.PROTOCOL_PROPERTY_NAME + "=" +ProtocolNames.ICQ + ")"
+ "(" + ProtocolProviderFactory.ACCOUNT_ID_PROPERTY_NAME + "="+ fixture.icqAccountID + ")"
+ ")");
}
catch (InvalidSyntaxException ex)
@ -164,11 +164,11 @@ public void testUninstallAccount()
//verify that the provider knows that we have uninstalled the service.
assertTrue(
"The ICQ account manager kept a reference to the provider we just "
+"uninstalled (accID="+fixture.icqAccountID+")",
fixture.accManager.getRegisteredAccounts().isEmpty()
&& fixture.accManager.getProviderForAccount(fixture.icqAccountID) == null
);
"The ICQ provider factory kept a reference to the provider we just "
+"uninstalled (accID="+fixture.icqAccountID+")",
fixture.accManager.getRegisteredAccounts().isEmpty()
&& fixture.accManager.getProviderForAccount(fixture.icqAccountID)
== null);
}
/**

Loading…
Cancel
Save