001/**
002 *
003 * Copyright 2003-2007 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 */
017
018package org.jivesoftware.smackx.muc.provider;
019
020import org.jivesoftware.smack.provider.IQProvider;
021import org.jivesoftware.smack.util.PacketParserUtils;
022import org.jivesoftware.smackx.muc.packet.MUCOwner;
023import org.xmlpull.v1.XmlPullParser;
024
025/**
026 * The MUCOwnerProvider parses MUCOwner packets. (@see MUCOwner)
027 * 
028 * @author Gaston Dombiak
029 */
030public class MUCOwnerProvider extends IQProvider<MUCOwner> {
031
032    @Override
033    public MUCOwner parse(XmlPullParser parser, int initialDepth)
034                    throws Exception {
035        MUCOwner mucOwner = new MUCOwner();
036        boolean done = false;
037        while (!done) {
038            int eventType = parser.next();
039            if (eventType == XmlPullParser.START_TAG) {
040                if (parser.getName().equals("item")) {
041                    mucOwner.addItem(MUCParserUtils.parseItem(parser));
042                }
043                else if (parser.getName().equals("destroy")) {
044                    mucOwner.setDestroy(MUCParserUtils.parseDestroy(parser));
045                }
046                // Otherwise, it must be a packet extension.
047                else {
048                    PacketParserUtils.addExtensionElement(mucOwner, parser);
049                }
050            }
051            else if (eventType == XmlPullParser.END_TAG) {
052                if (parser.getName().equals("query")) {
053                    done = true;
054                }
055            }
056        }
057
058        return mucOwner;
059    }
060}