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 020import org.jivesoftware.smack.util.XmlStringBuilder; 021 022/** 023 * IQ packet used by Smack to bind a resource and to obtain the jid assigned by the server. 024 * There are two ways to bind a resource. One is simply sending an empty Bind packet where the 025 * server will assign a new resource for this connection. The other option is to set a desired 026 * resource but the server may return a modified version of the sent resource.<p> 027 * 028 * For more information refer to the following 029 * <a href=http://www.xmpp.org/specs/rfc3920.html#bind>link</a>. 030 * 031 * @author Gaston Dombiak 032 */ 033public class Bind extends IQ { 034 035 private String resource = null; 036 private String jid = null; 037 038 public Bind() { 039 setType(IQ.Type.SET); 040 } 041 042 public String getResource() { 043 return resource; 044 } 045 046 public void setResource(String resource) { 047 this.resource = resource; 048 } 049 050 public String getJid() { 051 return jid; 052 } 053 054 public void setJid(String jid) { 055 this.jid = jid; 056 } 057 058 @Override 059 public CharSequence getChildElementXML() { 060 XmlStringBuilder xml = new XmlStringBuilder(); 061 xml.halfOpenElement("bind"); 062 xml.xmlnsAttribute("urn:ietf:params:xml:ns:xmpp-bind"); 063 xml.rightAngelBracket(); 064 xml.optElement("resource", resource); 065 xml.optElement("jid", jid); 066 xml.closeElement("bind"); 067 068 return xml; 069 } 070}