SessionID.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.workgroup.packet;

  18. import java.io.IOException;

  19. import javax.xml.namespace.QName;

  20. import org.jivesoftware.smack.packet.ExtensionElement;
  21. import org.jivesoftware.smack.packet.XmlEnvironment;
  22. import org.jivesoftware.smack.provider.ExtensionElementProvider;
  23. import org.jivesoftware.smack.xml.XmlPullParser;
  24. import org.jivesoftware.smack.xml.XmlPullParserException;

  25. public class SessionID implements ExtensionElement {

  26.     /**
  27.      * Element name of the stanza extension.
  28.      */
  29.     public static final String ELEMENT_NAME = "session";

  30.     /**
  31.      * Namespace of the stanza extension.
  32.      */
  33.     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";

  34.     public static final QName QNAME = new QName(NAMESPACE, ELEMENT_NAME);

  35.     private final String sessionID;

  36.     public SessionID(String sessionID) {
  37.         this.sessionID = sessionID;
  38.     }

  39.     public String getSessionID() {
  40.         return this.sessionID;
  41.     }

  42.     @Override
  43.     public String getElementName() {
  44.         return ELEMENT_NAME;
  45.     }

  46.     @Override
  47.     public String getNamespace() {
  48.         return NAMESPACE;
  49.     }

  50.     @Override
  51.     public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
  52.         StringBuilder buf = new StringBuilder();

  53.         buf.append('<').append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\" ");
  54.         buf.append("id=\"").append(this.getSessionID());
  55.         buf.append("\"/>");

  56.         return buf.toString();
  57.     }

  58.     public static class Provider extends ExtensionElementProvider<SessionID> {

  59.         @Override
  60.         public SessionID parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
  61.                         throws XmlPullParserException, IOException {
  62.             String sessionID = parser.getAttributeValue("", "id");

  63.             // Advance to end of extension.
  64.             parser.next();

  65.             return new SessionID(sessionID);
  66.         }
  67.     }
  68. }