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.Jid;

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

  32.     private Jid user;

  33.     private DepartQueuePacket() {
  34.         super("depart-queue", "http://jabber.org/protocol/workgroup");
  35.     }

  36.     /**
  37.      * Creates a depart queue request packet to the specified workgroup.
  38.      *
  39.      * @param workgroup the workgroup to depart.
  40.      */
  41.     public DepartQueuePacket(Jid workgroup) {
  42.         this(workgroup, null);
  43.     }

  44.     /**
  45.      * Creates a depart queue request to the specified workgroup and for the
  46.      * specified user.
  47.      *
  48.      * @param workgroup the workgroup to depart.
  49.      * @param user the user to make depart from the queue.
  50.      */
  51.     public DepartQueuePacket(Jid workgroup, Jid user) {
  52.         this();
  53.         this.user = user;

  54.         setTo(workgroup);
  55.         setType(IQ.Type.set);
  56.         setFrom(user);
  57.     }

  58.     @Override
  59.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
  60.         buf.rightAngleBracket();

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

  64.         return buf;
  65.     }
  66. }