001/**
002 *
003 * Copyright 2016 Fernando Ramirez
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 */
017package org.jivesoftware.smackx.muclight.element;
018
019import java.util.Iterator;
020import java.util.Map;
021
022import org.jivesoftware.smack.packet.IQ;
023
024import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
025import org.jivesoftware.smackx.muclight.MultiUserChatLight;
026import org.jivesoftware.smackx.muclight.element.MUCLightElements.UserWithAffiliationElement;
027
028import org.jxmpp.jid.Jid;
029
030/**
031 * MUC Light affiliations response IQ class.
032 *
033 * @author Fernando Ramirez
034 *
035 */
036public class MUCLightAffiliationsIQ extends IQ {
037
038    public static final String ELEMENT = QUERY_ELEMENT;
039    public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.AFFILIATIONS;
040
041    private final String version;
042    private Map<Jid, MUCLightAffiliation> affiliations;
043
044    /**
045     * MUC Light affiliations response IQ constructor.
046     *
047     * @param version TODO javadoc me please
048     * @param affiliations TODO javadoc me please
049     */
050    @SuppressWarnings("this-escape")
051    public MUCLightAffiliationsIQ(String version, Map<Jid, MUCLightAffiliation> affiliations) {
052        super(ELEMENT, NAMESPACE);
053        this.version = version;
054        this.affiliations = affiliations;
055    }
056
057    @Override
058    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
059        xml.rightAngleBracket();
060        xml.optElement("version", version);
061
062        Iterator<Map.Entry<Jid, MUCLightAffiliation>> it = affiliations.entrySet().iterator();
063        while (it.hasNext()) {
064            Map.Entry<Jid, MUCLightAffiliation> pair = it.next();
065            xml.append(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
066        }
067
068        return xml;
069    }
070
071    /**
072     * Returns the version.
073     *
074     * @return the version
075     */
076    public String getVersion() {
077        return version;
078    }
079
080    /**
081     * Returns the room affiliations.
082     *
083     * @return the affiliations of the room
084     */
085    public Map<Jid, MUCLightAffiliation> getAffiliations() {
086        return affiliations;
087    }
088
089}