|
| 1 | +/** |
| 2 | + * Copyright 2011 ArcBees Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.gwtplatform.dispatch.server; |
| 18 | + |
| 19 | +import com.google.inject.AbstractModule; |
| 20 | +import com.google.inject.Singleton; |
| 21 | +import com.gwtplatform.dispatch.server.actionhandler.ActionHandler; |
| 22 | +import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorClass; |
| 23 | +import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorMap; |
| 24 | +import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorMapImpl; |
| 25 | +import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorRegistry; |
| 26 | +import com.gwtplatform.dispatch.server.actionvalidator.ActionValidator; |
| 27 | +import com.gwtplatform.dispatch.server.guice.DispatchImpl; |
| 28 | +import com.gwtplatform.dispatch.server.guice.actionhandlervalidator.ActionHandlerValidatorLinker; |
| 29 | +import com.gwtplatform.dispatch.server.guice.actionhandlervalidator.LazyActionHandlerValidatorRegistryImpl; |
| 30 | +import com.gwtplatform.dispatch.shared.Action; |
| 31 | +import com.gwtplatform.dispatch.shared.Result; |
| 32 | + |
| 33 | +public class ServiceModule extends AbstractModule { |
| 34 | + private final Class<? extends ActionValidator> actionValidator; |
| 35 | + |
| 36 | + public ServiceModule(Class<? extends ActionValidator> actionValidator) { |
| 37 | + this.actionValidator = actionValidator; |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + protected void configure() { |
| 42 | + bind(Dispatch.class).to(DispatchImpl.class); |
| 43 | + bind(ActionHandlerValidatorRegistry.class).to( |
| 44 | + LazyActionHandlerValidatorRegistryImpl.class).in(Singleton.class); |
| 45 | + |
| 46 | + bindHandler(SomeAction.class, HandlerThatThrowsActionException.class, actionValidator); |
| 47 | + requestStaticInjection(ActionHandlerValidatorLinker.class); |
| 48 | + } |
| 49 | + |
| 50 | + protected <A extends Action<R>, R extends Result> void bindHandler( |
| 51 | + Class<A> actionClass, Class<? extends ActionHandler<A, R>> handlerClass, |
| 52 | + Class<? extends ActionValidator> actionValidator) { |
| 53 | + |
| 54 | + bind(ActionHandlerValidatorMap.class).toInstance( |
| 55 | + new ActionHandlerValidatorMapImpl<A, R>(actionClass, |
| 56 | + new ActionHandlerValidatorClass<A, R>(handlerClass, actionValidator))); |
| 57 | + } |
| 58 | +} |
0 commit comments