diff --git a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/DispatchImpl.java b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/DispatchImpl.java index 55def4c840..f752264fd9 100644 --- a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/DispatchImpl.java +++ b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/DispatchImpl.java @@ -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); diff --git a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/DispatchModule.java b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/DispatchModule.java index a816522193..1746e36dac 100644 --- a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/DispatchModule.java +++ b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/DispatchModule.java @@ -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 dispatchClass; private final Class lazyActionHandlerValidatorRegistryClass; @@ -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); } } diff --git a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/DispatchServiceImpl.java b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/DispatchServiceImpl.java index 855dbf9130..c580437b0c 100644 --- a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/DispatchServiceImpl.java +++ b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/DispatchServiceImpl.java @@ -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}") @@ -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); } @@ -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; } - } diff --git a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/HandlerModule.java b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/HandlerModule.java index 03ae181437..3c032bcdaf 100644 --- a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/HandlerModule.java +++ b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/HandlerModule.java @@ -31,7 +31,6 @@ @Import({DispatchModule.class}) public abstract class HandlerModule { - @Autowired protected ApplicationContext applicationContext; diff --git a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/HttpSessionSecurityCookieFilter.java b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/HttpSessionSecurityCookieFilter.java index 117851e6a3..eb5a9c3c46 100644 --- a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/HttpSessionSecurityCookieFilter.java +++ b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/HttpSessionSecurityCookieFilter.java @@ -24,7 +24,6 @@ import com.gwtplatform.dispatch.rpc.server.AbstractHttpSessionSecurityCookieFilter; public class HttpSessionSecurityCookieFilter extends AbstractHttpSessionSecurityCookieFilter { - public HttpSessionSecurityCookieFilter(String securityCookieName) { super(securityCookieName); } diff --git a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/LoggerFactoryBean.java b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/LoggerFactoryBean.java index 0e18e6a9db..3e95d1887e 100644 --- a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/LoggerFactoryBean.java +++ b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/LoggerFactoryBean.java @@ -21,7 +21,6 @@ import org.springframework.beans.factory.FactoryBean; public class LoggerFactoryBean implements FactoryBean { - private final Logger logger; public LoggerFactoryBean(Logger logger) { diff --git a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/SpringBeanProvider.java b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/SpringBeanProvider.java index c3e68ab432..6a0e16240e 100644 --- a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/SpringBeanProvider.java +++ b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/SpringBeanProvider.java @@ -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 extends CommonBindingDescriptor { - public SpringBindingDescriptorAdapter(Entry binding) { super(binding.getValue(), binding.getKey()); } @@ -54,7 +52,6 @@ public B getInstance(Class clazz) { @Override public Iterator> getBindings(Class clazz) { - List> result = new ArrayList>(); Map beansOfType = applicationContext.getBeansOfType(clazz); diff --git a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/actionhandlervalidator/LazyActionHandlerValidatorRegistryImpl.java b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/actionhandlervalidator/LazyActionHandlerValidatorRegistryImpl.java index f9311f9f37..514a497bdf 100644 --- a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/actionhandlervalidator/LazyActionHandlerValidatorRegistryImpl.java +++ b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/actionhandlervalidator/LazyActionHandlerValidatorRegistryImpl.java @@ -34,11 +34,10 @@ public class LazyActionHandlerValidatorRegistryImpl implements LazyActionHandlerValidatorRegistry, ApplicationContextAware { - private ApplicationContext applicationContext; - private final Map>, ActionHandlerValidatorClass, - ? extends Result>> actionHandlerValidatorClasses; + private final Map>, ActionHandlerValidatorClass, ? extends Result>> + actionHandlerValidatorClasses; private final Map>, ActionHandlerValidatorInstance> actionHandlerValidatorInstances; private final Map, ActionValidator> validators; @@ -65,14 +64,12 @@ public void clearActionHandlerValidators() { @SuppressWarnings("unchecked") @Override public , R extends Result> ActionHandlerValidatorInstance findActionHandlerValidator(A action) { - - ActionHandlerValidatorInstance actionHandlerValidatorInstance = actionHandlerValidatorInstances.get(action - .getClass()); + ActionHandlerValidatorInstance actionHandlerValidatorInstance = + actionHandlerValidatorInstances.get(action.getClass()); if (actionHandlerValidatorInstance == null) { ActionHandlerValidatorClass, ? extends Result> actionHandlerValidatorClass = - actionHandlerValidatorClasses.get(action - .getClass()); + actionHandlerValidatorClasses.get(action.getClass()); if (actionHandlerValidatorClass != null) { actionHandlerValidatorInstance = createInstance(actionHandlerValidatorClass); if (actionHandlerValidatorInstance != null) { @@ -93,9 +90,8 @@ public ActionValidator findActionValidator(Class acti @Override public , R extends Result> void removeActionHandlerValidatorClass(Class actionClass, ActionHandlerValidatorClass actionHandlerValidatorClass) { - - ActionHandlerValidatorClass oldActionHandlerValidatorClass = actionHandlerValidatorClasses.get( - actionClass); + ActionHandlerValidatorClass oldActionHandlerValidatorClass = + actionHandlerValidatorClasses.get(actionClass); if (oldActionHandlerValidatorClass == actionHandlerValidatorClass) { actionHandlerValidatorClasses.remove(actionClass); @@ -117,9 +113,8 @@ private boolean containValidator(ActionValidator actionValidator) { return false; } - private ActionHandlerValidatorInstance createInstance(ActionHandlerValidatorClass, - ? extends Result> actionHandlerValidatorClass) { - + private ActionHandlerValidatorInstance createInstance( + ActionHandlerValidatorClass, ? extends Result> actionHandlerValidatorClass) { ActionHandlerValidatorInstance actionHandlerValidatorInstance = null; ActionValidator actionValidator = findActionValidator(actionHandlerValidatorClass.getActionValidatorClass()); diff --git a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/configuration/DefaultModule.java b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/configuration/DefaultModule.java index 314a383a5a..beee319371 100644 --- a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/configuration/DefaultModule.java +++ b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/configuration/DefaultModule.java @@ -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 diff --git a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/request/DefaultRequestProvider.java b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/request/DefaultRequestProvider.java index ba85dd234c..6d3b8bfa02 100644 --- a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/request/DefaultRequestProvider.java +++ b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/request/DefaultRequestProvider.java @@ -23,8 +23,10 @@ import com.gwtplatform.dispatch.rpc.server.RequestProvider; +/** + * Request provider. + */ public class DefaultRequestProvider implements RequestProvider { - public DefaultRequestProvider() { } @@ -33,5 +35,4 @@ public DefaultRequestProvider() { public HttpServletRequest getServletRequest() { return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); } - } diff --git a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/utils/SpringUtils.java b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/utils/SpringUtils.java index 336fed1419..2e7925051c 100644 --- a/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/utils/SpringUtils.java +++ b/gwtp-core/gwtp-dispatch-rpc-server-spring/src/main/java/com/gwtplatform/dispatch/rpc/server/spring/utils/SpringUtils.java @@ -29,9 +29,7 @@ import org.springframework.web.context.support.AbstractRefreshableWebApplicationContext; public class SpringUtils { - - public static B getOrCreate(ApplicationContext applicationContext, - Class clazz) throws BeansException { + public static B getOrCreate(ApplicationContext applicationContext, Class clazz) throws BeansException { try { return getInstance(applicationContext, clazz); } catch (BeansException ex) { @@ -41,44 +39,38 @@ public static B getOrCreate(ApplicationContext applicationContext, } @SuppressWarnings("unchecked") - public static B instantiate(ApplicationContext applicationContext, - Class clazz) throws BeansException { - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory( - applicationContext); - return (B) beanFactory.createBean(clazz, - AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR, false); + public static B instantiate(ApplicationContext applicationContext, Class clazz) throws BeansException { + DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(applicationContext); + return (B) beanFactory.createBean(clazz, AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR, false); } public static 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 getInstance(ApplicationContext applicationContext, - Class clazz) throws BeansException { - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory( - applicationContext); + public static B getInstance(ApplicationContext applicationContext, Class clazz) throws BeansException { + DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(applicationContext); return beanFactory.getBean(clazz); } private static 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) { @@ -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; diff --git a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/annotations/NameToken.java b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/annotations/NameToken.java index fdcb770dd2..64439d1bd9 100644 --- a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/annotations/NameToken.java +++ b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/annotations/NameToken.java @@ -28,5 +28,5 @@ */ @Target(ElementType.TYPE) public @interface NameToken { - String value(); + String[] value(); } diff --git a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/PlaceImpl.java b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/PlaceImpl.java index 409f3b4100..a2cd8ec4fa 100644 --- a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/PlaceImpl.java +++ b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/PlaceImpl.java @@ -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 @@ -36,8 +34,17 @@ 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; @@ -45,22 +52,31 @@ public final boolean equals(Object o) { @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(); } - } diff --git a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/PlaceWithGatekeeper.java b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/PlaceWithGatekeeper.java index 584f2d80c9..aed40373f8 100644 --- a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/PlaceWithGatekeeper.java +++ b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/PlaceWithGatekeeper.java @@ -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; } diff --git a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/PlaceWithGatekeeperWithParams.java b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/PlaceWithGatekeeperWithParams.java index 2ee887d908..b4621656ae 100644 --- a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/PlaceWithGatekeeperWithParams.java +++ b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/PlaceWithGatekeeperWithParams.java @@ -17,19 +17,26 @@ package com.gwtplatform.mvp.client.proxy; /** - * Specialized {@link PlaceWithGatekeeper} which uses a {@link GatekeeperWithParams} - * and an array of parameters to protect the {@link Place}. - * - * @author Juan Carlos González + * Specialized {@link PlaceWithGatekeeper} which uses a {@link GatekeeperWithParams} and an array of parameters to + * protect the {@link Place}. */ public class PlaceWithGatekeeperWithParams extends PlaceImpl { - private final GatekeeperWithParams gatekeeper; private final String[] params; - public PlaceWithGatekeeperWithParams(String nameToken, GatekeeperWithParams gatekeeper, + public PlaceWithGatekeeperWithParams( + String nameToken, + GatekeeperWithParams gatekeeper, + String[] params) { + this(new String[] { nameToken }, gatekeeper, params); + } + + public PlaceWithGatekeeperWithParams( + String[] nameTokens, + GatekeeperWithParams gatekeeper, String[] params) { - super(nameToken); + super(nameTokens); + this.gatekeeper = gatekeeper; this.params = params; } diff --git a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/PlaceTokenRegistryGenerator.java b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/PlaceTokenRegistryGenerator.java index 8131419390..aaa87f8c07 100644 --- a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/PlaceTokenRegistryGenerator.java +++ b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/PlaceTokenRegistryGenerator.java @@ -65,7 +65,9 @@ private static Map findPlaceTokens(final GeneratorContext ge for (JClassType type : generatorContext.getTypeOracle().getTypes()) { NameToken nameTokenAnnotation = type.getAnnotation(NameToken.class); if (nameTokenAnnotation != null) { - placeTokens.put(nameTokenAnnotation.value(), type); + for (String nameToken : nameTokenAnnotation.value()) { + placeTokens.put(nameToken, type); + } } } diff --git a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/ProxyPlaceOutputter.java b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/ProxyPlaceOutputter.java index fbe28bd5a6..4250762a7e 100644 --- a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/ProxyPlaceOutputter.java +++ b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/ProxyPlaceOutputter.java @@ -34,21 +34,19 @@ /** * Proxy outputter for a proxy that is also a place. - * - * @author Philippe Beaudoin */ public class ProxyPlaceOutputter extends ProxyOutputterBase { - public static final String WRAPPED_CLASS_NAME = "WrappedProxy"; - private String nameToken; + private String[] nameTokens; private String getGatekeeperMethod; private String[] gatekeeperParams; private String title; private PresenterTitleMethod presenterTitleMethod; - public ProxyPlaceOutputter(TypeOracle oracle, + public ProxyPlaceOutputter( + TypeOracle oracle, TreeLogger logger, ClassCollection classCollection, GinjectorInspector ginjectorInspector, @@ -87,8 +85,8 @@ String getSuperclassName() { return ClassCollection.proxyPlaceImplClassName; } - public String getNameToken() { - return nameToken; + public String[] getNameToken() { + return nameTokens; } public String getGatekeeperParamsString() { @@ -107,9 +105,8 @@ public String getGatekeeperParamsString() { } @Override - void initSubclass(JClassType proxyInterface) - throws UnableToCompleteException { - findNameToken(proxyInterface); + void initSubclass(JClassType proxyInterface) throws UnableToCompleteException { + findNameTokens(proxyInterface); findGatekeeperMethod(proxyInterface); findGatekeeperParams(proxyInterface); findTitle(proxyInterface); @@ -124,50 +121,49 @@ void addSubclassImports(ClassSourceFileComposerFactory composerFactory) { } } - private void findNameToken(JClassType proxyInterface) - throws UnableToCompleteException { + private void findNameTokens(JClassType proxyInterface) throws UnableToCompleteException { NameToken nameTokenAnnotation = proxyInterface.getAnnotation(NameToken.class); if (nameTokenAnnotation == null) { logger.log(TreeLogger.ERROR, - "The proxy for '" + presenterInspector.getPresenterClassName() - + "' is a Place, but is not annotated with @' +" - + NameToken.class.getSimpleName() + ".", null); + String.format("The proxy for '%s' is a Place, but is not annotated with @' +%s.", + presenterInspector.getPresenterClassName(), NameToken.class.getSimpleName())); + throw new UnableToCompleteException(); + } + nameTokens = nameTokenAnnotation.value(); + if (nameTokens.length == 0) { + logger.log(TreeLogger.ERROR, + String.format("The proxy for '%s' is annotated with '@%s', but has no name token specified.", + presenterInspector.getPresenterClassName(), NameToken.class.getSimpleName())); throw new UnableToCompleteException(); } - nameToken = nameTokenAnnotation.value(); } - private void findGatekeeperMethod(JClassType proxyInterface) - throws UnableToCompleteException { + private void findGatekeeperMethod(JClassType proxyInterface) throws UnableToCompleteException { UseGatekeeper gatekeeperAnnotation = proxyInterface.getAnnotation(UseGatekeeper.class); if (gatekeeperAnnotation != null) { String gatekeeperName = gatekeeperAnnotation.value().getCanonicalName(); JClassType customGatekeeperClass = oracle.findType(gatekeeperName); if (customGatekeeperClass == null) { - logger.log(TreeLogger.ERROR, "The class '" + gatekeeperName - + "' provided to @" + UseGatekeeper.class.getSimpleName() - + " can't be found.", null); + logger.log(TreeLogger.ERROR, String.format("The class '%s' provided to @%s can't be found.", + gatekeeperName, UseGatekeeper.class.getSimpleName())); throw new UnableToCompleteException(); } if (!customGatekeeperClass.isAssignableTo(classCollection.gatekeeperClass)) { - logger.log(TreeLogger.ERROR, "The class '" + gatekeeperName - + "' provided to @" + UseGatekeeper.class.getSimpleName() - + " does not inherit from '" + ClassCollection.gatekeeperClassName + "'.", null); + logger.log(TreeLogger.ERROR, String.format("The class '%s' provided to @%s does not inherit from '%s'.", + gatekeeperName, UseGatekeeper.class.getSimpleName(), ClassCollection.gatekeeperClassName)); throw new UnableToCompleteException(); } // Find the appropriate get method in the Ginjector getGatekeeperMethod = ginjectorInspector.findGetMethod(customGatekeeperClass); if (getGatekeeperMethod == null) { logger.log(TreeLogger.ERROR, - "The Ginjector '" + ginjectorInspector.getGinjectorClassName() - + "' does not have a get() method returning '" - + gatekeeperName + "'. This is required when using @" - + UseGatekeeper.class.getSimpleName() + ".", null); + String.format("The Ginjector '%s' does not have a get() method returning '%s'. This is " + + "required when using @%s.", ginjectorInspector.getGinjectorClassName(), gatekeeperName, + UseGatekeeper.class.getSimpleName())); throw new UnableToCompleteException(); } } - if (getGatekeeperMethod == null - && proxyInterface.getAnnotation(NoGatekeeper.class) == null) { + if (getGatekeeperMethod == null && proxyInterface.getAnnotation(NoGatekeeper.class) == null) { // No Gatekeeper specified, see if there is a DefaultGatekeeper defined in the ginjector getGatekeeperMethod = ginjectorInspector.findAnnotatedGetMethod( classCollection.gatekeeperClass, DefaultGatekeeper.class, true); @@ -189,11 +185,10 @@ private void findTitle(JClassType proxyInterface) title = titleAnnotation.value(); } if (presenterTitleMethod != null && title != null) { - logger.log(TreeLogger.ERROR, "The proxy for '" + presenterInspector.getPresenterClassName() - + "' is annotated with @' +" + Title.class.getSimpleName() - + " and its presenter has a method annotated with @" - + TitleFunction.class.getSimpleName() + ". Only once can be used.", - null); + logger.log(TreeLogger.ERROR, String.format( + "The proxy for '%s' is annotated with @' +%s and its presenter has a method annotated with @%s. " + + "Only once can be used.", presenterInspector.getPresenterClassName(), + Title.class.getSimpleName(), TitleFunction.class.getSimpleName())); throw new UnableToCompleteException(); } } @@ -236,13 +231,23 @@ private void writeGetPlaceTitleMethodConstantText(SourceWriter writer) { writer.println("}"); } + protected String createInitNameTokens() { + StringBuilder sb = new StringBuilder(); + sb.append('{'); + for (String nameToken : nameTokens) { + sb.append('"').append(nameToken).append('"').append(','); + } + sb.setLength(sb.length() - 1); + sb.append('}'); + return sb.toString(); + } + @Override void writeSubclassDelayedBind(SourceWriter writer) { - writer.println(WRAPPED_CLASS_NAME + " wrappedProxy = GWT.create(" + WRAPPED_CLASS_NAME - + ".class);"); + writer.println(WRAPPED_CLASS_NAME + " wrappedProxy = GWT.create(" + WRAPPED_CLASS_NAME + ".class);"); writer.println("wrappedProxy.delayedBind( ginjector ); "); writer.println("setProxy(wrappedProxy); "); - writer.println("String nameToken = \"" + getNameToken() + "\"; "); + writer.println("String[] nameToken = " + createInitNameTokens() + "; "); writer.println("String[] gatekeeperParams = " + getGatekeeperParamsString() + ";"); writer.println("setPlace(" + getPlaceInstantiationString() + ");"); } diff --git a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/TabContentProxyPlaceOutputter.java b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/TabContentProxyPlaceOutputter.java index 9ac351deb0..3455bde5dd 100644 --- a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/TabContentProxyPlaceOutputter.java +++ b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/TabContentProxyPlaceOutputter.java @@ -55,7 +55,7 @@ public TabContentProxyPlaceOutputter(TypeOracle oracle, @Override void initSubclass(JClassType proxyInterface) throws UnableToCompleteException { proxyPlaceOutputter.init(proxyInterface); - nonLeafTabContentProxyOutputter.setNameToken(proxyPlaceOutputter.getNameToken()); + nonLeafTabContentProxyOutputter.setNameToken(proxyPlaceOutputter.getNameToken()[0]); nonLeafTabContentProxyOutputter.init(proxyInterface); } diff --git a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/AdminPresenterTestUtilGwt.java b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/AdminPresenterTestUtilGwt.java index 1c68b99dea..e456ecedb6 100644 --- a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/AdminPresenterTestUtilGwt.java +++ b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/AdminPresenterTestUtilGwt.java @@ -43,7 +43,7 @@ public interface MyView extends View { * Presenter's proxy. */ @ProxyStandard - @NameToken("admin") + @NameToken({"admin","selfService"}) public interface MyProxy extends ProxyPlace { } diff --git a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java index 3f9881e6b0..42c128129f 100644 --- a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java +++ b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java @@ -17,27 +17,29 @@ package com.gwtplatform.mvp.client.gwt.mvp; import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.junit.client.GWTTestCase; import com.gwtplatform.mvp.client.DelayedBindRegistry; +import com.gwtplatform.mvp.shared.proxy.PlaceRequest; +import com.gwtplatform.mvp.shared.proxy.PlaceRequest.Builder; /** * Integration test for various components of GWTP's MVP module. - * - * @author Philippe Beaudoin */ public class MvpGwtTestInSuite extends GWTTestCase { + GinjectorTestUtilGwt ginjector; + MainPresenterTestUtilGwt presenter; @Override public String getModuleName() { return "com.gwtplatform.mvp.MvpGwtTest"; } - GinjectorTestUtilGwt ginjector; - MainPresenterTestUtilGwt presenter; - @Override protected void gwtSetUp() throws Exception { super.gwtSetUp(); + InstantiationCounterTestUtilGwt.resetCounter(); ginjector = GWT.create(GinjectorTestUtilGwt.class); DelayedBindRegistry.bind(ginjector); @@ -48,6 +50,70 @@ protected void gwtSetUp() throws Exception { */ public void testShouldCreateOnlyOneGinjector() { ginjector.getPlaceManager().revealCurrentPlace(); + assertEquals(1, InstantiationCounterTestUtilGwt.getCounter()); } + + /** + * Verify multiple name tokens. + */ + public void testMultipleTokens() { + ginjector.getPlaceManager().revealDefaultPlace(); + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + assertTrue(ginjector.getMainPresenter().get().isVisible()); + assertFalse(ginjector.getAdminPresenter().get().isVisible()); + + revealAdmin(); + } + }); + + delayTestFinish(1000); + } + + private void revealAdmin() { + PlaceRequest placeRequest = new Builder().nameToken("admin").build(); + ginjector.getPlaceManager().revealPlace(placeRequest); + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + assertFalse(ginjector.getMainPresenter().get().isVisible()); + assertTrue(ginjector.getAdminPresenter().get().isVisible()); + + revealDefaultPlace(); + } + }); + } + + private void revealDefaultPlace() { + ginjector.getPlaceManager().revealDefaultPlace(); + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + assertTrue(ginjector.getMainPresenter().get().isVisible()); + assertFalse(ginjector.getAdminPresenter().get().isVisible()); + + revealSelfService(); + } + }); + } + + private void revealSelfService() { + PlaceRequest placeRequest = new Builder().nameToken("selfService").build(); + ginjector.getPlaceManager().revealPlace(placeRequest); + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + assertFalse(ginjector.getMainPresenter().get().isVisible()); + assertTrue(ginjector.getAdminPresenter().get().isVisible()); + + finishTest(); + } + }); + } } diff --git a/gwtp-core/gwtp-mvp-shared/src/main/java/com/gwtplatform/mvp/shared/proxy/PlaceRequest.java b/gwtp-core/gwtp-mvp-shared/src/main/java/com/gwtplatform/mvp/shared/proxy/PlaceRequest.java index 11ee75e4e7..9016525a80 100644 --- a/gwtp-core/gwtp-mvp-shared/src/main/java/com/gwtplatform/mvp/shared/proxy/PlaceRequest.java +++ b/gwtp-core/gwtp-mvp-shared/src/main/java/com/gwtplatform/mvp/shared/proxy/PlaceRequest.java @@ -166,6 +166,11 @@ public int hashCode() { return 11 * (nameToken.hashCode() + (params == null ? 0 : params.hashCode())); } + @Override + public String toString() { + return "PlaceRequest(nameToken=" + nameToken + ", params=" + params + ")"; + } + /** * Checks if this place request has the same name token as the one passed in. * diff --git a/gwtp-core/gwtp-mvp-shared/src/test/java/com/gwtplatform/mvp/shared/proxy/PlaceRequestTest.java b/gwtp-core/gwtp-mvp-shared/src/test/java/com/gwtplatform/mvp/shared/proxy/PlaceRequestTest.java index cadc90981a..483e95388e 100644 --- a/gwtp-core/gwtp-mvp-shared/src/test/java/com/gwtplatform/mvp/shared/proxy/PlaceRequestTest.java +++ b/gwtp-core/gwtp-mvp-shared/src/test/java/com/gwtplatform/mvp/shared/proxy/PlaceRequestTest.java @@ -87,4 +87,21 @@ public void shouldBuildRequestFromExistingRequest() { // then assertEquals(request, copyOfRequest); } + + @Test + public void testToString() { + // given + PlaceRequest request = new PlaceRequest.Builder() + .nameToken("nameToken") + .with("name1", "value1") + .with("name2", "value2") + .build(); + + // when + String result = request.toString(); + + // then + assertNotNull(result); + assertEquals("PlaceRequest(nameToken=nameToken, params={name1=value1, name2=value2})", result); + } } diff --git a/pom.xml b/pom.xml index 1a9b2ba249..a29f76204e 100644 --- a/pom.xml +++ b/pom.xml @@ -216,7 +216,7 @@ 1.7 - 2.5.1 + 2.6.0 1.0.0 2.7 2.3.2 @@ -231,7 +231,7 @@ 2.12 - 2.5.1 + 2.6.0 2.1.2 1.3.2 0.4.0 @@ -243,7 +243,7 @@ 1.8.8 3.0 1 - 16.0 + 16.0.1 4.0b3 1.0 2.5