1/**
2 * $RCSfile$
3 * $Revision$
4 * $Date$
5 *
6 * Copyright 2003-2007 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
21package org.jivesoftware.smackx.packet;
22
23import org.jivesoftware.smack.packet.IQ;
24
25/**
26 * A Version IQ packet, which is used by XMPP clients to discover version information
27 * about the software running at another entity's JID.<p>
28 *
29 * An example to discover the version of the server:
30 * <pre>
31 * // Request the version from the server.
32 * Version versionRequest = new Version();
33 * timeRequest.setType(IQ.Type.GET);
34 * timeRequest.setTo("example.com");
35 *
36 * // Create a packet collector to listen for a response.
37 * PacketCollector collector = con.createPacketCollector(
38 *                new PacketIDFilter(versionRequest.getPacketID()));
39 *
40 * con.sendPacket(versionRequest);
41 *
42 * // Wait up to 5 seconds for a result.
43 * IQ result = (IQ)collector.nextResult(5000);
44 * if (result != null && result.getType() == IQ.Type.RESULT) {
45 *     Version versionResult = (Version)result;
46 *     // Do something with result...
47 * }</pre><p>
48 *
49 * @author Gaston Dombiak
50 */
51public class Version extends IQ {
52
53    private String name;
54    private String version;
55    private String os;
56
57    /**
58     * Returns the natural-language name of the software. This property will always be
59     * present in a result.
60     *
61     * @return the natural-language name of the software.
62     */
63    public String getName() {
64        return name;
65    }
66
67    /**
68     * Sets the natural-language name of the software. This message should only be
69     * invoked when parsing the XML and setting the property to a Version instance.
70     *
71     * @param name the natural-language name of the software.
72     */
73    public void setName(String name) {
74        this.name = name;
75    }
76
77    /**
78     * Returns the specific version of the software. This property will always be
79     * present in a result.
80     *
81     * @return the specific version of the software.
82     */
83    public String getVersion() {
84        return version;
85    }
86
87    /**
88     * Sets the specific version of the software. This message should only be
89     * invoked when parsing the XML and setting the property to a Version instance.
90     *
91     * @param version the specific version of the software.
92     */
93    public void setVersion(String version) {
94        this.version = version;
95    }
96
97    /**
98     * Returns the operating system of the queried entity. This property will always be
99     * present in a result.
100     *
101     * @return the operating system of the queried entity.
102     */
103    public String getOs() {
104        return os;
105    }
106
107    /**
108     * Sets the operating system of the queried entity. This message should only be
109     * invoked when parsing the XML and setting the property to a Version instance.
110     *
111     * @param os operating system of the queried entity.
112     */
113    public void setOs(String os) {
114        this.os = os;
115    }
116
117    public String getChildElementXML() {
118        StringBuilder buf = new StringBuilder();
119        buf.append("<query xmlns=\"jabber:iq:version\">");
120        if (name != null) {
121            buf.append("<name>").append(name).append("</name>");
122        }
123        if (version != null) {
124            buf.append("<version>").append(version).append("</version>");
125        }
126        if (os != null) {
127            buf.append("<os>").append(os).append("</os>");
128        }
129        buf.append("</query>");
130        return buf.toString();
131    }
132}
133