LegacyIQProvider.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  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 java.text.ParseException;

  20. import org.jivesoftware.smack.packet.IQ;
  21. import org.jivesoftware.smack.packet.IqData;
  22. import org.jivesoftware.smack.packet.XmlEnvironment;
  23. import org.jivesoftware.smack.parsing.SmackParsingException;
  24. import org.jivesoftware.smack.util.ParserUtils;
  25. import org.jivesoftware.smack.xml.XmlPullParser;
  26. import org.jivesoftware.smack.xml.XmlPullParserException;

  27. /**
  28.  * <p>
  29.  * <b>Deprecation Notice:</b> This class is deprecated, use {@link IqProvider} instead.
  30.  * </p>
  31.  * An abstract class for parsing custom IQ packets. Each IQProvider must be registered with
  32.  * the ProviderManager class for it to be used. Every implementation of this
  33.  * abstract class <b>must</b> have a public, no-argument constructor.
  34.  *
  35.  * @author Matt Tucker
  36.  * @deprecated Use {@link IqProvider} instead
  37.  */
  38. @Deprecated
  39. // TODO: Remove in Smack 4.6.
  40. public abstract class LegacyIQProvider<I extends IQ> extends IqProvider<I> {

  41.     public final I parse(XmlPullParser parser) throws IOException, XmlPullParserException, SmackParsingException {
  42.         return parse(parser, (XmlEnvironment) null);
  43.     }

  44.     public final I parse(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws IOException, XmlPullParserException, SmackParsingException {
  45.         // XPP3 calling convention assert: Parser should be at start tag
  46.         ParserUtils.assertAtStartTag(parser);

  47.         final int initialDepth = parser.getDepth();
  48.         final XmlEnvironment xmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);

  49.         I e = wrapExceptions(() -> parse(parser, initialDepth, xmlEnvironment));

  50.         // XPP3 calling convention assert: Parser should be at end tag of the consumed/parsed element
  51.         ParserUtils.forwardToEndTagOfDepth(parser, initialDepth);
  52.         return e;
  53.     }

  54.     @Override
  55.     public final I parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment)
  56.                     throws XmlPullParserException, IOException, SmackParsingException, ParseException {
  57.         // Old-style IQ parsers do not need IqData.
  58.         return parse(parser, initialDepth, xmlEnvironment);
  59.     }

  60.     public abstract I parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
  61.                     throws XmlPullParserException, IOException, SmackParsingException, ParseException;

  62. }