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