001/**
002 *
003 * Copyright 2003-2007 Jive Software.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.jivesoftware.smackx.workgroup.packet;
019
020import org.jivesoftware.smack.packet.IQ;
021
022import org.jxmpp.jid.Jid;
023
024/**
025 * A IQ stanza(/packet) used to depart a workgroup queue. There are two cases for issuing a depart
026 * queue request:<ul>
027 *     <li>The user wants to leave the queue. In this case, an instance of this class
028 *         should be created without passing in a user address.
029 *     <li>An administrator or the server removes wants to remove a user from the queue.
030 *         In that case, the address of the user to remove from the queue should be
031 *         used to create an instance of this class.</ul>
032 *
033 * @author loki der quaeler
034 */
035public class DepartQueuePacket extends IQ {
036
037    private Jid user;
038
039    private DepartQueuePacket() {
040        super("depart-queue", "http://jabber.org/protocol/workgroup");
041    }
042
043    /**
044     * Creates a depart queue request stanza(/packet) to the specified workgroup.
045     *
046     * @param workgroup the workgroup to depart.
047     */
048    public DepartQueuePacket(Jid workgroup) {
049        this(workgroup, null);
050    }
051
052    /**
053     * Creates a depart queue request to the specified workgroup and for the
054     * specified user.
055     *
056     * @param workgroup the workgroup to depart.
057     * @param user the user to make depart from the queue.
058     */
059    public DepartQueuePacket(Jid workgroup, Jid user) {
060        this();
061        this.user = user;
062
063        setTo(workgroup);
064        setType(IQ.Type.set);
065        setFrom(user);
066    }
067
068    @Override
069    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
070        buf.rightAngleBracket();
071
072        if (this.user != null) {
073            buf.append("<jid>").append(this.user).append("</jid>");
074        }
075
076        return buf;
077    }
078}