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;
021import org.jxmpp.jid.Jid;
022
023/**
024 * A IQ stanza(/packet) used to depart a workgroup queue. There are two cases for issuing a depart
025 * queue request:<ul>
026 *     <li>The user wants to leave the queue. In this case, an instance of this class
027 *         should be created without passing in a user address.
028 *     <li>An administrator or the server removes wants to remove a user from the queue.
029 *         In that case, the address of the user to remove from the queue should be
030 *         used to create an instance of this class.</ul>
031 *
032 * @author loki der quaeler
033 */
034public class DepartQueuePacket extends IQ {
035
036    private Jid user;
037
038    private DepartQueuePacket() {
039        super("depart-queue", "http://jabber.org/protocol/workgroup");
040    }
041
042    /**
043     * Creates a depart queue request stanza(/packet) to the specified workgroup.
044     *
045     * @param workgroup the workgroup to depart.
046     */
047    public DepartQueuePacket(Jid workgroup) {
048        this(workgroup, null);
049    }
050
051    /**
052     * Creates a depart queue request to the specified workgroup and for the
053     * specified user.
054     *
055     * @param workgroup the workgroup to depart.
056     * @param user the user to make depart from the queue.
057     */
058    public DepartQueuePacket(Jid workgroup, Jid user) {
059        this();
060        this.user = user;
061
062        setTo(workgroup);
063        setType(IQ.Type.set);
064        setFrom(user);
065    }
066
067    @Override
068    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
069        buf.rightAngleBracket();
070
071        if (this.user != null) {
072            buf.append("<jid>").append(this.user).append("</jid>");
073        }
074
075        return buf;
076    }
077}