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.jingle.mediaimpl.test;
018
019import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
020import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
021import org.jivesoftware.smackx.jingle.media.PayloadType;
022import org.jivesoftware.smackx.jingle.nat.JingleTransportManager;
023import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
024import org.jivesoftware.smackx.jingle.JingleSession;
025
026import java.util.*;
027
028/**
029 * Implements a MediaManager for test purposes.
030 *
031 * @author Thiago Camargo
032 */
033
034public class TestMediaManager extends JingleMediaManager {
035
036    public static final String MEDIA_NAME = "TestMedia";
037
038    private List<PayloadType> payloads = new ArrayList<PayloadType>();
039
040    private PayloadType preferredPayloadType = null;
041
042    public TestMediaManager(JingleTransportManager transportManager) {
043        super(transportManager);
044    }
045
046    /**
047    * Return all supported Payloads for this Manager.
048    *
049    * @return The Payload List
050    */
051    public List<PayloadType> getPayloads() {
052        return payloads;
053    }
054
055    public void setPayloads(List<PayloadType> payloads) {
056        this.payloads.addAll(payloads);
057    }
058
059    /**
060     * Returns a new JingleMediaSession
061     *
062     * @param payloadType payloadType
063     * @param remote      remote Candidate
064     * @param local       local Candidate
065     * @return JingleMediaSession JingleMediaSession
066     */
067    public JingleMediaSession createMediaSession(PayloadType payloadType, final TransportCandidate remote,
068            final TransportCandidate local, final JingleSession jingleSession) {
069        TestMediaSession session = null;
070
071        session = new TestMediaSession(payloadType, remote, local, "", jingleSession);
072
073        return session;
074    }
075
076    public PayloadType getPreferredPayloadType() {
077        if (preferredPayloadType != null)
078            return preferredPayloadType;
079        return super.getPreferredPayloadType();
080    }
081
082    public void setPreferredPayloadType(PayloadType preferredPayloadType) {
083        this.preferredPayloadType = preferredPayloadType;
084    }
085
086    public String getName() {
087        return MEDIA_NAME;
088    }
089}