com.gwtplatform.dispatch.server.guice.HandlerModule Maven / Gradle / Ivy
/**
* 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 Action}s to {@link ActionHandler}s and
* {@link ActionValidator}s. Your own Guice modules should extend this class.
*
* @author Christian Goudreau
* @author David Peterson
*/
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 Action}
* @param Type of {@link Result}
* @param actionClass Implementation of {@link Action} to link and bind
* @param handlerClass Implementation of {@link ActionHandler} to link and
* bind
*/
protected , R extends Result> void bindHandler(
Class actionClass, Class extends ActionHandler> handlerClass) {
bind(ActionHandlerValidatorMap.class).annotatedWith(
UniqueAnnotations.create()).toInstance(
new ActionHandlerValidatorMapImpl(actionClass,
new ActionHandlerValidatorClass(handlerClass,
DefaultActionValidator.class)));
}
/**
* @param Type of {@link Action}
* @param Type of {@link Result}
* @param actionClass Implementation of {@link Action} to link and bind
* @param handlerClass Implementation of {@link ActionHandler} to link and
* bind
* @param actionValidator Implementation of {@link ActionValidator} to link
* and bind
*/
protected , R extends Result> void bindHandler(
Class actionClass, Class extends ActionHandler> handlerClass,
Class extends ActionValidator> 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
*/
}