001/**
002 *
003 * Copyright 2015-2021 Florian Schmaus
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.smack.iqrequest;
018
019import org.jivesoftware.smack.packet.IQ;
020
021/**
022 * Convenience class to create IQ requests handlers.
023 */
024public abstract class AbstractIqRequestHandler implements IQRequestHandler {
025
026    private final String element;
027    private final String namespace;
028    private final IQ.Type type;
029    private final Mode mode;
030
031    protected AbstractIqRequestHandler(String element, String namespace, IQ.Type type, Mode mode) {
032        switch (type) {
033        case set:
034        case get:
035            break;
036        default:
037            throw new IllegalArgumentException("Only get and set IQ type allowed");
038        }
039        this.element = element;
040        this.namespace = namespace;
041        this.type = type;
042        this.mode = mode;
043    }
044
045    @Override
046    public abstract IQ handleIQRequest(IQ iqRequest);
047
048    @Override
049    public Mode getMode() {
050        return mode;
051    }
052
053    @Override
054    public IQ.Type getType() {
055        return type;
056    }
057
058    @Override
059    public String getElement() {
060        return element;
061    }
062
063    @Override
064    public String getNamespace() {
065        return namespace;
066    }
067
068}