MUCLightAffiliationsIQ.java

  1. /**
  2.  *
  3.  * Copyright 2016 Fernando Ramirez
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.muclight.element;

  18. import java.util.HashMap;
  19. import java.util.Iterator;
  20. import java.util.Map;

  21. import org.jivesoftware.smack.packet.IQ;

  22. import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
  23. import org.jivesoftware.smackx.muclight.MultiUserChatLight;
  24. import org.jivesoftware.smackx.muclight.element.MUCLightElements.UserWithAffiliationElement;

  25. import org.jxmpp.jid.Jid;

  26. /**
  27.  * MUC Light affiliations response IQ class.
  28.  *
  29.  * @author Fernando Ramirez
  30.  *
  31.  */
  32. public class MUCLightAffiliationsIQ extends IQ {

  33.     public static final String ELEMENT = QUERY_ELEMENT;
  34.     public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.AFFILIATIONS;

  35.     private final String version;
  36.     private HashMap<Jid, MUCLightAffiliation> affiliations;

  37.     /**
  38.      * MUC Light affiliations response IQ constructor.
  39.      *
  40.      * @param version TODO javadoc me please
  41.      * @param affiliations TODO javadoc me please
  42.      */
  43.     public MUCLightAffiliationsIQ(String version, HashMap<Jid, MUCLightAffiliation> affiliations) {
  44.         super(ELEMENT, NAMESPACE);
  45.         this.version = version;
  46.         this.affiliations = affiliations;
  47.     }

  48.     @Override
  49.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
  50.         xml.rightAngleBracket();
  51.         xml.optElement("version", version);

  52.         Iterator<Map.Entry<Jid, MUCLightAffiliation>> it = affiliations.entrySet().iterator();
  53.         while (it.hasNext()) {
  54.             Map.Entry<Jid, MUCLightAffiliation> pair = it.next();
  55.             xml.append(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
  56.         }

  57.         return xml;
  58.     }

  59.     /**
  60.      * Returns the version.
  61.      *
  62.      * @return the version
  63.      */
  64.     public String getVersion() {
  65.         return version;
  66.     }

  67.     /**
  68.      * Returns the room affiliations.
  69.      *
  70.      * @return the affiliations of the room
  71.      */
  72.     public HashMap<Jid, MUCLightAffiliation> getAffiliations() {
  73.         return affiliations;
  74.     }

  75. }