All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gwtplatform.dispatch.server.guice.HandlerModule Maven / Gradle / Ivy

There is a newer version: 1.6
Show newest version
/**
 * Copyright 2011 ArcBees Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.gwtplatform.dispatch.server.guice;

import com.google.inject.AbstractModule;
import com.google.inject.internal.UniqueAnnotations;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorClass;
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorMap;
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorMapImpl;
import com.gwtplatform.dispatch.server.actionvalidator.ActionValidator;
import com.gwtplatform.dispatch.server.guice.actionvalidator.DefaultActionValidator;
import com.gwtplatform.dispatch.shared.Action;
import com.gwtplatform.dispatch.shared.Result;

/**
 * Base module that will bind {@link com.gwtplatform.dispatch.shared.Action}s to
 * {@link com.gwtplatform.dispatch.server.actionhandler.ActionHandler}s and
 * {@link com.gwtplatform.dispatch.server.actionvalidator.ActionValidator}s. Your own Guice modules should extend this
 * class.
 *
 * @deprecated Please use {@link com.gwtplatform.dispatch.rpc.server.guice.HandlerModule}.
 */
@Deprecated
public abstract class HandlerModule extends AbstractModule {

    private final DispatchModule dispatchModule;

    /**
     * Constructs a HandlerModule that uses the {@link DispatchModule} with
     * default configuration.
     */
    public HandlerModule() {
        this.dispatchModule = new DispatchModule();
    }

    /**
     * Constructs a {@link HandlerModule} that uses the {@link DispatchModule}
     * with a custom configuration.
     *
     * @param dispatchModule The custom configured {@link DispatchModule}
     */
    public HandlerModule(DispatchModule dispatchModule) {
        this.dispatchModule = dispatchModule;
    }

    /**
     * @param           Type of {@link com.gwtplatform.dispatch.shared.Action}
     * @param           Type of {@link com.gwtplatform.dispatch.shared.Result}
     * @param actionClass  Implementation of {@link com.gwtplatform.dispatch.shared.Action} to link and bind
     * @param handlerClass Implementation of {@link com.gwtplatform.dispatch.server.actionhandler.ActionHandler} to link
     *                     and
     *                     bind
     */
    protected , R extends Result> void bindHandler(
            Class actionClass, Class> handlerClass) {
        bind(ActionHandlerValidatorMap.class).annotatedWith(
                UniqueAnnotations.create()).toInstance(
                new ActionHandlerValidatorMapImpl(actionClass,
                        new ActionHandlerValidatorClass(handlerClass,
                                DefaultActionValidator.class)));
    }

    /**
     * @param              Type of {@link com.gwtplatform.dispatch.shared.Action}
     * @param              Type of {@link com.gwtplatform.dispatch.shared.Result}
     * @param actionClass     Implementation of {@link com.gwtplatform.dispatch.shared.Action} to link and bind
     * @param handlerClass    Implementation of {@link com.gwtplatform.dispatch.server.actionhandler.ActionHandler} to
     *                        link and bind
     * @param actionValidator Implementation of {@link com.gwtplatform.dispatch.server.actionvalidator.ActionValidator}
     *                        to link and bind
     */
    protected , R extends Result> void bindHandler(
            Class actionClass, Class> handlerClass,
            Class actionValidator) {
        bind(ActionHandlerValidatorMap.class).annotatedWith(
                UniqueAnnotations.create()).toInstance(
                new ActionHandlerValidatorMapImpl(
                        actionClass,
                        new ActionHandlerValidatorClass(handlerClass, actionValidator)));
    }

    @Override
    protected final void configure() {
        install(dispatchModule);
        configureHandlers();
    }

    /**
     * Override this method to configure your handlers. Use calls to
     * {@link #bindHandler} to register actions that do not need any specific
     * security validation.
     */
    protected abstract void configureHandlers();

    /**
     * Override this method to
     */
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy