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