AbstractIqRequestHandler.java

  1. /**
  2.  *
  3.  * Copyright 2015 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.iqrequest;

  18. import org.jivesoftware.smack.packet.IQ;
  19. import org.jivesoftware.smack.packet.IQ.Type;

  20. /**
  21.  * Convenience class to create IQ requests handlers.
  22.  */
  23. public abstract class AbstractIqRequestHandler implements IQRequestHandler {

  24.     private final String element;
  25.     private final String namespace;
  26.     private final Type type;
  27.     private final Mode mode;

  28.     protected AbstractIqRequestHandler(String element, String namespace, Type type, Mode mode) {
  29.         switch (type) {
  30.         case set:
  31.         case get:
  32.             break;
  33.         default:
  34.             throw new IllegalArgumentException("Only get and set IQ type allowed");
  35.         }
  36.         this.element = element;
  37.         this.namespace = namespace;
  38.         this.type = type;
  39.         this.mode = mode;
  40.     }

  41.     @Override
  42.     public abstract IQ handleIQRequest(IQ iqRequest);

  43.     @Override
  44.     public Mode getMode() {
  45.         return mode;
  46.     }

  47.     @Override
  48.     public Type getType() {
  49.         return type;
  50.     }

  51.     @Override
  52.     public String getElement() {
  53.         return element;
  54.     }

  55.     @Override
  56.     public String getNamespace() {
  57.         return namespace;
  58.     }

  59. }