1 20 21 package org.jivesoftware.smack.packet; 22 23 import org.jivesoftware.smack.provider.IQProvider; 24 import org.xmlpull.v1.XmlPullParser; 25 26 37 public class Bind extends IQ { 38 39 private String resource = null; 40 private String jid = null; 41 42 public Bind() { 43 setType(IQ.Type.SET); 44 } 45 46 public String getResource() { 47 return resource; 48 } 49 50 public void setResource(String resource) { 51 this.resource = resource; 52 } 53 54 public String getJid() { 55 return jid; 56 } 57 58 public void setJid(String jid) { 59 this.jid = jid; 60 } 61 62 public String getChildElementXML() { 63 StringBuffer buf = new StringBuffer (); 64 buf.append("<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">"); 65 if (resource != null) { 66 buf.append("<resource>").append(resource).append("</resource>"); 67 } 68 if (jid != null) { 69 buf.append("<jid>").append(jid).append("</jid>"); 70 } 71 buf.append("</bind>"); 72 return buf.toString(); 73 } 74 75 public static class Provider implements IQProvider { 76 77 public IQ parseIQ(XmlPullParser parser) throws Exception { 78 Bind bind = new Bind(); 79 boolean done = false; 80 while (!done) { 81 int eventType = parser.next(); 82 if (eventType == XmlPullParser.START_TAG) { 83 if (parser.getName().equals("resource")) { 84 bind.setResource(parser.nextText()); 85 } 86 else if (parser.getName().equals("jid")) { 87 bind.setJid(parser.nextText()); 88 } 89 } else if (eventType == XmlPullParser.END_TAG) { 90 if (parser.getName().equals("bind")) { 91 done = true; 92 } 93 } 94 } 95 96 return bind; 97 } 98 } 99 } 100 | Popular Tags |