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