code: public String getReservedNickname() throws SmackException, InterruptedException {
          try {
              DiscoverInfo result =
                  ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(
                      room,
                      "x-roomuser-item");
              // Look for an Identity that holds the reserved nickname and return its name
              for (DiscoverInfo.Identity identity : result.getIdentities()) {
                  return identity.getName();
              }
          }
          catch (XMPPException e) {
              LOGGER.log(Level.SEVERE, "Error retrieving room nickname", e);
          }
          // If no Identity was found then the user does not have a reserved room nickname
          return null;
      }
docs: Returns the reserved room nickname for the user in the room. A user may have a reserved
  nickname, for example through explicit room registration or database integration. In such
  cases it may be desirable for the user to discover the reserved nickname before attempting
  to enter the room.
  
  @return the reserved room nickname or <tt>null</tt> if none.
  @throws SmackException if there was no response from the server.
  @throws InterruptedException