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