Refactoring

cusax-fix
Emil Ivov 20 years ago
parent 795ee34240
commit 0df2d5ee19

@ -85,12 +85,30 @@ public ServiceReference getProviderForAccount(AccountID accountID)
public AccountID installAccount( String userIDStr,
Map accountProperties)
{
AccountID accountID = loadAccount(userIDStr, accountProperties);
BundleContext context
= IcqActivator.getBundleContext();
if (context == null)
throw new NullPointerException("The specified BundleContext was null");
if (userIDStr == null)
throw new NullPointerException("The specified AccountID was null");
if (accountProperties == null)
throw new NullPointerException("The specified property map was null");
AccountID accountID = new IcqAccountID(userIDStr, accountProperties);
//first store the account and only then load it as the load generates
//an osgi event, the osgi event triggers (trhgough the UI) a call to
//the register() method and it needs to acces the configuration service
//and check for a password.
this.storeAccount(
IcqActivator.getBundleContext()
, accountID
, implementationPackageName);
accountID = loadAccount(userIDStr, accountProperties);
return accountID;
}
@ -112,12 +130,6 @@ public AccountID loadAccount( String userIDStr,
if(context == null)
throw new NullPointerException("The specified BundleContext was null");
if(userIDStr == null)
throw new NullPointerException("The specified AccountID was null");
if(accountProperties == null)
throw new NullPointerException("The specified property map was null");
AccountID accountID = new IcqAccountID(userIDStr, accountProperties);
//make sure we haven't seen this account id before.
@ -135,7 +147,7 @@ public AccountID loadAccount( String userIDStr,
ProtocolProviderServiceIcqImpl icqProtocolProvider
= new ProtocolProviderServiceIcqImpl();
icqProtocolProvider.initialize(userIDStr, accountProperties, accountID);
icqProtocolProvider.initialize(userIDStr, accountID);
ServiceRegistration registration
= context.registerService( ProtocolProviderService.class.getName(),

@ -62,6 +62,10 @@ public class ProtocolProviderServiceIcqImpl
* indicates whether or not the provider is initialized and ready for use.
*/
private boolean isInitialized = false;
/**
* We use this to lock access to initialization.
*/
private Object initializationLock = new Object();
/**
@ -163,6 +167,11 @@ else if (joustSimConnState == State.FAILED)
*/
public void register(SecurityAuthority authority)
{
if(authority == null)
throw new IllegalArgumentException(
"The register method needs a valid non-null authority impl "
+ " in order to be able and retrieve passwords.");
synchronized(initializationLock)
{
String accountPrefix
@ -182,7 +191,25 @@ public void register(SecurityAuthority authority)
}
else
{
//authority.getNewPasswor();
//create a default credentials object
UserCredentials credentials = new UserCredentials();
credentials.setUserName(this.getAccountID().getUserID());
//request a password from the user
credentials = authority.obtainCredentials(ProtocolNames.ICQ
, credentials);
//extract the password the user passed us.
password = new String(credentials.getPassword());
if (credentials.isPasswordPersistent())
{
//verify whether a password has already been stored for this account
IcqActivator.getConfigurationService().setProperty(
accountPrefix + "."
+ ProtocolProviderFactory.PASSWORD
, new String(Base64.encode(password.getBytes())) );
}
}
//init the necessary objects
@ -252,15 +279,12 @@ public Map getSupportedOperationSets()
*
* @param screenname the account id/uin/screenname of the account that we're
* about to create
* @param initializationProperties all properties needed fo initializing the
* account.
* @param accountID the identifier of the account that this protocol
* provider represents.
*
* @see net.java.sip.communicator.service.protocol.AccountID
*/
protected void initialize(String screenname,
Map initializationProperties,
AccountID accountID)
{
synchronized(initializationLock)
@ -471,7 +495,7 @@ private void fireRegistrationStateChanged( RegistrationState oldState,
{
RegistrationStateChangeEvent event =
new RegistrationStateChangeEvent(
this, newState, newState, reasonCode, reason);
this, oldState, newState, reasonCode, reason);
logger.debug("Dispatching " + event + " to "
+ registrationListeners.size()+ " listeners.");
@ -525,7 +549,8 @@ public void handleStateChange(StateEvent event)
conn.getInfoService().
getOscarConnection().getSnacProcessor().
getFlapProcessor().addPacketListener(new ConnectionClosedListener(conn));
getFlapProcessor().addPacketListener(
new ConnectionClosedListener(conn));
}
else if (newState == State.DISCONNECTED)
{
@ -535,10 +560,15 @@ else if (newState == State.DISCONNECTED)
Service service = aimConnection.getBosService();
if(service != null)
{
int discconectCode = service.getOscarConnection().getLastCloseCode();
reasonCode = ConnectionClosedListener.convertCodeToRegistrationStateChangeEvent(discconectCode);
reasonStr = ConnectionClosedListener.convertCodeToStringReason(discconectCode);
logger.debug("The aim Connection was disconnected! with reason : " + reasonStr);
int discconectCode = service.getOscarConnection()
.getLastCloseCode();
reasonCode = ConnectionClosedListener
.convertCodeToRegistrationStateChangeEvent(
discconectCode);
reasonStr = ConnectionClosedListener
.convertCodeToStringReason(discconectCode);
logger.debug("The aim Connection was disconnected! with reason : "
+ reasonStr);
}
else
logger.debug("The aim Connection was disconnected!");
@ -546,9 +576,13 @@ else if (newState == State.DISCONNECTED)
else
if(newState == State.FAILED)
{
logger.debug("The aim Connection failed! " + event.getNewStateInfo());
logger.debug("The aim Connection failed! "
+ event.getNewStateInfo());
}
//as a side note - if this was an AuthenticationFailed error
//set the stored password to null so that we don't use it any more.
//now tell all interested parties about what happened.
fireRegistrationStateChanged(oldState, event.getOldStateInfo()
, newState, event.getNewStateInfo()

Loading…
Cancel
Save