BindIQProvider.java

  1. /**
  2.  *
  3.  * Copyright © 2003-2007 Jive Software, 2014 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smack.provider;

  18. import java.io.IOException;

  19. import org.jivesoftware.smack.SmackException;
  20. import org.jivesoftware.smack.packet.Bind;
  21. import org.jxmpp.jid.FullJid;
  22. import org.jxmpp.jid.impl.JidCreate;
  23. import org.xmlpull.v1.XmlPullParser;
  24. import org.xmlpull.v1.XmlPullParserException;

  25. public class BindIQProvider extends IQProvider<Bind> {

  26.     @Override
  27.     public Bind parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException,
  28.                     SmackException {
  29.         String name;
  30.         Bind bind = null;
  31.         outerloop: while (true) {
  32.             int eventType = parser.next();
  33.             switch (eventType) {
  34.             case XmlPullParser.START_TAG:
  35.                 name = parser.getName();
  36.                 switch (name) {
  37.                 case "resource":
  38.                     bind = Bind.newSet(parser.nextText());
  39.                     break;
  40.                 case "jid":
  41.                     FullJid fullJid = JidCreate.fullFrom(parser.nextText());
  42.                     bind = Bind.newResult(fullJid);
  43.                     break;
  44.                 }
  45.                 break;
  46.             case XmlPullParser.END_TAG:
  47.                 if (parser.getDepth() == initialDepth) {
  48.                     break outerloop;
  49.                 }
  50.                 break;
  51.             }
  52.         }
  53.         return bind;
  54.     }

  55. }