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.BareJid;

  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 BareJid jid;

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

  40.     public Destroy(BareJid alternativeJid, String reason) {
  41.         this.jid = alternativeJid;
  42.         this.reason = reason;
  43.     }

  44.     /**
  45.      * Returns the JID of an alternate location since the current room is being destroyed.
  46.      *
  47.      * @return the JID of an alternate location.
  48.      */
  49.     public BareJid getJid() {
  50.         return jid;
  51.     }

  52.     /**
  53.      * Returns the reason for the room destruction.
  54.      *
  55.      * @return the reason for the room destruction.
  56.      */
  57.     public String getReason() {
  58.         return reason;
  59.     }

  60.     @Override
  61.     public XmlStringBuilder toXML() {
  62.         XmlStringBuilder xml = new XmlStringBuilder(this);
  63.         xml.optAttribute("jid", getJid());
  64.         xml.rightAngleBracket();
  65.         xml.optElement("reason", getReason());
  66.         xml.closeElement(this);
  67.         return xml;
  68.     }

  69.     @Override
  70.     public String getElementName() {
  71.         return ELEMENT;
  72.     }

  73.     @Override
  74.     public Destroy clone() {
  75.         return new Destroy(this);
  76.     }
  77. }