ItEr11S12ArquitecturaClientesItEr09S11: Moving links support classes to their own package and renaming several classes.
This commit is contained in:
parent
ef85e83794
commit
16591a86df
22 changed files with 107 additions and 124 deletions
|
|
@ -1,12 +0,0 @@
|
||||||
package org.navalplanner.web.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contract for {@link RedirectorRegistry} <br />
|
|
||||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
|
||||||
*/
|
|
||||||
public interface IRedirectorRegistry {
|
|
||||||
|
|
||||||
public abstract <T> Redirector<T> getRedirectorFor(
|
|
||||||
Class<T> klassWithLinkableMetadata);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
package org.navalplanner.web.common;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks a controller that redirects to the real controller <br />
|
|
||||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
|
||||||
*/
|
|
||||||
@Qualifier("linked")
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target( { ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE })
|
|
||||||
public @interface Linked {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.navalplanner.web.common;
|
package org.navalplanner.web.common.converters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts from an object to an string representation, and converts the object
|
* Converts from an object to an string representation, and converts the object
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.navalplanner.web.common;
|
package org.navalplanner.web.common.converters;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
package org.navalplanner.web.common;
|
package org.navalplanner.web.common.converters;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a Converter given a type <br />
|
* Retrieves a Converter given a type <br />
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.navalplanner.web.common;
|
package org.navalplanner.web.common.converters;
|
||||||
|
|
||||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||||
import org.navalplanner.business.resources.entities.Resource;
|
import org.navalplanner.business.resources.entities.Resource;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.navalplanner.web.common;
|
package org.navalplanner.web.common.entrypoints;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.navalplanner.web.common;
|
package org.navalplanner.web.common.entrypoints;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
|
|
@ -13,6 +13,6 @@ import java.lang.annotation.Target;
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
@Documented
|
@Documented
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface LinkToState {
|
public @interface EntryPoint {
|
||||||
public String[] value();
|
public String[] value();
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.navalplanner.web.common;
|
package org.navalplanner.web.common.entrypoints;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
|
|
@ -10,10 +10,10 @@ import java.lang.annotation.RetentionPolicy;
|
||||||
*/
|
*/
|
||||||
@Documented
|
@Documented
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface LinksDefiner {
|
public @interface EntryPoints {
|
||||||
|
|
||||||
public String page();
|
public String page();
|
||||||
|
|
||||||
public String beanName();
|
public String registerAs();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.navalplanner.web.common;
|
package org.navalplanner.web.common.entrypoints;
|
||||||
|
|
||||||
import org.zkoss.zk.ui.Execution;
|
import org.zkoss.zk.ui.Execution;
|
||||||
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package org.navalplanner.web.common.entrypoints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contract for {@link URLHandlerRegistry} <br />
|
||||||
|
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||||
|
*/
|
||||||
|
public interface IURLHandlerRegistry {
|
||||||
|
|
||||||
|
public abstract <T> URLHandler<T> getRedirectorFor(
|
||||||
|
Class<T> klassWithLinkableMetadata);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.navalplanner.web.common;
|
package org.navalplanner.web.common.entrypoints;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.navalplanner.web.common;
|
package org.navalplanner.web.common.entrypoints;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
|
@ -10,6 +10,7 @@ import java.util.List;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
@ -34,7 +35,7 @@ public class RedirectorSynthetiser implements BeanFactoryPostProcessor {
|
||||||
|
|
||||||
private final Class<?> pageInterface;
|
private final Class<?> pageInterface;
|
||||||
|
|
||||||
private Redirector<?> redirector;
|
private URLHandler<?> urlHandler;
|
||||||
|
|
||||||
private SynthetizedImplementation(
|
private SynthetizedImplementation(
|
||||||
ConfigurableListableBeanFactory beanFactory,
|
ConfigurableListableBeanFactory beanFactory,
|
||||||
|
|
@ -46,26 +47,25 @@ public class RedirectorSynthetiser implements BeanFactoryPostProcessor {
|
||||||
@Override
|
@Override
|
||||||
public Object invoke(Object proxy, Method method, Object[] args)
|
public Object invoke(Object proxy, Method method, Object[] args)
|
||||||
throws Throwable {
|
throws Throwable {
|
||||||
Redirector<?> redirector = getRedirector();
|
URLHandler<?> redirector = getHandler();
|
||||||
redirector.doRedirect(method.getName(), args);
|
redirector.doTransition(method.getName(), args);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Redirector<?> getRedirector() {
|
private URLHandler<?> getHandler() {
|
||||||
if (redirector != null)
|
if (urlHandler != null)
|
||||||
return redirector;
|
return urlHandler;
|
||||||
RedirectorRegistry redirectorRegistry = (RedirectorRegistry) beanFactory
|
URLHandlerRegistry registry = (URLHandlerRegistry) BeanFactoryUtils
|
||||||
.getBean(getSpringDefaultName(RedirectorRegistry.class),
|
.beanOfType(beanFactory, URLHandlerRegistry.class);
|
||||||
RedirectorRegistry.class);
|
urlHandler = registry.getRedirectorFor(pageInterface);
|
||||||
redirector = redirectorRegistry.getRedirectorFor(pageInterface);
|
return urlHandler;
|
||||||
return redirector;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postProcessBeanFactory(
|
public void postProcessBeanFactory(
|
||||||
ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||||
long elapsedTime = System.currentTimeMillis();
|
long elapsedTime = System.currentTimeMillis();
|
||||||
for (Class<?> pageInterface : findInterfacesMarkedWithLinkable()) {
|
for (Class<?> pageInterface : findInterfacesMarkedEntryPoints()) {
|
||||||
beanFactory.registerSingleton(getBeanName(pageInterface),
|
beanFactory.registerSingleton(getBeanName(pageInterface),
|
||||||
createRedirectorImplementationFor(beanFactory,
|
createRedirectorImplementationFor(beanFactory,
|
||||||
pageInterface));
|
pageInterface));
|
||||||
|
|
@ -73,10 +73,10 @@ public class RedirectorSynthetiser implements BeanFactoryPostProcessor {
|
||||||
elapsedTime = System.currentTimeMillis() - elapsedTime;
|
elapsedTime = System.currentTimeMillis() - elapsedTime;
|
||||||
LOG.debug("Took " + elapsedTime
|
LOG.debug("Took " + elapsedTime
|
||||||
+ " ms to search for interfaces annotated with "
|
+ " ms to search for interfaces annotated with "
|
||||||
+ LinksDefiner.class.getSimpleName());
|
+ EntryPoints.class.getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Class<?>> findInterfacesMarkedWithLinkable() {
|
private List<Class<?>> findInterfacesMarkedEntryPoints() {
|
||||||
List<Class<?>> result = new ArrayList<Class<?>>();
|
List<Class<?>> result = new ArrayList<Class<?>>();
|
||||||
PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
|
PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
|
||||||
CachingMetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(
|
CachingMetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(
|
||||||
|
|
@ -112,7 +112,7 @@ public class RedirectorSynthetiser implements BeanFactoryPostProcessor {
|
||||||
ClassMetadata classMetadata = metadataReader.getClassMetadata();
|
ClassMetadata classMetadata = metadataReader.getClassMetadata();
|
||||||
if (classMetadata.isInterface()
|
if (classMetadata.isInterface()
|
||||||
&& annotationMetadata.getAnnotationTypes().contains(
|
&& annotationMetadata.getAnnotationTypes().contains(
|
||||||
LinksDefiner.class.getName())) {
|
EntryPoints.class.getName())) {
|
||||||
Class<?> klass = Class
|
Class<?> klass = Class
|
||||||
.forName(classMetadata.getClassName());
|
.forName(classMetadata.getClassName());
|
||||||
if (klass.isInterface()) {
|
if (klass.isInterface()) {
|
||||||
|
|
@ -134,14 +134,8 @@ public class RedirectorSynthetiser implements BeanFactoryPostProcessor {
|
||||||
beanFactory, pageInterface));
|
beanFactory, pageInterface));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getSpringDefaultName(Class<?> klass) {
|
|
||||||
String simpleName = klass.getSimpleName();
|
|
||||||
return simpleName.substring(0, 1).toLowerCase()
|
|
||||||
+ simpleName.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getBeanName(Class<?> pageInterface) {
|
private static String getBeanName(Class<?> pageInterface) {
|
||||||
LinksDefiner annotation = pageInterface.getAnnotation(LinksDefiner.class);
|
EntryPoints annotation = pageInterface.getAnnotation(EntryPoints.class);
|
||||||
return annotation.beanName();
|
return annotation.registerAs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.navalplanner.web.common;
|
package org.navalplanner.web.common.entrypoints;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -13,22 +13,24 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.navalplanner.web.common.converters.Converter;
|
||||||
|
import org.navalplanner.web.common.converters.IConverterFactory;
|
||||||
import org.zkoss.zk.ui.Execution;
|
import org.zkoss.zk.ui.Execution;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <br />
|
* <br />
|
||||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||||
*/
|
*/
|
||||||
public class Redirector<T> {
|
public class URLHandler<T> {
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(Redirector.class);
|
private static final Log LOG = LogFactory.getLog(URLHandler.class);
|
||||||
|
|
||||||
private static class LinkMetadata {
|
private static class EntryPointMetadata {
|
||||||
private final Method method;
|
private final Method method;
|
||||||
|
|
||||||
private final LinkToState annotation;
|
private final EntryPoint annotation;
|
||||||
|
|
||||||
private LinkMetadata(Method method, LinkToState annotation) {
|
private EntryPointMetadata(Method method, EntryPoint annotation) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.annotation = annotation;
|
this.annotation = annotation;
|
||||||
}
|
}
|
||||||
|
|
@ -36,42 +38,42 @@ public class Redirector<T> {
|
||||||
|
|
||||||
private final ExecutorRetriever executorRetriever;
|
private final ExecutorRetriever executorRetriever;
|
||||||
|
|
||||||
private Map<String, LinkMetadata> metadata = new HashMap<String, LinkMetadata>();
|
private Map<String, EntryPointMetadata> metadata = new HashMap<String, EntryPointMetadata>();
|
||||||
|
|
||||||
private final String page;
|
private final String page;
|
||||||
|
|
||||||
private final IConverterFactory converterFactory;
|
private final IConverterFactory converterFactory;
|
||||||
|
|
||||||
public Redirector(IConverterFactory converterFactory,
|
public URLHandler(IConverterFactory converterFactory,
|
||||||
ExecutorRetriever executorRetriever, Class<T> interfaceDefiningLinks) {
|
ExecutorRetriever executorRetriever,
|
||||||
Validate.isTrue(interfaceDefiningLinks.isInterface());
|
Class<T> interfaceDefiningEntryPoints) {
|
||||||
|
Validate.isTrue(interfaceDefiningEntryPoints.isInterface());
|
||||||
this.converterFactory = converterFactory;
|
this.converterFactory = converterFactory;
|
||||||
this.executorRetriever = executorRetriever;
|
this.executorRetriever = executorRetriever;
|
||||||
LinksDefiner linkDefiner = interfaceDefiningLinks
|
EntryPoints entryPoints = interfaceDefiningEntryPoints
|
||||||
.getAnnotation(LinksDefiner.class);
|
.getAnnotation(EntryPoints.class);
|
||||||
Validate
|
Validate.notNull(entryPoints, EntryPoints.class.getName()
|
||||||
.notNull(linkDefiner, LinksDefiner.class.getName()
|
+ " annotation required on "
|
||||||
+ " annotation required on "
|
+ interfaceDefiningEntryPoints.getName());
|
||||||
+ interfaceDefiningLinks.getName());
|
this.page = entryPoints.page();
|
||||||
this.page = linkDefiner.page();
|
for (Method method : interfaceDefiningEntryPoints.getMethods()) {
|
||||||
for (Method method : interfaceDefiningLinks.getMethods()) {
|
EntryPoint entryPoint = method.getAnnotation(EntryPoint.class);
|
||||||
LinkToState linkToState = method.getAnnotation(LinkToState.class);
|
if (entryPoint != null) {
|
||||||
if (linkToState != null) {
|
metadata.put(method.getName(), new EntryPointMetadata(method,
|
||||||
metadata.put(method.getName(), new LinkMetadata(method,
|
entryPoint));
|
||||||
linkToState));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doRedirect(String methodName, Object... values) {
|
public void doTransition(String methodName, Object... values) {
|
||||||
if (!metadata.containsKey(methodName)) {
|
if (!metadata.containsKey(methodName)) {
|
||||||
LOG.error("Method " + methodName
|
LOG.error("Method " + methodName
|
||||||
+ "doesn't represent a state(It doesn't have a "
|
+ "doesn't represent a state(It doesn't have a "
|
||||||
+ LinkToState.class.getSimpleName()
|
+ EntryPoint.class.getSimpleName()
|
||||||
+ " annotation). Nothing will be done");
|
+ " annotation). Nothing will be done");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LinkMetadata linkableMetadata = metadata.get(methodName);
|
EntryPointMetadata linkableMetadata = metadata.get(methodName);
|
||||||
Class<?>[] types = linkableMetadata.method.getParameterTypes();
|
Class<?>[] types = linkableMetadata.method.getParameterTypes();
|
||||||
String[] parameterNames = linkableMetadata.annotation.value();
|
String[] parameterNames = linkableMetadata.annotation.value();
|
||||||
String[] stringRepresentations = new String[parameterNames.length];
|
String[] stringRepresentations = new String[parameterNames.length];
|
||||||
|
|
@ -102,28 +104,28 @@ public class Redirector<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public <S extends T> void applyTo(S controller) {
|
public <S extends T> void applyIfMatches(S controller) {
|
||||||
Execution current = executorRetriever.getCurrent();
|
Execution current = executorRetriever.getCurrent();
|
||||||
Map<String, String> matrixParams = MatrixParameters
|
Map<String, String> matrixParams = MatrixParameters
|
||||||
.extract((HttpServletRequest) current.getNativeRequest());
|
.extract((HttpServletRequest) current.getNativeRequest());
|
||||||
Set<String> matrixParamsNames = matrixParams.keySet();
|
Set<String> matrixParamsNames = matrixParams.keySet();
|
||||||
for (Entry<String, LinkMetadata> entry : metadata.entrySet()) {
|
for (Entry<String, EntryPointMetadata> entry : metadata.entrySet()) {
|
||||||
LinkMetadata linkMetadata = entry.getValue();
|
EntryPointMetadata entryPointMetadata = entry.getValue();
|
||||||
LinkToState linkToStateAnnotation = linkMetadata.annotation;
|
EntryPoint entryPointAnnotation = entryPointMetadata.annotation;
|
||||||
HashSet<String> requiredParams = new HashSet<String>(Arrays
|
HashSet<String> requiredParams = new HashSet<String>(Arrays
|
||||||
.asList(linkToStateAnnotation.value()));
|
.asList(entryPointAnnotation.value()));
|
||||||
if (matrixParamsNames.equals(requiredParams)) {
|
if (matrixParamsNames.equals(requiredParams)) {
|
||||||
Object[] arguments = retrieveArguments(matrixParams,
|
Object[] arguments = retrieveArguments(matrixParams,
|
||||||
linkToStateAnnotation, linkMetadata.method
|
entryPointAnnotation, entryPointMetadata.method
|
||||||
.getParameterTypes());
|
.getParameterTypes());
|
||||||
callMethod(controller, linkMetadata.method, arguments);
|
callMethod(controller, entryPointMetadata.method, arguments);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object[] retrieveArguments(Map<String, String> matrixParams,
|
private Object[] retrieveArguments(Map<String, String> matrixParams,
|
||||||
LinkToState linkToStateAnnotation, Class<?>[] parameterTypes) {
|
EntryPoint linkToStateAnnotation, Class<?>[] parameterTypes) {
|
||||||
Object[] result = new Object[parameterTypes.length];
|
Object[] result = new Object[parameterTypes.length];
|
||||||
for (int i = 0; i < parameterTypes.length; i++) {
|
for (int i = 0; i < parameterTypes.length; i++) {
|
||||||
Object argumentName = linkToStateAnnotation.value()[i];
|
Object argumentName = linkToStateAnnotation.value()[i];
|
||||||
|
|
@ -1,20 +1,21 @@
|
||||||
package org.navalplanner.web.common;
|
package org.navalplanner.web.common.entrypoints;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.navalplanner.web.common.converters.IConverterFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registry of {@link Redirector} <br />
|
* Registry of {@link URLHandler} <br />
|
||||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||||
public class RedirectorRegistry implements IRedirectorRegistry {
|
public class URLHandlerRegistry implements IURLHandlerRegistry {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ExecutorRetriever executorRetriever;
|
private ExecutorRetriever executorRetriever;
|
||||||
|
|
@ -22,12 +23,13 @@ public class RedirectorRegistry implements IRedirectorRegistry {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IConverterFactory converterFactory;
|
private IConverterFactory converterFactory;
|
||||||
|
|
||||||
private Map<Class<?>, Redirector> cached = new HashMap<Class<?>, Redirector>();;
|
private Map<Class<?>, URLHandler<?>> cached = new HashMap<Class<?>, URLHandler<?>>();;
|
||||||
|
|
||||||
public <T> Redirector<T> getRedirectorFor(Class<T> klassWithLinkableMetadata) {
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> URLHandler<T> getRedirectorFor(Class<T> klassWithLinkableMetadata) {
|
||||||
if (cached.containsKey(klassWithLinkableMetadata))
|
if (cached.containsKey(klassWithLinkableMetadata))
|
||||||
return cached.get(klassWithLinkableMetadata);
|
return (URLHandler<T>) cached.get(klassWithLinkableMetadata);
|
||||||
Redirector<T> result = new Redirector<T>(converterFactory,
|
URLHandler<T> result = new URLHandler<T>(converterFactory,
|
||||||
executorRetriever, klassWithLinkableMetadata);
|
executorRetriever, klassWithLinkableMetadata);
|
||||||
cached.put(klassWithLinkableMetadata, result);
|
cached.put(klassWithLinkableMetadata, result);
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -9,7 +9,7 @@ import java.util.Set;
|
||||||
import org.navalplanner.business.resources.entities.Resource;
|
import org.navalplanner.business.resources.entities.Resource;
|
||||||
import org.navalplanner.business.resources.entities.Worker;
|
import org.navalplanner.business.resources.entities.Worker;
|
||||||
import org.navalplanner.web.common.Util;
|
import org.navalplanner.web.common.Util;
|
||||||
import org.navalplanner.web.resources.worker.WorkerCRUDLinks;
|
import org.navalplanner.web.resources.worker.IWorkerCRUDControllerEntryPoints;
|
||||||
import org.zkoss.zk.ui.Component;
|
import org.zkoss.zk.ui.Component;
|
||||||
import org.zkoss.zk.ui.event.Event;
|
import org.zkoss.zk.ui.event.Event;
|
||||||
import org.zkoss.zk.ui.event.EventListener;
|
import org.zkoss.zk.ui.event.EventListener;
|
||||||
|
|
@ -34,7 +34,7 @@ public class CriterionWorkersController extends GenericForwardComposer {
|
||||||
|
|
||||||
private Button cancelListButton;
|
private Button cancelListButton;
|
||||||
|
|
||||||
private WorkerCRUDLinks workerCRUD;
|
private IWorkerCRUDControllerEntryPoints workerCRUD;
|
||||||
|
|
||||||
public void showList(Event event) {
|
public void showList(Event event) {
|
||||||
loadDataToList();
|
loadDataToList();
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,23 @@
|
||||||
package org.navalplanner.web.resources.worker;
|
package org.navalplanner.web.resources.worker;
|
||||||
|
|
||||||
import org.navalplanner.business.resources.entities.Worker;
|
import org.navalplanner.business.resources.entities.Worker;
|
||||||
import org.navalplanner.web.common.LinksDefiner;
|
import org.navalplanner.web.common.entrypoints.EntryPoint;
|
||||||
import org.navalplanner.web.common.LinkToState;
|
import org.navalplanner.web.common.entrypoints.EntryPoints;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contract for {@link WorkerCRUDController}. <br />
|
* Contract for {@link WorkerCRUDController}. <br />
|
||||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||||
*/
|
*/
|
||||||
@LinksDefiner(page = "/resources/worker/worker.zul", beanName = "workerCRUD")
|
@EntryPoints(page = "/resources/worker/worker.zul", registerAs = "workerCRUD")
|
||||||
public interface WorkerCRUDLinks {
|
public interface IWorkerCRUDControllerEntryPoints {
|
||||||
|
|
||||||
@LinkToState("edit")
|
@EntryPoint("edit")
|
||||||
public abstract void goToEditForm(Worker worker);
|
public abstract void goToEditForm(Worker worker);
|
||||||
|
|
||||||
@LinkToState("workRelationships")
|
@EntryPoint("workRelationships")
|
||||||
public abstract void goToWorkRelationshipsForm(Worker worker);
|
public abstract void goToWorkRelationshipsForm(Worker worker);
|
||||||
|
|
||||||
@LinkToState("create")
|
@EntryPoint("create")
|
||||||
public abstract void goToCreateForm();
|
public abstract void goToCreateForm();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -14,12 +14,12 @@ import org.navalplanner.business.resources.entities.Worker;
|
||||||
import org.navalplanner.business.resources.entities.WorkingRelationship;
|
import org.navalplanner.business.resources.entities.WorkingRelationship;
|
||||||
import org.navalplanner.business.resources.services.CriterionService;
|
import org.navalplanner.business.resources.services.CriterionService;
|
||||||
import org.navalplanner.web.common.IMessagesForUser;
|
import org.navalplanner.web.common.IMessagesForUser;
|
||||||
import org.navalplanner.web.common.IRedirectorRegistry;
|
|
||||||
import org.navalplanner.web.common.Level;
|
import org.navalplanner.web.common.Level;
|
||||||
import org.navalplanner.web.common.MessagesForUser;
|
import org.navalplanner.web.common.MessagesForUser;
|
||||||
import org.navalplanner.web.common.OnlyOneVisible;
|
import org.navalplanner.web.common.OnlyOneVisible;
|
||||||
import org.navalplanner.web.common.Redirector;
|
|
||||||
import org.navalplanner.web.common.Util;
|
import org.navalplanner.web.common.Util;
|
||||||
|
import org.navalplanner.web.common.entrypoints.IURLHandlerRegistry;
|
||||||
|
import org.navalplanner.web.common.entrypoints.URLHandler;
|
||||||
import org.zkoss.zk.ui.Component;
|
import org.zkoss.zk.ui.Component;
|
||||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||||
import org.zkoss.zul.api.Window;
|
import org.zkoss.zul.api.Window;
|
||||||
|
|
@ -29,7 +29,7 @@ import org.zkoss.zul.api.Window;
|
||||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||||
*/
|
*/
|
||||||
public class WorkerCRUDController extends GenericForwardComposer implements
|
public class WorkerCRUDController extends GenericForwardComposer implements
|
||||||
WorkerCRUDLinks {
|
IWorkerCRUDControllerEntryPoints {
|
||||||
|
|
||||||
private Window createWindow;
|
private Window createWindow;
|
||||||
|
|
||||||
|
|
@ -45,7 +45,7 @@ public class WorkerCRUDController extends GenericForwardComposer implements
|
||||||
|
|
||||||
private IWorkerModel workerModel;
|
private IWorkerModel workerModel;
|
||||||
|
|
||||||
private IRedirectorRegistry redirectorRegistry;
|
private IURLHandlerRegistry URLHandlerRegistry;
|
||||||
|
|
||||||
private OnlyOneVisible visibility;
|
private OnlyOneVisible visibility;
|
||||||
|
|
||||||
|
|
@ -179,9 +179,9 @@ public class WorkerCRUDController extends GenericForwardComposer implements
|
||||||
new WorkRelationshipsController(this.workerModel,this);
|
new WorkRelationshipsController(this.workerModel,this);
|
||||||
this.workRelationship.doAfterCompose(
|
this.workRelationship.doAfterCompose(
|
||||||
comp.getFellow("addWorkRelationshipWindow"));
|
comp.getFellow("addWorkRelationshipWindow"));
|
||||||
Redirector<WorkerCRUDLinks> redirector = redirectorRegistry
|
URLHandler<IWorkerCRUDControllerEntryPoints> handler = URLHandlerRegistry
|
||||||
.getRedirectorFor(WorkerCRUDLinks.class);
|
.getRedirectorFor(IWorkerCRUDControllerEntryPoints.class);
|
||||||
redirector.applyTo(this);
|
handler.applyIfMatches(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LocalizationsController createLocalizationsController(
|
private LocalizationsController createLocalizationsController(
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
required for "@Autowired")
|
required for "@Autowired")
|
||||||
-->
|
-->
|
||||||
<context:annotation-config />
|
<context:annotation-config />
|
||||||
<bean class="org.navalplanner.web.common.RedirectorSynthetiser"></bean>
|
<bean class="org.navalplanner.web.common.entrypoints.RedirectorSynthetiser"></bean>
|
||||||
|
|
||||||
<context:component-scan base-package="org.navalplanner.web"/>
|
<context:component-scan base-package="org.navalplanner.web"/>
|
||||||
</beans>
|
</beans>
|
||||||
|
|
@ -9,6 +9,7 @@ import org.junit.experimental.theories.DataPoint;
|
||||||
import org.junit.experimental.theories.Theories;
|
import org.junit.experimental.theories.Theories;
|
||||||
import org.junit.experimental.theories.Theory;
|
import org.junit.experimental.theories.Theory;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.navalplanner.web.common.entrypoints.MatrixParameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that {@link MatrixParameters} supports extracting several
|
* Tests that {@link MatrixParameters} supports extracting several
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import org.junit.experimental.theories.DataPoint;
|
||||||
import org.junit.experimental.theories.Theories;
|
import org.junit.experimental.theories.Theories;
|
||||||
import org.junit.experimental.theories.Theory;
|
import org.junit.experimental.theories.Theory;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.navalplanner.web.common.entrypoints.MatrixParameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that {@link MatrixParameters} support one parameter<br />
|
* Test that {@link MatrixParameters} support one parameter<br />
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import org.junit.experimental.theories.DataPoint;
|
||||||
import org.junit.experimental.theories.Theories;
|
import org.junit.experimental.theories.Theories;
|
||||||
import org.junit.experimental.theories.Theory;
|
import org.junit.experimental.theories.Theory;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.navalplanner.web.common.entrypoints.MatrixParameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that {@link MatrixParameters} supports matrix parameters
|
* Tests that {@link MatrixParameters} supports matrix parameters
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue