001/**
002 *
003 * Copyright 2003-2005 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.provider;
018
019import org.jivesoftware.smack.packet.PacketExtension;
020import org.jivesoftware.smack.provider.PacketExtensionProvider;
021import org.jivesoftware.smackx.jingle.media.ContentInfo;
022import org.jivesoftware.smackx.jingle.packet.JingleContentInfo;
023import org.xmlpull.v1.XmlPullParser;
024
025/**
026 * Jingle Audio jmf-info provider
027 *
028 * @author Alvaro Saurin
029 */
030public class JingleContentInfoProvider implements PacketExtensionProvider {
031
032    /**
033     * Creates a new provider. ProviderManager requires that every
034     * PacketExtensionProvider has a public, no-argument constructor
035     */
036    public JingleContentInfoProvider() {
037        super();
038    }
039
040    public PacketExtension parseExtension(final XmlPullParser parser) throws Exception {
041        // This method must be overwritten by subclasses...
042        return null;
043    }
044
045    /**
046     * JingleDescription.Audio info provider
047     */
048    public static class Audio extends JingleContentInfoProvider {
049
050        private PacketExtension audioInfo;
051
052        /**
053         * Empty constructor.
054         */
055        public Audio() {
056            this(null);
057        }
058
059        /**
060         * Constructor with an audio info.
061         *
062         * @param audioInfo the jmf info
063         */
064        public Audio(final PacketExtension audioInfo) {
065            super();
066            this.audioInfo = audioInfo;
067        }
068
069        /**
070         * Parse a JingleDescription.Audio extension.
071         */
072        public PacketExtension parseExtension(final XmlPullParser parser)
073                throws Exception {
074            PacketExtension result = null;
075
076            if (audioInfo != null) {
077                result = audioInfo;
078            } else {
079                String elementName = parser.getName();
080
081                // Try to get an Audio content info
082                ContentInfo mi = ContentInfo.Audio.fromString(elementName);
083                if (mi != null) {
084                    result = new JingleContentInfo.Audio(mi);
085                }
086            }
087            return result;
088        }
089
090        // Sub-elements
091
092        public static class Busy extends Audio {
093            public Busy() {
094                super(new JingleContentInfo.Audio.Busy());
095            }
096        }
097
098        public static class Hold extends Audio {
099            public Hold() {
100                super(new JingleContentInfo.Audio.Hold());
101            }
102        }
103
104        public static class Mute extends Audio {
105            public Mute() {
106                super(new JingleContentInfo.Audio.Mute());
107            }
108        }
109
110        public static class Queued extends Audio {
111            public Queued() {
112                super(new JingleContentInfo.Audio.Queued());
113            }
114        }
115
116        public static class Ringing extends Audio {
117            public Ringing() {
118                super(new JingleContentInfo.Audio.Ringing());
119                        }
120                }
121        }
122}