1 import org.jivesoftware.smack.packet.IQ; 2 import org.jivesoftware.smack.provider.ProviderManager; 3 4 44 public final class VersionIQ extends IQ { 45 46 private String name=null; 47 private String version=null; 48 private String os=null; 49 50 private boolean isEmpty=true; 51 52 53 public VersionIQ(){ 54 } 56 57 62 public VersionIQ(String name, String version, String os){ 63 if(name==null || version==null){ 64 throw new NullPointerException ("Null parameter passed to VersionIQ constructor"); 65 } 66 isEmpty=false; 67 this.name=name; 68 this.version=version; 69 this.os=os; 70 } 71 72 74 public String getName(){ 75 return name; 76 } 77 78 80 public String getVersion(){ 81 return version; 82 } 83 84 86 public String getOs(){ 87 return os; 88 } 89 90 91 public void setName(String name){ 92 this.name=name; 93 if(name!=null){ 94 isEmpty=false; 95 } 96 } 97 98 99 public void setVersion(String version){ 100 this.version=version; 101 if(version!=null){ 102 isEmpty=false; 103 } 104 } 105 106 107 public void setOs(String os){ 108 this.os=os; 109 } 110 111 112 public static void install(){ 113 ProviderManager.addIQProvider("query","jabber:iq:version",VersionIQ.class); 114 } 115 116 public String getChildElementXML() { 117 StringBuffer buf = new StringBuffer (); 118 if(isEmpty){ 119 buf.append("<query xmlns=\"jabber:iq:version\"/>"); 120 return buf.toString(); 121 } 122 buf.append("<query xmlns=\"jabber:iq:version\">"); 123 buf.append("<name>").append(name).append("</name>"); 124 buf.append("<version>").append(version).append("</version>"); 125 if(os!=null){ 126 buf.append("<os>").append(os).append("</os>"); 127 } 128 buf.append("</query>"); 129 return buf.toString(); 130 } 131 } | Popular Tags |