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