001/**
002 *
003 * Copyright 2017 Paul Schaub
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.transports.jingle_ibb;
018
019import java.util.WeakHashMap;
020
021import org.jivesoftware.smack.XMPPConnection;
022import org.jivesoftware.smackx.jingle.JingleSession;
023import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
024import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
025import org.jivesoftware.smackx.jingle.transports.JingleTransportSession;
026import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport;
027import org.jivesoftware.smackx.jingle.transports.jingle_ibb.provider.JingleIBBTransportProvider;
028
029/**
030 * Manager for Jingle InBandBytestream transports (XEP-0261).
031 */
032public final class JingleIBBTransportManager extends JingleTransportManager<JingleIBBTransport> {
033
034    private static final WeakHashMap<XMPPConnection, JingleIBBTransportManager> INSTANCES = new WeakHashMap<>();
035
036    private JingleIBBTransportManager(XMPPConnection connection) {
037        super(connection);
038        JingleContentProviderManager.addJingleContentTransportProvider(getNamespace(), new JingleIBBTransportProvider());
039    }
040
041    public static JingleIBBTransportManager getInstanceFor(XMPPConnection connection) {
042        JingleIBBTransportManager manager = INSTANCES.get(connection);
043        if (manager == null) {
044            manager = new JingleIBBTransportManager(connection);
045            INSTANCES.put(connection, manager);
046        }
047        return manager;
048    }
049
050    @Override
051    public String getNamespace() {
052        return JingleIBBTransport.NAMESPACE_V1;
053    }
054
055    @Override
056    public JingleTransportSession<JingleIBBTransport> transportSession(JingleSession jingleSession) {
057        return new JingleIBBTransportSession(jingleSession);
058    }
059
060    @Override
061    public void authenticated(XMPPConnection connection, boolean resumed) {
062        // Nothing to do.
063    }
064}