2013-02-07 15:19:47 +01:00
|
|
|
/**
|
2014-02-19 10:38:30 +01:00
|
|
|
*
|
|
|
|
* Copyright the original author or authors
|
2013-02-07 15:19:47 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2013-02-07 15:19:47 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2014-08-20 00:25:57 +02:00
|
|
|
package org.jivesoftware.smackx.jingleold;
|
2008-05-21 06:35:42 +02:00
|
|
|
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.SmackException;
|
2008-05-21 06:35:42 +02:00
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-08-20 00:25:57 +02:00
|
|
|
import org.jivesoftware.smackx.jingleold.packet.Jingle;
|
2008-05-21 06:35:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement the Jingle Session state using the State Behavioral pattern.
|
|
|
|
* (From the book Design Patterns, AKA GoF.)
|
|
|
|
* These classes also employ the Flyweight and Singleton patterns as recommended for the State pattern by GoF.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2008-05-21 06:35:42 +02:00
|
|
|
* There seems to be three ways to go with the State pattern in Java: interface, abstract class and enums.
|
|
|
|
* Most of the accepted models use abstract classes. It wasn't clear to me that any of the three models was
|
|
|
|
* superior, so I went with the most common example.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2008-05-21 06:35:42 +02:00
|
|
|
* @author Jeff Williams
|
|
|
|
*/
|
|
|
|
public abstract class JingleSessionState {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when entering the state.
|
|
|
|
*/
|
|
|
|
public static JingleSessionState getInstance() {
|
|
|
|
// Since we can never instantiate this class there is nothing to return (ever).
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when entering the state.
|
|
|
|
*/
|
|
|
|
public abstract void enter();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when exiting the state.
|
|
|
|
*/
|
|
|
|
public abstract void exit();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process an incoming Jingle Packet.
|
|
|
|
* When you look at the GoF State pattern this method roughly corresponds to example on p310: ProcessOctect().
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws InterruptedException
|
2008-05-21 06:35:42 +02:00
|
|
|
*/
|
2015-02-14 09:43:44 +01:00
|
|
|
public abstract IQ processJingle(JingleSession session, Jingle jingle, JingleActionEnum action) throws SmackException, InterruptedException;
|
2008-05-21 06:35:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For debugging just emit the short name of the class.
|
|
|
|
*/
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2008-05-21 06:35:42 +02:00
|
|
|
public String toString() {
|
|
|
|
return this.getClass().getSimpleName();
|
|
|
|
}
|
|
|
|
}
|