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     */
055    public TransportResolver getResolver(JingleSession session) throws XMPPException, SmackException {
056        TransportResolver resolver = createResolver(session);
057        if (resolver == null) {
058            resolver = new BasicResolver();
059        }
060        resolver.initializeAndWait();
061
062        return resolver;
063    }
064
065    /**
066     * Create a Transport Resolver instance according to the implementation.
067     *
068     * @return the TransportResolver
069     */
070    protected abstract TransportResolver createResolver(JingleSession session) throws SmackException;
071
072}