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