1 20 21 package org.xmpp.packet; 22 23 import org.dom4j.DocumentFactory; 24 import org.dom4j.Element; 25 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 30 37 public class DiscoInfo extends IQ { 38 39 public Collection <Identity> getIdentities() { 40 Collection <Identity> answer = new ArrayList <Identity>(); 41 for (Iterator it=getChildElement().elementIterator("identity"); it.hasNext();) { 42 answer.add(new Identity((Element) it.next())); 43 } 44 return answer; 45 } 46 47 public void addIdentity(Identity identity) { 48 getChildElement().add(identity.getElement()); 49 } 50 51 public Collection <String > getFeatures() { 52 Collection <String > answer = new ArrayList <String >(); 53 for (Iterator it=getChildElement().elementIterator("feature"); it.hasNext();) { 54 answer.add(((Element)it.next()).attributeValue("var")); 55 } 56 return answer; 57 } 58 59 public void addFeature(String feature) { 60 getChildElement().addElement("feature").addAttribute("var", feature); 61 } 62 63 public static class Identity { 64 private Element element; 65 66 Identity(Element element) { 67 this.element = element; 68 } 69 70 public Identity(String category, String type, String name) { 71 this.element = 72 DocumentFactory.getInstance().createDocument().addElement("identity") 73 .createCopy(); 74 element.addAttribute("category", category); 76 element.addAttribute("type", type); 77 element.addAttribute("name", name); 78 } 79 80 public String getCategory() { 81 return element.attributeValue("category"); 82 } 83 84 public String getType() { 85 return element.attributeValue("type"); 86 } 87 88 public String getName() { 89 return element.attributeValue("name"); 90 } 91 92 Element getElement() { 93 return element; 94 } 95 } 96 } 97 | Popular Tags |