001/** 002 * 003 * Copyright 2003-2007 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.jivesoftware.smack.packet; 019 020import javax.xml.namespace.QName; 021 022import org.jivesoftware.smack.util.XmlStringBuilder; 023 024/** 025 * IQ stanza that will be sent to the server to establish a session.<p> 026 * 027 * If a server supports sessions, it MUST include a <i>session</i> element in the 028 * stream features it advertises to a client after the completion of stream authentication. 029 * Upon being informed that session establishment is required by the server the client MUST 030 * establish a session if it desires to engage in instant messaging and presence functionality.<p> 031 * 032 * For more information refer to the following 033 * <a href=http://www.xmpp.org/specs/rfc3921.html#session>link</a>. 034 * 035 * @author Gaston Dombiak 036 */ 037public class Session extends SimpleIQ { 038 039 public static final String ELEMENT = "session"; 040 public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-session"; 041 042 @SuppressWarnings("this-escape") 043 public Session() { 044 super(ELEMENT, NAMESPACE); 045 setType(IQ.Type.set); 046 } 047 048 public static class Feature implements ExtensionElement { 049 050 public static final QName QNAME = new QName(NAMESPACE, ELEMENT); 051 052 public static final String OPTIONAL_ELEMENT = "optional"; 053 054 private final boolean optional; 055 056 public Feature(boolean optional) { 057 this.optional = optional; 058 } 059 060 public boolean isOptional() { 061 return optional; 062 } 063 064 @Override 065 public String getElementName() { 066 return ELEMENT; 067 } 068 069 @Override 070 public String getNamespace() { 071 return NAMESPACE; 072 } 073 074 @Override 075 public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { 076 XmlStringBuilder xml = new XmlStringBuilder(this); 077 if (optional) { 078 xml.rightAngleBracket(); 079 xml.emptyElement(OPTIONAL_ELEMENT); 080 xml.closeElement(this); 081 } else { 082 xml.closeEmptyElement(); 083 } 084 return xml; 085 } 086 } 087}