/**
  * Returns the number of offline messages for the user of the connection.
  *
  * @return the number of offline messages for the user of the connection.
  * @throws XMPPException If the user is not allowed to make this request or the server does not
  *     support offline message retrieval.
  */
 public int getMessageCount() throws XMPPException {
   DiscoverInfo info =
       ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(null, namespace);
   Form extendedInfo = Form.getFormFrom(info);
   if (extendedInfo != null) {
     String value = (String) extendedInfo.getField("number_of_messages").getValues().next();
     return Integer.parseInt(value);
   }
   return 0;
 }