Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to automatic register handler annotated with RegisterActionH... #292

Merged
merged 4 commits into from
Jul 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Copyright 2013 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.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.core.Ordered;

import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorClass;
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorMapImpl;
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorRegistry;
import com.gwtplatform.dispatch.server.actionhandlervalidator.LazyActionHandlerValidatorRegistry;
import com.gwtplatform.dispatch.server.spring.annotation.RegisterActionHandler;
import com.gwtplatform.dispatch.server.spring.utils.SpringUtils;

/**
* Annotation bean post processing to register ActionHadlers annotate
* with {@link RegisterActionHandler}.
*/
public class AnnotatedActionBeandHandlerRegistrator implements BeanPostProcessor, Ordered {
@Autowired
protected ApplicationContext applicationContext;

@Autowired
protected ActionHandlerValidatorRegistry actionHandlerValidatorRegistry;

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean instanceof ActionHandler<?, ?>) {
ActionHandler<?, ?> actionHandler = (ActionHandler<?, ?>) bean;
RegisterActionHandler registerHandler = bean.getClass().getAnnotation(RegisterActionHandler.class);
if (registerHandler != null) {
ActionHandlerValidatorClass actionHandlerValidatorClass = new ActionHandlerValidatorClass(
actionHandler.getClass(),registerHandler.validator());
SpringUtils.registerBean(applicationContext, new ActionHandlerValidatorMapImpl(
actionHandler.getActionType(), actionHandlerValidatorClass));
if (actionHandlerValidatorRegistry instanceof LazyActionHandlerValidatorRegistry) {
((LazyActionHandlerValidatorRegistry) actionHandlerValidatorRegistry)
.addActionHandlerValidatorClass(actionHandler.getActionType(), actionHandlerValidatorClass);
}
}
}

return bean;
}

@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
}

@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,18 @@
import com.gwtplatform.dispatch.server.RequestProvider;

/**
* @author Peter Simun
*/
@Component("dispatch")
public class DispatchServiceImpl extends AbstractDispatchServiceImpl implements HttpRequestHandler,
ServletContextAware {

private static final long serialVersionUID = 136176741488585959L;

private ServletContext servletContext;

@Autowired(required = false)
protected String securityCookieName;

private ServletContext servletContext;

@Autowired
public DispatchServiceImpl(final Logger logger, final Dispatch dispatch,
RequestProvider requestProvider) {
Expand Down
Loading