/** * * Copyright 2017 Paul Schaub * * Licensed under the Apache License, Version 2.0 (the "License"); * 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. */ package org.jivesoftware.smackx.jingle_filetransfer; import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager; import org.jivesoftware.smackx.jingle_filetransfer.provider.JingleContentDescriptionFileTransferProvider; import java.util.WeakHashMap; /** * Manager for Jingle File Transfers. * * @author Paul Schaub */ public final class JingleFileTransferManager extends Manager { public static final String NAMESPACE_V5 = "urn:xmpp:jingle:apps:file-transfer:5"; private static final WeakHashMap INSTANCES = new WeakHashMap<>(); /** * Private constructor. This registers a JingleContentDescriptionFileTransferProvider with the * JingleContentProviderManager. * @param connection connection */ private JingleFileTransferManager(XMPPConnection connection) { super(connection); JingleContentProviderManager.addJingleContentDescriptionProvider( NAMESPACE_V5, new JingleContentDescriptionFileTransferProvider()); } /** * Return a new instance of the FileTransferManager for the given connection. * * @param connection XMPPConnection we wish to get a FileTransferManager for. * @return manager instance. */ public static JingleFileTransferManager getInstanceFor(XMPPConnection connection) { JingleFileTransferManager manager = INSTANCES.get(connection); if (manager == null) { manager = new JingleFileTransferManager(connection); INSTANCES.put(connection, manager); } return manager; } }