KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > messenger > handler > IQVersionHandler


1 /**
2  * $RCSfile: IQVersionHandler.java,v $
3  * $Revision: 1.12 $
4  * $Date: 2004/12/12 02:30:40 $
5  *
6  * Copyright (C) 2004 Jive Software. All rights reserved.
7  *
8  * This software is published under the terms of the GNU Public License (GPL),
9  * a copy of which is included in this distribution.
10  */

11
12 package org.jivesoftware.messenger.handler;
13
14 import org.jivesoftware.messenger.disco.ServerFeaturesProvider;
15 import org.jivesoftware.messenger.IQHandlerInfo;
16 import org.jivesoftware.messenger.PacketException;
17 import org.jivesoftware.admin.AdminConsole;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import org.dom4j.DocumentHelper;
22 import org.dom4j.Element;
23 import org.dom4j.QName;
24 import org.xmpp.packet.IQ;
25
26 /**
27  * Implements the TYPE_IQ jabber:iq:version protocol (version info). Allows
28  * XMPP entities to query each other's application versions. The server
29  * will respond with its current version info.
30  *
31  * @author Iain Shigeoka
32  */

33 public class IQVersionHandler extends IQHandler implements ServerFeaturesProvider {
34
35     private static Element bodyElement;
36     private IQHandlerInfo info;
37
38     public IQVersionHandler() {
39         super("XMPP Server Version Handler");
40         info = new IQHandlerInfo("query", "jabber:iq:version");
41         if (bodyElement == null) {
42             bodyElement = DocumentHelper.createElement(QName.get("query", "jabber:iq:version"));
43             bodyElement.addElement("name").setText(AdminConsole.getAppName());
44             bodyElement.addElement("os").setText("Java 5");
45             bodyElement.addElement("version");
46         }
47     }
48
49     public IQ handleIQ(IQ packet) throws PacketException {
50         // Could cache this information for every server we see
51
Element answerElement = bodyElement.createCopy();
52         answerElement.element("name").setText(AdminConsole.getAppName());
53         answerElement.element("version").setText(AdminConsole.getVersionString());
54         IQ result = IQ.createResultIQ(packet);
55         result.setChildElement(answerElement);
56         return result;
57     }
58
59     public IQHandlerInfo getInfo() {
60         return info;
61     }
62
63     public Iterator JavaDoc getFeatures() {
64         ArrayList JavaDoc features = new ArrayList JavaDoc();
65         features.add("jabber:iq:version");
66         return features.iterator();
67     }
68 }
Popular Tags