Destroy.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software, 2014 Florian Schmaus
  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.io.Serializable;

  19. import org.jivesoftware.smack.packet.NamedElement;
  20. import org.jivesoftware.smack.util.XmlStringBuilder;

  21. import org.jxmpp.jid.EntityBareJid;

  22. /**
  23.  * Represents a request to the server to destroy a room. The sender of the request should be the
  24.  * room's owner. If the sender of the destroy request is not the room's owner then the server will
  25.  * answer a "Forbidden" error.
  26.  *
  27.  * @author Gaston Dombiak
  28.  */
  29. public class Destroy implements NamedElement, Serializable {
  30.     /**
  31.      *
  32.      */
  33.     private static final long serialVersionUID = 1L;

  34.     public static final String ELEMENT = "destroy";

  35.     private final String reason;
  36.     private final EntityBareJid jid;
  37.     private final String password;

  38.     public Destroy(Destroy other) {
  39.         this(other.jid, other.password, other.reason);
  40.     }

  41.     public Destroy(EntityBareJid alternativeJid, String reason) {
  42.         this.jid = alternativeJid;
  43.         this.reason = reason;
  44.         this.password = null;
  45.     }

  46.     public Destroy(EntityBareJid alternativeJid, String password, String reason) {
  47.         this.jid = alternativeJid;
  48.         this.password = password;
  49.         this.reason = reason;
  50.     }

  51.     /**
  52.      * Returns the JID of an alternate location since the current room is being destroyed.
  53.      *
  54.      * @return the JID of an alternate location.
  55.      */
  56.     public EntityBareJid getJid() {
  57.         return jid;
  58.     }

  59.     /**
  60.      * Returns the password of the alternate location.
  61.      *
  62.      * @return the password of the alternate location.
  63.      */
  64.     public String getPassword() {
  65.         return password;
  66.     }

  67.     /**
  68.      * Returns the reason for the room destruction.
  69.      *
  70.      * @return the reason for the room destruction.
  71.      */
  72.     public String getReason() {
  73.         return reason;
  74.     }

  75.     @Override
  76.     public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
  77.         XmlStringBuilder xml = new XmlStringBuilder(this);
  78.         xml.optAttribute("jid", getJid());
  79.         xml.rightAngleBracket();
  80.         xml.optElement("password", getPassword());
  81.         xml.optElement("reason", getReason());
  82.         xml.closeElement(this);
  83.         return xml;
  84.     }

  85.     @Override
  86.     public String getElementName() {
  87.         return ELEMENT;
  88.     }

  89.     @Override
  90.     public Destroy clone() {
  91.         return new Destroy(this);
  92.     }
  93. }