001/**
002 *
003 * Copyright the original author or authors
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 */
017package org.jivesoftware.smackx.jingleold;
018
019import java.util.logging.Level;
020import java.util.logging.Logger;
021
022import org.jivesoftware.smack.packet.IQ;
023
024import org.jivesoftware.smackx.jingleold.packet.Jingle;
025import org.jivesoftware.smackx.jingleold.packet.JingleError;
026
027/**
028 * Jingle.
029 *  @author Jeff Williams
030 *  @see JingleSessionState
031 */
032public class JingleSessionStateActive extends JingleSessionState {
033    private static final Logger LOGGER = Logger.getLogger(JingleSessionStateActive.class.getName());
034
035    private static JingleSessionStateActive INSTANCE = null;
036
037    protected JingleSessionStateActive() {
038        // Prevent instantiation of the class.
039    }
040
041    /**
042     *  A thread-safe means of getting the one instance of this class.
043     *  @return The singleton instance of this class.
044     */
045    public static synchronized JingleSessionState getInstance() {
046        if (INSTANCE == null) {
047            INSTANCE = new JingleSessionStateActive();
048        }
049        return INSTANCE;
050    }
051
052    @Override
053    public void enter() {
054        // TODO Auto-generated method stub
055
056    }
057
058    @Override
059    public void exit() {
060        // TODO Auto-generated method stub
061
062    }
063
064    @Override
065    public IQ processJingle(JingleSession session, Jingle jingle, JingleActionEnum action) {
066        IQ response = null;
067
068        switch (action) {
069
070            case CONTENT_ACCEPT:
071                break;
072
073            case CONTENT_ADD:
074                break;
075
076            case CONTENT_MODIFY:
077                break;
078
079            case CONTENT_REMOVE:
080                break;
081
082            case SESSION_INFO:
083                break;
084
085            case SESSION_TERMINATE:
086                receiveSessionTerminateAction(session, jingle);
087                break;
088
089            case TRANSPORT_INFO:
090                break;
091
092            default:
093                // Anything other action is an error.
094                response = session.createJingleError(jingle, JingleError.OUT_OF_ORDER);
095                break;
096        }
097        return response;
098    }
099
100    /**
101     * Receive and process the <session-terminate> action.
102     */
103    private static IQ receiveSessionTerminateAction(JingleSession session, Jingle jingle) {
104
105        // According to XEP-166 the only thing we can do is ack.
106        IQ response = session.createAck(jingle);
107
108        try {
109            session.terminate("Closed remotely");
110        } catch (Exception e) {
111            LOGGER.log(Level.WARNING, "exception", e);
112        }
113
114        return response;
115    }
116
117}