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