Added reason code and string to status change events

cusax-fix
Emil Ivov 20 years ago
parent 2320eb38ee
commit 8f9f7b0859

@ -65,6 +65,11 @@ public class ProtocolProviderServiceIcqImpl
*/
private List registrationListeners = new ArrayList();
/**
* The identifier of the account that this provider represents.
*/
private AccountID accountID = null;
/**
* Returns the state of the registration of this protocol provider
* @return the <tt>RegistrationState</tt> that this provider is
@ -204,13 +209,18 @@ public Map getSupportedOperationSets()
* 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.AccountProperties
* @see net.java.sip.communicator.service.protocol.AccountID
*/
protected void initialize(String screenname, Map initializationProperties)
protected void initialize(String screenname,
Map initializationProperties,
AccountID accountID)
{
synchronized(initializationLock)
{
this.accountID = accountID;
//extract the necessary properties and validate them
String password =
(String)initializationProperties.get(AccountProperties.PASSWORD);
@ -315,6 +325,16 @@ public void addRegistrationStateChangeListener(RegistrationStateChangeListener l
registrationListeners.add(listener);
}
/**
* Returns the AccountID that uniquely identifies the account represented by
* this instance of the ProtocolProviderService.
* @return the id of the account represented by this provider.
*/
public AccountID getAccountID()
{
return accountID;
}
/**
* Creates a RegistrationStateChange event corresponding to the specified
* old and new joust sim states and notifies all currently registered
@ -328,11 +348,18 @@ public void addRegistrationStateChangeListener(RegistrationStateChangeListener l
* connection is currently in.
* @param newJoustSimStateInfo the state info associated with the state of
* the underlying connection state as it was before the change.
* @param reasonCode a value corresponding to one of the REASON_XXX fields
* of the RegistrationStateChangeEvent class, indicating the reason for this
* state transition.
* @param reason a String further explaining the reason code or null if
* no such explanation is necessary.
*/
private void fireRegistrationStateChanged( State oldJoustSimState,
StateInfo oldJoustSimStateInfo,
State newJoustSimState,
StateInfo newJoustSimStateInfo)
StateInfo newJoustSimStateInfo,
int reasonCode,
String reason)
{
RegistrationState oldRegistrationState
= joustSimStateToRegistrationState(oldJoustSimState
@ -342,8 +369,8 @@ private void fireRegistrationStateChanged( State oldJoustSimState,
, newJoustSimStateInfo);
RegistrationStateChangeEvent event =
new RegistrationStateChangeEvent(
this, oldRegistrationState, newRegistrationState);
new RegistrationStateChangeEvent( this, oldRegistrationState
, newRegistrationState, reasonCode, reason);
logger.debug("Dispatching " + event + " to "
+ registrationListeners.size()+ " listeners.");
@ -378,12 +405,14 @@ public void handleStateChange(StateEvent event)
if (newState == State.ONLINE)
{
icbmService = conn.getIcbmService();
icbmService.addIcbmListener(aimIcbmListener);
conn.getInfoService().
getOscarConnection().getSnacProcessor().
getCmdFactoryMgr().getDefaultFactoryList().
registerAll(new DefaultCmdFactory());
icbmService.addIcbmListener(aimIcbmListener);
//set our own cmd factory as we'd like some extra control on
//outgoing commands.
conn.getInfoService().
getOscarConnection().getSnacProcessor().
getCmdFactoryMgr().getDefaultFactoryList().
registerAll(new DefaultCmdFactory());
}
else if (newState == State.DISCONNECTED
|| newState == State.FAILED)
@ -393,7 +422,8 @@ else if (newState == State.DISCONNECTED
//now tell all interested parties about what happened.
fireRegistrationStateChanged(oldState, event.getOldStateInfo()
, newState, event.getNewStateInfo());
, newState, event.getNewStateInfo()
, RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, null);
}
}

@ -12,24 +12,93 @@
/**
* Instances of this class represent a change in the status of the provider
* that triggerred them.
* that triggerred them. A status change may have occurred because the user
* requested it or because an error or a failure have occurred, in which case
* the reason and reason code would be set accordingly.
* <p>
* Keep in mind that reasons are not localized and services such as the user
* interface should only show them in a "details box". In the rest of the time,
* such services should consult the error code and provide corresponding,
* localized, reason phrases.
* <p>
* Note, that we have tried to provide a maximum number of error codes in order
* to enumerate all possible reason codes that may be returned from servers
* in the various protocols. Each protocol would only return a subset of these.
* <p>
* @author Emil Ivov
*/
public class RegistrationStateChangeEvent extends PropertyChangeEvent
{
/**
* Indicates that no reason is specified for this event transition.
*/
public static final int REASON_NOT_SPECIFIED = -1;
/**
* Indicates that the server has refused registration du to a problem with
* the authentication (most probably a wrong password).
*/
public static final int REASON_AUTHENTICATION_FAILED = 1;
/**
* Indicates that the same user identifier has logged somewhere else. This
* code is often returned when transitting into disconnected state. Some
* protocols, however, support multiple logins and servers would only return
* this code for purely informational reasons.
*/
public static final int REASON_MULTIPLE_LOGINS = 2;
/**
* Indicates that the server does not recognize the used idenfitier that
* we tried to register with.
*/
public static final int REASON_NON_EXISTING_USER_ID = 3;
/**
* Indicates that we have too many existing registrations from the local
* IP address and the server won't allow us to open any more of them.
*/
public static final int REASON_CLIENT_LIMIT_REACHED_FOR_IP = 4;
/**
* Indicates that we have been disconnecting and reconnecting to the server
* at a rate that ha become too fast. We're temporarily banned and would
* have to wait a bit before trying again. It is often a good idea for the
* user interface to prevent the user from actually trying again for a
* certain amount of time.
*/
public static final int REASON_RECONNECTION_RATE_LIMIT_EXCEEDED = 5;
/**
* Creates an event instance indicating a change of the property
* specified by <tt>eventType</tt> from <tt>oldValue</tt> to
* <tt>newValue</tt>.
* The reason code returned by the server in order to explain the state
* transition.
*/
private int reasonCode = REASON_NOT_SPECIFIED;
/**
* A (non localized) String containing information further explaining the
* reason code.
*/
private String reason = null;
/**
* Creates an event instance indicating a change of the provider state
* from <tt>oldValue</tt> to <tt>newValue</tt>.
*
* @param source the provider that generated the event
* @param oldValue the status the source provider was int before enetering
* the new state.
* @param newValue the status the source provider is currently in.
* @param reasonCode a value corresponding to one of the REASON_XXX fields
* of this class, indicating the reason for this state transition.
* @param reason a String further explaining the reason code or null if
* no such explanation is necessary.
*/
public RegistrationStateChangeEvent( ProtocolProviderService source,
RegistrationState oldValue,
RegistrationState newValue)
RegistrationState newValue,
int reasonCode,
String reason)
{
super(source,
RegistrationStateChangeEvent.class.getName(),
@ -78,4 +147,34 @@ public String toString()
+ getOldState().getStateName()
+ "; newState="+ getNewState()+"]";
}
/**
* One of the REASON_XXX fields, indicating the reason code returned by the
* server in order to explain the state transition.
*
* @return a value corresponding toone of the REASON_XXX fields of this
* class.
*/
public int getReasonCode()
{
return reasonCode;
}
/**
* Returns a (non localized) String containing information further
* explaining the reason code, or null if no particular reason has been
* specified.
*
* Keep in mind that reason String-s returned by this method are not
* localized and services such as the user interface should only show them
* in a "details box". In the rest of the time, such services should consult
* the error code and provide corresponding, localized, reason phrases.
*
* @return a non localized String explaining the reason fo the state
* transition.
*/
public String getReason()
{
return reason;
}
}

Loading…
Cancel
Save