private void unregister(IQ request, JID actorJID, boolean isRemote) throws Exception {
    LOGGER.debug("Processing unregister request from " + request.getFrom());

    if (!validateSingleChildElement(request)) {
      failBadRequest(request);
      return;
    }
    if (!isRemote && !userRegistered(actorJID)) {
      failRegistrationRequired(request);
      return;
    }

    Transaction t = null;
    try {
      t = channelManager.beginTransaction();

      List<Packet> notifications = new LinkedList<Packet>();
      Set<String> remoteDomains = getRemoteDomains();

      ResultSet<NodeMembership> userMemberships = channelManager.getUserMemberships(actorJID);
      for (NodeMembership userMembership : userMemberships) {
        String nodeId = userMembership.getNodeId();
        if (isPersonal(nodeId) || isSingleOwner(nodeId, actorJID)) {
          channelManager.deleteNode(nodeId);
          if (Configuration.getInstance().isLocalNode(nodeId)) {
            addDeleteNodeNotifications(nodeId, notifications);
          }
        }
        if (!isRemote) {
          addUnsubscribeFromNodeNotifications(actorJID, userMembership.getNodeId(), notifications);
        }
      }

      ResultSet<NodeItem> userItems = channelManager.getUserPublishedItems(actorJID);
      for (NodeItem userItem : userItems) {
        if (Configuration.getInstance().isLocalNode(userItem.getNodeId())) {
          addDeleteItemNotifications(userItem.getNodeId(), userItem.getId(), notifications);
        }
      }

      channelManager.deleteUserItems(actorJID);
      channelManager.deleteUserSubscriptions(actorJID);
      channelManager.deleteUserAffiliations(actorJID);

      outQueue.put(IQ.createResultIQ(request));
      if (!isRemote) {
        makeRemoteRequests(request, remoteDomains);
      }
      sendNotifications(notifications);

      t.commit();
    } finally {
      if (t != null) {
        t.close();
      }
    }
  }
 private Set<String> getRemoteDomains() throws NodeStoreException {
   ArrayList<String> nodeList = channelManager.getNodeList();
   Set<String> remoteDomains = new HashSet<String>();
   for (String node : nodeList) {
     try {
       if (!Configuration.getInstance().isLocalNode(node)) {
         remoteDomains.add(new JID(node.split("/")[2]).getDomain());
       }
     } catch (IllegalArgumentException e) {
       // Ignore bad formatted nodes
     }
   }
   return remoteDomains;
 }
 private void addDeleteNodeNotifications(String node, List<Packet> notifications)
     throws Exception {
   ResultSet<NodeSubscription> subscriptions = channelManager.getNodeSubscriptionListeners(node);
   Message notification = createNodeDeletedNotificationMessage(node);
   if (subscriptions != null) {
     for (NodeSubscription subscription : subscriptions) {
       notification.setTo(subscription.getListener().toString());
       notifications.add(notification.createCopy());
     }
   }
   Collection<JID> adminUsers = Configuration.getInstance().getAdminUsers();
   for (JID admin : adminUsers) {
     notification.setTo(admin);
     notifications.add(notification.createCopy());
   }
 }
  private void addDeleteItemNotifications(String node, String itemId, List<Packet> notifications)
      throws NodeStoreException {
    ResultSet<NodeSubscription> subscriptions = channelManager.getNodeSubscriptionListeners(node);
    Message notification = createItemDeleteNotificationMessage(node, itemId);
    if (subscriptions != null) {
      for (NodeSubscription subscription : subscriptions) {
        if (subscription.getSubscription().equals(Subscriptions.subscribed)) {
          notification.setTo(subscription.getListener().toString());
          notifications.add(notification);
        }
      }
    }

    Collection<JID> adminUsers = Configuration.getInstance().getAdminUsers();
    for (JID admin : adminUsers) {
      notification.setTo(admin);
      notifications.add(notification);
    }
  }
  private void addUnsubscribeFromNodeNotifications(
      JID userJid, String node, List<Packet> notifications) throws NodeStoreException {

    ResultSet<NodeSubscription> subscribers = channelManager.getNodeSubscriptionListeners(node);

    Message messagePacket = createUnsubscribeNotification(userJid, node);
    if (subscribers != null) {
      for (NodeSubscription subscriber : subscribers) {
        Message notification = messagePacket.createCopy();
        notification.setTo(subscriber.getListener());
        notifications.add(notification);
      }
    }

    Collection<JID> adminUsers = Configuration.getInstance().getAdminUsers();
    for (JID admin : adminUsers) {
      Message notification = messagePacket.createCopy();
      notification.setTo(admin);
      notifications.add(notification);
    }
  }
 protected String getTopicsDomain() {
   if (null == topicsDomain) {
     topicsDomain = Configuration.getInstance().getProperty("server.domain.topics");
   }
   return topicsDomain;
 }
 protected Collection<JID> getAdminUsers() {
   if (null == adminUsers) {
     adminUsers = Configuration.getInstance().getAdminUsers();
   }
   return adminUsers;
 }
 protected String getServerDomain() {
   if (null == serverDomain) {
     serverDomain = Configuration.getInstance().getProperty("server.domain");
   }
   return serverDomain;
 }