001/**
002 *
003 * Copyright 2003-2006 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 */
017package org.jivesoftware.smackx.jingleold.nat;
018
019import org.jivesoftware.smack.SmackException;
020import org.jivesoftware.smack.XMPPException;
021import org.jivesoftware.smackx.jingleold.JingleSession;
022
023/**
024 * Transport manager for Jingle.
025 *
026 * This class makes easier the use of transport resolvers by presenting a simple
027 * interface for algorithm selection. The transport manager also keeps the match
028 * between the resolution method and the <transport> element present in
029 * Jingle packets.
030 *
031 * As Jingle have many transport methods (official and unofficial methods),
032 * this abstract class helps us to extends the transport support of the API.
033 *
034 * This class must be used with a JingleManager instance in the following way:
035 *
036 * JingleManager jingleManager = new JingleManager(xmppConnection, new BasicTransportManager());
037 *
038 * @author Thiago Camargo
039 */
040public abstract class JingleTransportManager {
041    // This class implements the context of a Strategy pattern...
042
043    /**
044     * Deafult contructor.
045     */
046    public JingleTransportManager() {
047
048    }
049
050    /**
051     * Get a new Transport Resolver to be used in a Jingle Session.
052     *
053     * @return the TransportResolver to be used
054     * @throws InterruptedException 
055     */
056    public TransportResolver getResolver(JingleSession session) throws XMPPException, SmackException, InterruptedException {
057        TransportResolver resolver = createResolver(session);
058        if (resolver == null) {
059            resolver = new BasicResolver();
060        }
061        resolver.initializeAndWait();
062
063        return resolver;
064    }
065
066    /**
067     * Create a Transport Resolver instance according to the implementation.
068     *
069     * @return the TransportResolver
070     * @throws InterruptedException 
071     */
072    protected abstract TransportResolver createResolver(JingleSession session) throws SmackException, InterruptedException;
073
074}