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 that serves for granting and revoking ownership privileges, granting 027 * and revoking administrative privileges and destroying a room. All these operations 028 * are scoped by the 'http://jabber.org/protocol/muc#owner' namespace. 029 * 030 * @author Gaston Dombiak 031 */ 032public class MUCOwner extends IQ { 033 034 public static final String ELEMENT = QUERY_ELEMENT; 035 public static final String NAMESPACE = MUCInitialPresence.NAMESPACE + "#owner"; 036 037 private final List<MUCItem> items = new ArrayList<>(); 038 private Destroy destroy; 039 040 public MUCOwner() { 041 super(ELEMENT, NAMESPACE); 042 } 043 044 /** 045 * Returns a List of item children that holds information about affiliation, 046 * jids and nicks. 047 * 048 * @return a List of item children that holds information about affiliation, 049 * jids and nicks. 050 */ 051 public List<MUCItem> getItems() { 052 synchronized (items) { 053 return Collections.unmodifiableList(new ArrayList<>(items)); 054 } 055 } 056 057 /** 058 * Returns a request to the server to destroy a room. The sender of the request 059 * should be the room's owner. If the sender of the destroy request is not the room's owner 060 * then the server will answer a "Forbidden" error. 061 * 062 * @return a request to the server to destroy a room. 063 */ 064 public Destroy getDestroy() { 065 return destroy; 066 } 067 068 /** 069 * Sets a request to the server to destroy a room. The sender of the request 070 * should be the room's owner. If the sender of the destroy request is not the room's owner 071 * then the server will answer a "Forbidden" error. 072 * 073 * @param destroy the request to the server to destroy a room. 074 */ 075 public void setDestroy(Destroy destroy) { 076 this.destroy = destroy; 077 } 078 079 /** 080 * Adds an item child that holds information about affiliation, jids and nicks. 081 * 082 * @param item the item child that holds information about affiliation, jids and nicks. 083 */ 084 public void addItem(MUCItem item) { 085 synchronized (items) { 086 items.add(item); 087 } 088 } 089 090 @Override 091 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 092 xml.rightAngleBracket(); 093 094 synchronized (items) { 095 for (MUCItem item : items) { 096 xml.append(item.toXML()); 097 } 098 } 099 xml.optElement(getDestroy()); 100 101 return xml; 102 } 103 104}