1/**
2 * $Revision$
3 * $Date$
4 *
5 * Copyright 2003-2007 Jive Software.
6 *
7 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20package org.jivesoftware.smackx.workgroup.packet;
21
22import org.jivesoftware.smack.packet.PacketExtension;
23import org.jivesoftware.smack.provider.PacketExtensionProvider;
24import org.xmlpull.v1.XmlPullParser;
25
26public class SessionID implements PacketExtension {
27
28    /**
29     * Element name of the packet extension.
30     */
31    public static final String ELEMENT_NAME = "session";
32
33    /**
34     * Namespace of the packet extension.
35     */
36    public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
37
38    private String sessionID;
39
40    public SessionID(String sessionID) {
41        this.sessionID = sessionID;
42    }
43
44    public String getSessionID() {
45        return this.sessionID;
46    }
47
48    public String getElementName() {
49        return ELEMENT_NAME;
50    }
51
52    public String getNamespace() {
53        return NAMESPACE;
54    }
55
56    public String toXML() {
57        StringBuilder buf = new StringBuilder();
58
59        buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\" ");
60        buf.append("id=\"").append(this.getSessionID());
61        buf.append("\"/>");
62
63        return buf.toString();
64    }
65
66    public static class Provider implements PacketExtensionProvider {
67
68        public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
69            String sessionID = parser.getAttributeValue("", "id");
70
71            // Advance to end of extension.
72            parser.next();
73
74            return new SessionID(sessionID);
75        }
76    }
77}
78