001/**
002 *
003 * Copyright 2008 Jive Software.
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.smackx.commands;
018
019import java.lang.reflect.InvocationTargetException;
020
021/**
022 * A factory for creating ad-hoc command handlers. It's useful in cases where instantiation
023 * of a command is more complicated than just using the default constructor. For example,
024 * when arguments must be passed into the constructor or when using a dependency injection
025 * framework. When a factory isn't used, you can provide the AdHocCommandManager
026 * a Class object instead. For more details, see
027 * {@link AdHocCommandManager#registerCommand(String, String, AdHocCommandHandlerFactory)}.
028 *
029 * @author Matt Tucker
030 */
031public interface AdHocCommandHandlerFactory {
032
033    /**
034     * Returns a new instance of an ad-hoc command handler.
035     *
036     * @param node the node of the ad-hoc command.
037     * @param name the name of the ad-hoc command.
038     * @param sessionId the session ID of the ad-hoc command.
039     * @return a LocalCommand instance.
040     * @throws InstantiationException if creating an instance failed.
041     * @throws IllegalAccessException if creating an instance is not allowed.
042     * @throws InvocationTargetException if a reflection-based method or constructor invocation threw.
043     * @throws IllegalArgumentException if an illegal argument was given.
044     */
045    AdHocCommandHandler create(String node, String name, String sessionId)
046                    throws InstantiationException, IllegalAccessException, IllegalArgumentException,
047                    InvocationTargetException;
048
049}