1 20 21 package org.jivesoftware.smackx.packet; 22 23 import java.util.*; 24 25 import org.jivesoftware.smack.packet.IQ; 26 27 36 public class DiscoverInfo extends IQ { 37 38 private List features = new ArrayList(); 39 private List identities = new ArrayList(); 40 private String node; 41 42 47 public void addFeature(String feature) { 48 addFeature(new DiscoverInfo.Feature(feature)); 49 } 50 51 private void addFeature(Feature feature) { 52 synchronized (features) { 53 features.add(feature); 54 } 55 } 56 57 62 Iterator getFeatures() { 63 synchronized (features) { 64 return Collections.unmodifiableList(new ArrayList(features)).iterator(); 65 } 66 } 67 68 73 public void addIdentity(Identity identity) { 74 synchronized (identities) { 75 identities.add(identity); 76 } 77 } 78 79 84 public Iterator getIdentities() { 85 synchronized (identities) { 86 return Collections.unmodifiableList(new ArrayList(identities)).iterator(); 87 } 88 } 89 90 99 public String getNode() { 100 return node; 101 } 102 103 112 public void setNode(String node) { 113 this.node = node; 114 } 115 116 122 public boolean containsFeature(String feature) { 123 for (Iterator it = getFeatures(); it.hasNext();) { 124 if (feature.equals(((DiscoverInfo.Feature) it.next()).getVar())) 125 return true; 126 } 127 return false; 128 } 129 130 public String getChildElementXML() { 131 StringBuffer buf = new StringBuffer (); 132 buf.append("<query xmlns=\"http://jabber.org/protocol/disco#info\""); 133 if (getNode() != null) { 134 buf.append(" node=\""); 135 buf.append(getNode()); 136 buf.append("\""); 137 } 138 buf.append(">"); 139 synchronized (identities) { 140 for (int i = 0; i < identities.size(); i++) { 141 Identity identity = (Identity) identities.get(i); 142 buf.append(identity.toXML()); 143 } 144 } 145 synchronized (features) { 146 for (int i = 0; i < features.size(); i++) { 147 Feature feature = (Feature) features.get(i); 148 buf.append(feature.toXML()); 149 } 150 } 151 buf.append(getExtensionsXML()); 153 buf.append("</query>"); 154 return buf.toString(); 155 } 156 157 166 public static class Identity { 167 168 private String category; 169 private String name; 170 private String type; 171 172 178 public Identity(String category, String name) { 179 this.category = category; 180 this.name = name; 181 } 182 183 189 public String getCategory() { 190 return category; 191 } 192 193 198 public String getName() { 199 return name; 200 } 201 202 208 public String getType() { 209 return type; 210 } 211 212 218 public void setType(String type) { 219 this.type = type; 220 } 221 222 public String toXML() { 223 StringBuffer buf = new StringBuffer (); 224 buf.append("<identity category=\"").append(category).append("\""); 225 buf.append(" name=\"").append(name).append("\""); 226 if (type != null) { 227 buf.append(" type=\"").append(type).append("\""); 228 } 229 buf.append("/>"); 230 return buf.toString(); 231 } 232 } 233 234 240 public static class Feature { 241 242 private String variable; 243 244 249 public Feature(String variable) { 250 this.variable = variable; 251 } 252 253 258 public String getVar() { 259 return variable; 260 } 261 262 public String toXML() { 263 StringBuffer buf = new StringBuffer (); 264 buf.append("<feature var=\"").append(variable).append("\"/>"); 265 return buf.toString(); 266 } 267 } 268 } | Popular Tags |