MUCOwner.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  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.muc.packet;
  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

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

  22. /**
  23.  * IQ stanza that serves for granting and revoking ownership privileges, granting
  24.  * and revoking administrative privileges and destroying a room. All these operations
  25.  * are scoped by the 'http://jabber.org/protocol/muc#owner' namespace.
  26.  *
  27.  * @author Gaston Dombiak
  28.  */
  29. public class MUCOwner extends IQ {

  30.     public static final String ELEMENT = QUERY_ELEMENT;
  31.     public static final String NAMESPACE = MUCInitialPresence.NAMESPACE + "#owner";

  32.     private final List<MUCItem> items = new ArrayList<>();
  33.     private Destroy destroy;

  34.     public MUCOwner() {
  35.         super(ELEMENT, NAMESPACE);
  36.     }

  37.     /**
  38.      * Returns a List of item children that holds information about affiliation,
  39.      * jids and nicks.
  40.      *
  41.      * @return a List of item children that holds information about affiliation,
  42.      *          jids and nicks.
  43.      */
  44.     public List<MUCItem> getItems() {
  45.         synchronized (items) {
  46.             return Collections.unmodifiableList(new ArrayList<>(items));
  47.         }
  48.     }

  49.     /**
  50.      * Returns a request to the server to destroy a room. The sender of the request
  51.      * should be the room's owner. If the sender of the destroy request is not the room's owner
  52.      * then the server will answer a "Forbidden" error.
  53.      *
  54.      * @return a request to the server to destroy a room.
  55.      */
  56.     public Destroy getDestroy() {
  57.         return destroy;
  58.     }

  59.     /**
  60.      * Sets a request to the server to destroy a room. The sender of the request
  61.      * should be the room's owner. If the sender of the destroy request is not the room's owner
  62.      * then the server will answer a "Forbidden" error.
  63.      *
  64.      * @param destroy the request to the server to destroy a room.
  65.      */
  66.     public void setDestroy(Destroy destroy) {
  67.         this.destroy = destroy;
  68.     }

  69.     /**
  70.      * Adds an item child that holds information about affiliation, jids and nicks.
  71.      *
  72.      * @param item the item child that holds information about affiliation, jids and nicks.
  73.      */
  74.     public void addItem(MUCItem item) {
  75.         synchronized (items) {
  76.             items.add(item);
  77.         }
  78.     }

  79.     @Override
  80.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
  81.         xml.rightAngleBracket();

  82.         synchronized (items) {
  83.             for (MUCItem item : items) {
  84.                 xml.append(item.toXML());
  85.             }
  86.         }
  87.         xml.optElement(getDestroy());

  88.         return xml;
  89.     }

  90. }