KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xmpp > packet > DiscoInfo


1 /**
2  * $RCSfile: $
3  * $Revision: $
4  * $Date: $
5  *
6  * Copyright 2005 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.xmpp.packet;
22
23 import org.dom4j.DocumentFactory;
24 import org.dom4j.Element;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 /**
31  * Created by IntelliJ IDEA.
32  * User: Gaston
33  * Date: Apr 11, 2005
34  * Time: 10:16:52 AM
35  * To change this template use File | Settings | File Templates.
36  */

37 public class DiscoInfo extends IQ {
38
39     public Collection JavaDoc<Identity> getIdentities() {
40         Collection JavaDoc<Identity> answer = new ArrayList JavaDoc<Identity>();
41         for (Iterator JavaDoc 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 JavaDoc<String JavaDoc> getFeatures() {
52         Collection JavaDoc<String JavaDoc> answer = new ArrayList JavaDoc<String JavaDoc>();
53         for (Iterator JavaDoc 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 JavaDoc 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 JavaDoc category, String JavaDoc type, String JavaDoc name) {
71             this.element =
72                     DocumentFactory.getInstance().createDocument().addElement("identity")
73                     .createCopy();
74             // Set the new attributes
75
element.addAttribute("category", category);
76             element.addAttribute("type", type);
77             element.addAttribute("name", name);
78         }
79
80         public String JavaDoc getCategory() {
81             return element.attributeValue("category");
82         }
83
84         public String JavaDoc getType() {
85             return element.attributeValue("type");
86         }
87
88         public String JavaDoc getName() {
89             return element.attributeValue("name");
90         }
91
92         Element getElement() {
93             return element;
94         }
95     }
96 }
97
Popular Tags