MUCLightChangeAffiliationsIQ.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.  * MUCLight change affiliations IQ class.
  28.  *
  29.  * @author Fernando Ramirez
  30.  *
  31.  */
  32. public class MUCLightChangeAffiliationsIQ extends IQ {

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

  35.     private HashMap<Jid, MUCLightAffiliation> affiliations;

  36.     /**
  37.      * MUCLight change affiliations IQ constructor.
  38.      *
  39.      * @param room TODO javadoc me please
  40.      * @param affiliations TODO javadoc me please
  41.      */
  42.     public MUCLightChangeAffiliationsIQ(Jid room, HashMap<Jid, MUCLightAffiliation> affiliations) {
  43.         super(ELEMENT, NAMESPACE);
  44.         this.setType(Type.set);
  45.         this.setTo(room);
  46.         this.affiliations = affiliations;
  47.     }

  48.     /**
  49.      * Get the affiliations.
  50.      *
  51.      * @return the affiliations
  52.      */
  53.     public HashMap<Jid, MUCLightAffiliation> getAffiliations() {
  54.         return affiliations;
  55.     }

  56.     @Override
  57.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
  58.         xml.rightAngleBracket();

  59.         if (affiliations != null) {
  60.             Iterator<Map.Entry<Jid, MUCLightAffiliation>> it = affiliations.entrySet().iterator();
  61.             while (it.hasNext()) {
  62.                 Map.Entry<Jid, MUCLightAffiliation> pair = it.next();
  63.                 xml.append(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
  64.             }
  65.         }

  66.         return xml;
  67.     }

  68. }