Home | History | Annotate | Download | only in packet
      1 /**
      2  * $RCSfile$
      3  * $Revision$
      4  * $Date$
      5  *
      6  * Copyright 2003-2007 Jive Software.
      7  *
      8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
      9  * you may not use this file except in compliance with the License.
     10  * You may obtain a copy of the License at
     11  *
     12  *     http://www.apache.org/licenses/LICENSE-2.0
     13  *
     14  * Unless required by applicable law or agreed to in writing, software
     15  * distributed under the License is distributed on an "AS IS" BASIS,
     16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     17  * See the License for the specific language governing permissions and
     18  * limitations under the License.
     19  */
     20 
     21 package org.jivesoftware.smack.packet;
     22 
     23 /**
     24  * IQ packet used by Smack to bind a resource and to obtain the jid assigned by the server.
     25  * There are two ways to bind a resource. One is simply sending an empty Bind packet where the
     26  * server will assign a new resource for this connection. The other option is to set a desired
     27  * resource but the server may return a modified version of the sent resource.<p>
     28  *
     29  * For more information refer to the following
     30  * <a href=http://www.xmpp.org/specs/rfc3920.html#bind>link</a>.
     31  *
     32  * @author Gaston Dombiak
     33  */
     34 public class Bind extends IQ {
     35 
     36     private String resource = null;
     37     private String jid = null;
     38 
     39     public Bind() {
     40         setType(IQ.Type.SET);
     41     }
     42 
     43     public String getResource() {
     44         return resource;
     45     }
     46 
     47     public void setResource(String resource) {
     48         this.resource = resource;
     49     }
     50 
     51     public String getJid() {
     52         return jid;
     53     }
     54 
     55     public void setJid(String jid) {
     56         this.jid = jid;
     57     }
     58 
     59     public String getChildElementXML() {
     60         StringBuilder buf = new StringBuilder();
     61         buf.append("<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">");
     62         if (resource != null) {
     63             buf.append("<resource>").append(resource).append("</resource>");
     64         }
     65         if (jid != null) {
     66             buf.append("<jid>").append(jid).append("</jid>");
     67         }
     68         buf.append("</bind>");
     69         return buf.toString();
     70     }
     71 }
     72