package org.jivesoftware.smack.packet;

import org.jxmpp.jid.FullJid;

public class Bind extends IQ {
   public static final String ELEMENT = "bind";
   public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-bind";
   private final String resource;
   private final FullJid jid;

   public Bind(String resource, FullJid jid) {
      super("bind", "urn:ietf:params:xml:ns:xmpp-bind");
      this.resource = resource;
      this.jid = jid;
   }

   public String getResource() {
      return this.resource;
   }

   public FullJid getJid() {
      return this.jid;
   }

   public static Bind newSet(String resource) {
      Bind bind = new Bind(resource, (FullJid)null);
      bind.setType(IQ.Type.set);
      return bind;
   }

   public static Bind newResult(FullJid jid) {
      return new Bind((String)null, jid);
   }

   protected IQ.IQChildElementXmlStringBuilder getIQChildElementBuilder(IQ.IQChildElementXmlStringBuilder xml) {
      xml.rightAngleBracket();
      xml.optElement("resource", this.resource);
      xml.optElement("jid", this.jid);
      return xml;
   }

   public static class Feature implements ExtensionElement {
      public static final Bind.Feature INSTANCE = new Bind.Feature();

      private Feature() {
      }

      public String getElementName() {
         return "bind";
      }

      public String getNamespace() {
         return "urn:ietf:params:xml:ns:xmpp-bind";
      }

      public String toXML() {
         return "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>";
      }
   }
}
