public void signOut() {
    try {
      sipRC.register(this.getLocalURI(), true);
    } catch (Exception e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    Element[] elms = new Element[3];

    elms[0] = new Element(MessageCons.IM_TYPE, MessageCons.GATEWAY, Message.JXTA_NAME_SPACE);
    elms[1] = new Element(MessageCons.FROM_HEADER, this.getLocalURI(), Message.JXTA_NAME_SPACE);
    elms[2] =
        new Element(
            MessageCons.IM_STATUS,
            Integer.toString(MessageCons.IM_STATUS_OFFLINE),
            Message.JXTA_NAME_SPACE);

    try {
      groupsvc.send(impipe, new Message(elms));
    } catch (IOException e) {
      e.printStackTrace();
      //            LOG.error("could not subscribe, no other IM running");
      //            throw new IMException("could not subscribe, no other IM running");
    }
  }
  public void signIn() {
    try {
      sipRC.register(this.getLocalURI(), false);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    sendGatewayMessage();
  }
  public void handleMessage(Message message, String arg) {
    logger.debug("got message:" + message.toXMLString());

    String fromaddress = new String(message.getElement(MessageCons.FROM_HEADER).getData());

    String type = new String(message.getElement(MessageCons.IM_TYPE).getData());

    // IM_TYPE_MSG
    if (type.equals(MessageCons.MESSAGE))
    //                (addressto.equals(sipaddress) || address.equals("any")))
    {

      String toaddress = new String(message.getElement(MessageCons.TO_HEADER).getData());
      String msg = new String(message.getElement(MessageCons.MESSAGE_VALUE).getData());

      if (!registeredUserList.hasUser(toaddress)) {
        try {
          sipMC.sendMessage("sip:" + fromaddress, "sip:" + toaddress, msg);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      //            if (toaddress.equals(sipaddress) ||
      //            if (toaddress.equals(MessageCons.SIP_ADDRESS_ANY))
      //            {
      //                String msg = new
      // String(message.getElement(MessageCons.MESSAGE_VALUE).getData());
      //                imlistener.process(fromaddress, msg);
      //            }
    }
    // IM_TYPE_REG
    else if (type.equals(MessageCons.REGISTER)) {
      int status =
          Integer.parseInt(new String(message.getElement(MessageCons.IM_STATUS).getData()));
      Element element = message.getElement(MessageCons.PASSWORD);
      String password = null;
      if (element != null) {
        password = new String(element.getData());
      } else {
        logger.error("PLEASE PROVIDE A PASSWORD !");
      }
      String username = fromaddress.substring(0, fromaddress.indexOf("@"));
      String realm = fromaddress.substring(fromaddress.indexOf("@") + 1);

      logger.debug("Adding user to registereduser list: " + fromaddress);
      RegisteredUser user =
          new RegisteredUser(
              username,
              realm,
              password,
              new AuthenticationProcess(this, username, realm, password));
      registeredUserList.addUser(user);

      try {
        sipRC.register("sip:" + fromaddress, false);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      sendGatewayMessage();

      //            try{
      //                processMessage(fromaddress,"sip:gw@localhost","test");
      //            }
      //            catch (IMException e) {
      //            	e.printStackTrace();
      //            }
      //            NeighbourTuple ntuple = new NeighbourTuple(fromaddress, status);
      //            neighbours.put(fromaddress,ntuple);
      //
      //            imlistener.imRegistered(fromaddress, status);
    }
    // IM_TYPE_UNREG
    else if (type.equals(MessageCons.BYE)) {
      //            imlistener.imUnregistered(fromaddress);
      //
      //            neighbours.remove(fromaddress);
    }
    // IM_TYPE_NACK
    //        else if (type.equals(IM_TYPE_ALIVE))
    //        {
    //            int status = Integer.parseInt(new
    // String(message.getElement(IM_STATUS).getData()));
    //
    //            if (!neighbours.containsKey(fromaddress))
    //            {
    //                NeighbourTuple ntuple = new NeighbourTuple(fromaddress,status);
    //                neighbours.put(fromaddress, ntuple);
    //            }
    //        }
    // not known...
    else if (type.equals(MessageCons.PUBLISH)) {
      if (registeredUserList.hasUser(fromaddress)) {
        String status = new String(message.getElement(MessageCons.IM_STATUS).getData());

        sipPC.sendPublish("sip:" + fromaddress, status);
      }
    } else logger.debug("message type not known: " + type);
  }