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.smack.packet; 019 020/** 021 * IQ stanza(/packet) used by Smack to bind a resource and to obtain the jid assigned by the server. 022 * There are two ways to bind a resource. One is simply sending an empty Bind stanza(/packet) where the 023 * server will assign a new resource for this connection. The other option is to set a desired 024 * resource but the server may return a modified version of the sent resource.<p> 025 * 026 * For more information refer to the following 027 * <a href=http://www.xmpp.org/specs/rfc3920.html#bind>link</a>. 028 * 029 * @author Gaston Dombiak 030 */ 031public class Bind extends IQ { 032 033 public static final String ELEMENT = "bind"; 034 public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-bind"; 035 036 private final String resource; 037 private final String jid; 038 039 public Bind(String resource, String jid) { 040 super(ELEMENT, NAMESPACE); 041 this.resource = resource; 042 this.jid = jid; 043 } 044 045 public String getResource() { 046 return resource; 047 } 048 049 public String getJid() { 050 return jid; 051 } 052 053 public static Bind newSet(String resource) { 054 Bind bind = new Bind(resource, null); 055 bind.setType(IQ.Type.set); 056 return bind; 057 } 058 059 public static Bind newResult(String jid) { 060 return new Bind(null, jid); 061 } 062 063 @Override 064 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 065 xml.rightAngleBracket(); 066 xml.optElement("resource", resource); 067 xml.optElement("jid", jid); 068 return xml; 069 } 070 071 public static class Feature implements ExtensionElement { 072 073 public static final Feature INSTANCE = new Feature(); 074 075 private Feature() { 076 } 077 078 @Override 079 public String getElementName() { 080 return ELEMENT; 081 } 082 083 @Override 084 public String getNamespace() { 085 return NAMESPACE; 086 } 087 088 @Override 089 public String toXML() { 090 return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>"; 091 } 092 093 } 094}