Skip to content

Commit

Permalink
Merge pull request #448 from ArcBees/cv_multiple_nametokens
Browse files Browse the repository at this point in the history
Multiple nametokens, PlaceRequest.toString(), Updated POM versions

Former-commit-id: 9177dd4
  • Loading branch information
Chris-V committed Mar 7, 2014
2 parents 9441c92 + e23dd9f commit 68acb8c
Show file tree
Hide file tree
Showing 23 changed files with 240 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import com.gwtplatform.dispatch.rpc.server.AbstractDispatchImpl;
import com.gwtplatform.dispatch.rpc.server.actionhandlervalidator.ActionHandlerValidatorRegistry;

/**
* Dispatch implementation for spring.
*/
public class DispatchImpl extends AbstractDispatchImpl {

@Autowired
public DispatchImpl(ActionHandlerValidatorRegistry actionHandlerValidatorRegistry) {
super(actionHandlerValidatorRegistry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import com.gwtplatform.dispatch.rpc.server.spring.actionhandlervalidator.LazyActionHandlerValidatorRegistryImpl;
import com.gwtplatform.dispatch.rpc.server.spring.utils.SpringUtils;

/**
* Dispatch module spring configuration.
*/
public class DispatchModule {

private final Class<? extends Dispatch> dispatchClass;
private final Class<? extends ActionHandlerValidatorRegistry> lazyActionHandlerValidatorRegistryClass;

Expand Down Expand Up @@ -84,7 +86,6 @@ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderCon

@Bean
public Dispatch getDispatch() {
Dispatch instance = SpringUtils.getOrCreate(context, dispatchClass);
return instance;
return SpringUtils.getOrCreate(context, dispatchClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import com.gwtplatform.dispatch.rpc.server.Dispatch;
import com.gwtplatform.dispatch.rpc.server.RequestProvider;

/**
* Dispatch request to the handler.
*/
@Component("dispatch")
public class DispatchServiceImpl extends AbstractDispatchServiceImpl implements HttpRequestHandler,
ServletContextAware {

private static final long serialVersionUID = 136176741488585959L;

@Value("${securityCookieName:JSESSIONID}")
Expand All @@ -46,8 +48,7 @@ public class DispatchServiceImpl extends AbstractDispatchServiceImpl implements
private ServletContext servletContext;

@Autowired
public DispatchServiceImpl(final Logger logger, final Dispatch dispatch,
RequestProvider requestProvider) {
public DispatchServiceImpl(Logger logger, Dispatch dispatch, RequestProvider requestProvider) {
super(logger, dispatch, requestProvider);
}

Expand All @@ -63,13 +64,12 @@ public void handleRequest(HttpServletRequest request, HttpServletResponse respon
}

@Override
public void setServletContext(ServletContext arg0) {
this.servletContext = arg0;
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}

@Override
public ServletContext getServletContext() {
return servletContext;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

@Import({DispatchModule.class})
public abstract class HandlerModule {

@Autowired
protected ApplicationContext applicationContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.gwtplatform.dispatch.rpc.server.AbstractHttpSessionSecurityCookieFilter;

public class HttpSessionSecurityCookieFilter extends AbstractHttpSessionSecurityCookieFilter {

public HttpSessionSecurityCookieFilter(String securityCookieName) {
super(securityCookieName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.springframework.beans.factory.FactoryBean;

public class LoggerFactoryBean implements FactoryBean<Logger> {

private final Logger logger;

public LoggerFactoryBean(Logger logger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@
import com.gwtplatform.dispatch.rpc.server.spring.utils.SpringUtils;

public class SpringBeanProvider implements BeanProvider {

/**
* Adapter for transforming Guice Binding into BeanProvider implementation.
*/
public static class SpringBindingDescriptorAdapter<B> extends CommonBindingDescriptor<B> {

public SpringBindingDescriptorAdapter(Entry<String, B> binding) {
super(binding.getValue(), binding.getKey());
}
Expand All @@ -54,7 +52,6 @@ public <B> B getInstance(Class<B> clazz) {

@Override
public <B> Iterator<BindingDescriptor<B>> getBindings(Class<B> clazz) {

List<BindingDescriptor<B>> result = new ArrayList<BindingDescriptor<B>>();

Map<String, B> beansOfType = applicationContext.getBeansOfType(clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@

public class LazyActionHandlerValidatorRegistryImpl implements LazyActionHandlerValidatorRegistry,
ApplicationContextAware {

private ApplicationContext applicationContext;

private final Map<Class<? extends Action<?>>, ActionHandlerValidatorClass<? extends Action<?>,
? extends Result>> actionHandlerValidatorClasses;
private final Map<Class<? extends Action<?>>, ActionHandlerValidatorClass<? extends Action<?>, ? extends Result>>
actionHandlerValidatorClasses;
private final Map<Class<? extends Action<?>>, ActionHandlerValidatorInstance> actionHandlerValidatorInstances;
private final Map<Class<? extends ActionValidator>, ActionValidator> validators;

Expand All @@ -65,14 +64,12 @@ public void clearActionHandlerValidators() {
@SuppressWarnings("unchecked")
@Override
public <A extends Action<R>, R extends Result> ActionHandlerValidatorInstance findActionHandlerValidator(A action) {

ActionHandlerValidatorInstance actionHandlerValidatorInstance = actionHandlerValidatorInstances.get(action
.getClass());
ActionHandlerValidatorInstance actionHandlerValidatorInstance =
actionHandlerValidatorInstances.get(action.getClass());

if (actionHandlerValidatorInstance == null) {
ActionHandlerValidatorClass<? extends Action<?>, ? extends Result> actionHandlerValidatorClass =
actionHandlerValidatorClasses.get(action
.getClass());
actionHandlerValidatorClasses.get(action.getClass());
if (actionHandlerValidatorClass != null) {
actionHandlerValidatorInstance = createInstance(actionHandlerValidatorClass);
if (actionHandlerValidatorInstance != null) {
Expand All @@ -93,9 +90,8 @@ public ActionValidator findActionValidator(Class<? extends ActionValidator> acti
@Override
public <A extends Action<R>, R extends Result> void removeActionHandlerValidatorClass(Class<A> actionClass,
ActionHandlerValidatorClass<A, R> actionHandlerValidatorClass) {

ActionHandlerValidatorClass<?, ?> oldActionHandlerValidatorClass = actionHandlerValidatorClasses.get(
actionClass);
ActionHandlerValidatorClass<?, ?> oldActionHandlerValidatorClass =
actionHandlerValidatorClasses.get(actionClass);

if (oldActionHandlerValidatorClass == actionHandlerValidatorClass) {
actionHandlerValidatorClasses.remove(actionClass);
Expand All @@ -117,9 +113,8 @@ private boolean containValidator(ActionValidator actionValidator) {
return false;
}

private ActionHandlerValidatorInstance createInstance(ActionHandlerValidatorClass<? extends Action<?>,
? extends Result> actionHandlerValidatorClass) {

private ActionHandlerValidatorInstance createInstance(
ActionHandlerValidatorClass<? extends Action<?>, ? extends Result> actionHandlerValidatorClass) {
ActionHandlerValidatorInstance actionHandlerValidatorInstance = null;
ActionValidator actionValidator = findActionValidator(actionHandlerValidatorClass.getActionValidatorClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import com.gwtplatform.dispatch.rpc.server.spring.HttpSessionSecurityCookieFilter;
import com.gwtplatform.dispatch.rpc.server.spring.request.DefaultRequestProvider;

/**
* Default configuration for spring.
*/
public class DefaultModule {

private/* @Value("cookie") */ String securityCookieName;

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@

import com.gwtplatform.dispatch.rpc.server.RequestProvider;

/**
* Request provider.
*/
public class DefaultRequestProvider implements RequestProvider {

public DefaultRequestProvider() {
}

Expand All @@ -33,5 +35,4 @@ public DefaultRequestProvider() {
public HttpServletRequest getServletRequest() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
import org.springframework.web.context.support.AbstractRefreshableWebApplicationContext;

public class SpringUtils {

public static <B> B getOrCreate(ApplicationContext applicationContext,
Class<B> clazz) throws BeansException {
public static <B> B getOrCreate(ApplicationContext applicationContext, Class<B> clazz) throws BeansException {
try {
return getInstance(applicationContext, clazz);
} catch (BeansException ex) {
Expand All @@ -41,44 +39,38 @@ public static <B> B getOrCreate(ApplicationContext applicationContext,
}

@SuppressWarnings("unchecked")
public static <B> B instantiate(ApplicationContext applicationContext,
Class<B> clazz) throws BeansException {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(
applicationContext);
return (B) beanFactory.createBean(clazz,
AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR, false);
public static <B> B instantiate(ApplicationContext applicationContext, Class<B> clazz) throws BeansException {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(applicationContext);
return (B) beanFactory.createBean(clazz, AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR, false);
}

public static <B> void registerBean(ApplicationContext applicationContext,
B instance) throws BeansException {

if (applicationContext instanceof GenericApplicationContext) {
ConfigurableListableBeanFactory beanFactory = ((GenericApplicationContext) applicationContext)
.getBeanFactory();
ConfigurableListableBeanFactory beanFactory =
((GenericApplicationContext) applicationContext).getBeanFactory();
beanFactory.registerSingleton(generateName(beanFactory, createBeanDefinition(instance)), instance);
} else if (applicationContext instanceof AbstractRefreshableWebApplicationContext) {
ConfigurableListableBeanFactory beanFactory = ((AbstractRefreshableWebApplicationContext)
applicationContext).getBeanFactory();
ConfigurableListableBeanFactory beanFactory =
((AbstractRefreshableWebApplicationContext) applicationContext).getBeanFactory();
beanFactory.registerSingleton(generateName(beanFactory, createBeanDefinition(instance)), instance);
}
}

public static <B> B getInstance(ApplicationContext applicationContext,
Class<B> clazz) throws BeansException {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(
applicationContext);
public static <B> B getInstance(ApplicationContext applicationContext, Class<B> clazz) throws BeansException {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(applicationContext);
return beanFactory.getBean(clazz);
}

private static <B> RootBeanDefinition createBeanDefinition(B instance) {
RootBeanDefinition bd = new RootBeanDefinition(instance.getClass(),
AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR, false);
RootBeanDefinition bd = new RootBeanDefinition(instance.getClass(), AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR,
false);
bd.setScope(BeanDefinition.SCOPE_SINGLETON);
return bd;
}

private static String generateName(ConfigurableListableBeanFactory registry,
RootBeanDefinition definition) {
private static String generateName(ConfigurableListableBeanFactory registry, RootBeanDefinition definition) {
String generatedBeanName = definition.getBeanClassName();
if (generatedBeanName == null) {
if (definition.getParentName() != null) {
Expand All @@ -89,8 +81,8 @@ private static String generateName(ConfigurableListableBeanFactory registry,
}
if (!StringUtils.hasText(generatedBeanName)) {
throw new BeanDefinitionStoreException(
"Unnamed bean definition specifies neither "
+ "'class' nor 'parent' nor 'factory-bean' - can't generate bean name");
"Unnamed bean definition specifies neither 'class' nor 'parent' nor 'factory-bean' - can't " +
"generate bean name");
}

String id = generatedBeanName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
*/
@Target(ElementType.TYPE)
public @interface NameToken {
String value();
String[] value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@

package com.gwtplatform.mvp.client.proxy;

import java.util.Arrays;

import com.gwtplatform.mvp.shared.proxy.PlaceRequest;

/**
* @author Philippe Beaudoin
*/
public class PlaceImpl implements Place {
private final String[] nameTokens;

private final String nameToken;

public PlaceImpl(String nameToken) {
this.nameToken = nameToken;
public PlaceImpl(String... nameTokens) {
this.nameTokens = nameTokens;
}

@Override
Expand All @@ -36,31 +34,49 @@ public boolean canReveal() {

@Override
public final boolean equals(Object o) {
if (o instanceof PlaceImpl) {
PlaceImpl place = (PlaceImpl) o;
return Arrays.equals(nameTokens, place.nameTokens);
}
if (o instanceof Place) {
Place place = (Place) o;
for (String nameToken : nameTokens) {
if (nameToken.equals(place.getNameToken())) {
return true;
}
}
return getNameToken().equals(place.getNameToken());
}
return false;
}

@Override
public String getNameToken() {
return nameToken;
return nameTokens[0];
}

public String[] getNameTokens() {
return nameTokens;
}

@Override
public final int hashCode() {
return 17 * getNameToken().hashCode();
return 17 * Arrays.hashCode(nameTokens);
}

@Override
public final boolean matchesRequest(PlaceRequest request) {
return request.matchesNameToken(getNameToken());
for (String nameToken : nameTokens) {
if (request.matchesNameToken(nameToken)) {
return true;
}
}

return false;
}

@Override
public final String toString() {
return getNameToken();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@

package com.gwtplatform.mvp.client.proxy;

/**
* @author Philippe Beaudoin
*/
public class PlaceWithGatekeeper extends PlaceImpl {

private final Gatekeeper gatekeeper;

public PlaceWithGatekeeper(String nameToken, Gatekeeper gatekeeper) {
super(nameToken);
public PlaceWithGatekeeper(
String nameToken,
Gatekeeper gatekeeper) {
this(new String[] { nameToken }, gatekeeper);
}

public PlaceWithGatekeeper(
String[] nameTokens,
Gatekeeper gatekeeper) {
super(nameTokens);

this.gatekeeper = gatekeeper;
}

Expand Down
Loading

0 comments on commit 68acb8c

Please sign in to comment.