diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java
index aa48bfc0f..61857f509 100644
--- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java
@@ -452,31 +452,22 @@ public void sendInstantMessage(Contact to, Message message)
/**
* Utility method throwing an exception if the stack is not properly
* initialized.
+ *
* @throws java.lang.IllegalStateException if the underlying stack is
* not registered and initialized.
*/
- private void assertConnected() throws IllegalStateException
+ private void assertConnected()
+ throws IllegalStateException
{
- if (jabberProvider == null)
- throw new IllegalStateException(
- "The provider must be non-null and signed on the "
- +"service before being able to communicate.");
- if (!jabberProvider.isRegistered())
+ if (opSetPersPresence == null)
{
- // if we are not registered but the current status is online
- // change the current status
- if(opSetPersPresence.getPresenceStatus().isOnline())
- {
- opSetPersPresence.fireProviderStatusChangeEvent(
- opSetPersPresence.getPresenceStatus(),
- jabberProvider.getJabberStatusEnum().getStatus(
- JabberStatusEnum.OFFLINE));
- }
-
- throw new IllegalStateException(
- "The provider must be signed on the service before "
- +"being able to communicate.");
+ throw
+ new IllegalStateException(
+ "The provider must be signed on the service before"
+ + " being able to communicate.");
}
+ else
+ opSetPersPresence.assertConnected();
}
/**
@@ -501,9 +492,10 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt)
if (evt.getNewState() == RegistrationState.REGISTERING)
{
- opSetPersPresence =
- (OperationSetPersistentPresenceJabberImpl) jabberProvider
- .getOperationSet(OperationSetPersistentPresence.class);
+ opSetPersPresence
+ = (OperationSetPersistentPresenceJabberImpl)
+ jabberProvider.getOperationSet(
+ OperationSetPersistentPresence.class);
if(smackMessageListener == null)
smackMessageListener = new SmackMessageListener();
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java
index a91917981..1d1eec303 100644
--- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java
@@ -391,32 +391,53 @@ public void publishPresenceStatus(PresenceStatus status,
}
/**
- * Get the PresenceStatus for a particular contact.
+ * Gets the PresenceStatus of a contact with a specific
+ * String identifier.
*
- * @param contactIdentifier the identifier of the contact whose status
- * we're interested in.
- * @return PresenceStatus the PresenceStatus of the specified
- * contact
- * @throws IllegalArgumentException if contact is not a contact
- * known to the underlying protocol provider
- * @throws IllegalStateException if the underlying protocol provider is
- * not registered/signed on a public service.
- * @throws OperationFailedException with code NETWORK_FAILURE if
- * retrieving the status fails due to errors experienced during
- * network communication
+ * @param contactIdentifier the identifier of the contact whose status we're
+ * interested in.
+ * @return the PresenceStatus of the contact with the specified
+ * contactIdentifier
+ * @throws IllegalArgumentException if the specified
+ * contactIdentifier does not identify a contact known to the
+ * underlying protocol provider
+ * @throws IllegalStateException if the underlying protocol provider is not
+ * registered/signed on a public service
+ * @throws OperationFailedException with code NETWORK_FAILURE if retrieving
+ * the status fails due to errors experienced during network communication
*/
- public PresenceStatus queryContactStatus(String contactIdentifier) throws
- IllegalArgumentException, IllegalStateException,
- OperationFailedException
+ public PresenceStatus queryContactStatus(String contactIdentifier)
+ throws IllegalArgumentException,
+ IllegalStateException,
+ OperationFailedException
{
- Presence presence = parentProvider.getConnection().getRoster().
- getPresence(contactIdentifier);
+ /*
+ * As stated by the javadoc, IllegalStateException signals that the
+ * ProtocolProviderService is not registered.
+ */
+ assertConnected();
+
+ XMPPConnection xmppConnection = parentProvider.getConnection();
+
+ if (xmppConnection == null)
+ {
+ throw
+ new IllegalArgumentException(
+ "The provider/account must be signed on in order to"
+ + " query the status of a contact in its roster");
+ }
+
+ Presence presence
+ = xmppConnection.getRoster().getPresence(contactIdentifier);
if(presence != null)
return jabberStatusToPresenceStatus(presence, parentProvider);
else
- return parentProvider.getJabberStatusEnum().getStatus(
- JabberStatusEnum.OFFLINE);
+ {
+ return
+ parentProvider.getJabberStatusEnum().getStatus(
+ JabberStatusEnum.OFFLINE);
+ }
}
/**
@@ -633,30 +654,37 @@ public static Presence.Mode presenceStatusToJabberMode(PresenceStatus status)
/**
* Utility method throwing an exception if the stack is not properly
* initialized.
- * @throws java.lang.IllegalStateException if the underlying stack is
- * not registered and initialized.
+ *
+ * @throws IllegalStateException if the underlying stack is not registered
+ * and initialized.
*/
- private void assertConnected() throws IllegalStateException
+ void assertConnected()
+ throws IllegalStateException
{
if (parentProvider == null)
- throw new IllegalStateException(
- "The provider must be non-null and signed on the Jabber "
- +"service before being able to communicate.");
+ {
+ throw
+ new IllegalStateException(
+ "The provider must be non-null and signed on the"
+ + " Jabber service before being able to"
+ + " communicate.");
+ }
if (!parentProvider.isRegistered())
{
// if we are not registered but the current status is online
// change the current status
- if(currentStatus.isOnline())
+ if((currentStatus != null) && currentStatus.isOnline())
{
fireProviderStatusChangeEvent(
currentStatus,
parentProvider.getJabberStatusEnum().getStatus(
- JabberStatusEnum.OFFLINE));
+ JabberStatusEnum.OFFLINE));
}
- throw new IllegalStateException(
- "The provider must be signed on the Jabber service before "
- +"being able to communicate.");
+ throw
+ new IllegalStateException(
+ "The provider must be signed on the Jabber service"
+ + " before being able to communicate.");
}
}
diff --git a/src/net/java/sip/communicator/service/protocol/AbstractProtocolProviderService.java b/src/net/java/sip/communicator/service/protocol/AbstractProtocolProviderService.java
index fd5917964..8d7ba3f4c 100644
--- a/src/net/java/sip/communicator/service/protocol/AbstractProtocolProviderService.java
+++ b/src/net/java/sip/communicator/service/protocol/AbstractProtocolProviderService.java
@@ -214,8 +214,8 @@ public Map getSupportedOperationSets()
/**
* Indicates whether or not this provider is registered
*
- * @return true if the provider is currently registered and false
- * otherwise.
+ * @return true if the provider is currently registered and
+ * false otherwise.
*/
public boolean isRegistered()
{