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.jingleold.provider;
018
019import org.jivesoftware.smack.packet.ExtensionElement;
020import org.jivesoftware.smack.packet.XmlEnvironment;
021import org.jivesoftware.smack.provider.ExtensionElementProvider;
022import org.jivesoftware.smack.xml.XmlPullParser;
023
024import org.jivesoftware.smackx.jingleold.media.ContentInfo;
025import org.jivesoftware.smackx.jingleold.packet.JingleContentInfo;
026
027import org.jxmpp.JxmppContext;
028
029/**
030 * Jingle Audio jmf-info provider.
031 *
032 * @author Alvaro Saurin
033 */
034public class JingleContentInfoProvider {
035
036    /**
037     * JingleDescription.Audio info provider.
038     */
039    public static class Audio extends ExtensionElementProvider<ExtensionElement> {
040
041        private final ExtensionElement audioInfo;
042
043        /**
044         * Empty constructor.
045         */
046        public Audio() {
047            this(null);
048        }
049
050        /**
051         * Constructor with an audio info.
052         *
053         * @param audioInfo the jmf info
054         */
055        public Audio(final ExtensionElement audioInfo) {
056            super();
057            this.audioInfo = audioInfo;
058        }
059
060        /**
061         * Parse a JingleDescription.Audio extension.
062         */
063        @Override
064        public ExtensionElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment, JxmppContext jxmppContext) {
065            ExtensionElement result = null;
066
067            if (audioInfo != null) {
068                result = audioInfo;
069            } else {
070                String elementName = parser.getName();
071
072                // Try to get an Audio content info
073                ContentInfo mi = ContentInfo.Audio.fromString(elementName);
074                if (mi != null) {
075                    result = new JingleContentInfo.Audio(mi);
076                }
077            }
078            return result;
079        }
080
081        // Sub-elements
082
083        public static class Busy extends Audio {
084            public Busy() {
085                super(new JingleContentInfo.Audio.Busy());
086            }
087        }
088
089        public static class Hold extends Audio {
090            public Hold() {
091                super(new JingleContentInfo.Audio.Hold());
092            }
093        }
094
095        public static class Mute extends Audio {
096            public Mute() {
097                super(new JingleContentInfo.Audio.Mute());
098            }
099        }
100
101        public static class Queued extends Audio {
102            public Queued() {
103                super(new JingleContentInfo.Audio.Queued());
104            }
105        }
106
107        public static class Ringing extends Audio {
108            public Ringing() {
109                super(new JingleContentInfo.Audio.Ringing());
110            }
111        }
112    }
113}