DepartQueuePacket.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.workgroup.packet;

  18. import org.jivesoftware.smack.packet.IQ;

  19. import org.jxmpp.jid.EntityBareJid;
  20. import org.jxmpp.jid.EntityJid;

  21. /**
  22.  * A IQ stanza used to depart a workgroup queue. There are two cases for issuing a depart
  23.  * queue request:<ul>
  24.  *     <li>The user wants to leave the queue. In this case, an instance of this class
  25.  *         should be created without passing in a user address.
  26.  *     <li>An administrator or the server removes wants to remove a user from the queue.
  27.  *         In that case, the address of the user to remove from the queue should be
  28.  *         used to create an instance of this class.</ul>
  29.  *
  30.  * @author loki der quaeler
  31.  */
  32. public class DepartQueuePacket extends IQ {

  33.     private final EntityJid user;

  34.     /**
  35.      * Creates a depart queue request stanza to the specified workgroup.
  36.      *
  37.      * @param workgroup the workgroup to depart.
  38.      */
  39.     public DepartQueuePacket(EntityBareJid workgroup) {
  40.         this(workgroup, null);
  41.     }

  42.     /**
  43.      * Creates a depart queue request to the specified workgroup and for the
  44.      * specified user.
  45.      *
  46.      * @param workgroup the workgroup to depart.
  47.      * @param user the user to make depart from the queue.
  48.      */
  49.     public DepartQueuePacket(EntityBareJid workgroup, EntityJid user) {
  50.         super("depart-queue", "http://jabber.org/protocol/workgroup");
  51.         this.user = user;

  52.         setTo(workgroup);
  53.         setType(IQ.Type.set);
  54.         setFrom(user);
  55.     }

  56.     @Override
  57.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
  58.         buf.rightAngleBracket();

  59.         if (this.user != null) {
  60.             buf.append("<jid>").append(this.user).append("</jid>");
  61.         }

  62.         return buf;
  63.     }
  64. }