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