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.muc.packet;
019import java.util.ArrayList;
020import java.util.Collections;
021import java.util.List;
022
023import org.jivesoftware.smack.packet.IQ;
024
025/**
026 * IQ stanza(/packet) that serves for kicking users, granting and revoking voice, banning users, 
027 * modifying the ban list, granting and revoking membership and granting and revoking 
028 * moderator privileges. All these operations are scoped by the 
029 * 'http://jabber.org/protocol/muc#admin' namespace.
030 * 
031 * @author Gaston Dombiak
032 */
033public class MUCAdmin extends IQ {
034
035    public static final String ELEMENT = QUERY_ELEMENT;
036    public static final String NAMESPACE = MUCInitialPresence.NAMESPACE + "#admin";
037
038    private final List<MUCItem> items = new ArrayList<MUCItem>();
039
040    public MUCAdmin() {
041        super(ELEMENT, NAMESPACE);
042    }
043
044    /**
045     * Returns a List of item childs that holds information about roles, affiliation,
046     * jids and nicks.
047     * 
048     * @return a List of item childs that holds information about roles, affiliation,
049     *          jids and nicks.
050     */
051    public List<MUCItem> getItems() {
052        synchronized (items) {
053            return Collections.unmodifiableList(new ArrayList<MUCItem>(items));
054        }
055    }
056
057    /**
058     * Adds an item child that holds information about roles, affiliation, jids and nicks.
059     * 
060     * @param item the item child that holds information about roles, affiliation, jids and nicks.
061     */
062    public void addItem(MUCItem item) {
063        synchronized (items) {
064            items.add(item);
065        }
066    }
067
068    @Override
069    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
070        xml.rightAngleBracket();
071
072        synchronized (items) {
073            for (MUCItem item : items) {
074                xml.append(item.toXML());
075            }
076        }
077
078        return xml;
079    }
080}