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.smackx.chatstates.packet; 019 020import org.jivesoftware.smack.packet.XmlElement; 021import org.jivesoftware.smack.util.XmlStringBuilder; 022 023import org.jivesoftware.smackx.chatstates.ChatState; 024 025/** 026 * Represents a chat state which is an extension to message packets which is used to indicate 027 * the current status of a chat participant. 028 * 029 * @author Alexander Wenckus 030 * @see org.jivesoftware.smackx.chatstates.ChatState 031 */ 032public class ChatStateExtension implements XmlElement { 033 034 public static final String NAMESPACE = "http://jabber.org/protocol/chatstates"; 035 036 private final ChatState state; 037 038 /** 039 * Default constructor. The argument provided is the state that the extension will represent. 040 * 041 * @param state the state that the extension represents. 042 */ 043 public ChatStateExtension(ChatState state) { 044 this.state = state; 045 } 046 047 @Override 048 public String getElementName() { 049 return state.name(); 050 } 051 052 @Override 053 public String getNamespace() { 054 return NAMESPACE; 055 } 056 057 public ChatState getChatState() { 058 return state; 059 } 060 061 @Override 062 public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { 063 XmlStringBuilder xml = new XmlStringBuilder(this); 064 xml.closeEmptyElement(); 065 return xml; 066 } 067 068}