com.github.dynamicextensionsalfresco.webscripts.arguments.HandlerMethodArgumentsResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of annotations-runtime Show documentation
Show all versions of annotations-runtime Show documentation
Adds an OSGi container to alfresco repository supporting dynamic code reloading, classpath isolation and a bunch of other useful features
package com.github.dynamicextensionsalfresco.webscripts.arguments;
import com.github.dynamicextensionsalfresco.webscripts.MessageConverterRegistry;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
import org.springframework.util.Assert;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Strategy for resolving handler method arguments.
*
* @author Laurens Fridael
* @author Laurent Van der Linden
* @see ArgumentResolver
*/
public class HandlerMethodArgumentsResolver implements ApplicationContextAware {
/* Dependencies */
private StringValueConverter stringValueConverter;
private MessageConverterRegistry messageConverterRegistry;
private BundleContext bundleContext;
/* Configuration */
private List> argumentResolvers;
private final Map> argumentResolverCache = new ConcurrentHashMap>();
private final ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
private ServiceTracker resolverTracker;
private ApplicationContext applicationContext;
/* Main Operations */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void initializeArgumentResolvers() {
argumentResolvers = new ArrayList>();
argumentResolvers.add((ArgumentResolver) new RequestBodyArgumentResolver(this.messageConverterRegistry));
argumentResolvers.add((ArgumentResolver) new RequestParamArgumentResolver(getStringValueConverter()));
argumentResolvers.add((ArgumentResolver) new UriVariableArgumentResolver(getStringValueConverter()));
argumentResolvers.add((ArgumentResolver) new AttributeArgumentResolver());
argumentResolvers.add((ArgumentResolver) new ModelArgumentResolver());
argumentResolvers.add((ArgumentResolver) new ExceptionArgumentResolver());
argumentResolvers.add((ArgumentResolver) new HeaderArgumentResolver());
argumentResolvers.add((ArgumentResolver) new ContentArgumentResolver());
argumentResolvers.add((ArgumentResolver) new CommandArgumentResolver());
argumentResolvers.add((ArgumentResolver) new FileFieldArgumentResolver());
argumentResolvers.add((ArgumentResolver) new WebScriptRequestArgumentResolver());
argumentResolvers.add((ArgumentResolver) new WebScriptResponseArgumentResolver());
argumentResolvers.add((ArgumentResolver) new WebScriptSessionArgumentResolver());
argumentResolvers.add((ArgumentResolver) new HttpServletRequestArgumentResolver());
argumentResolvers.add((ArgumentResolver) new HttpServletResponseArgumentResolver());
argumentResolvers.add((ArgumentResolver) new JsonObjectArgumentResolver());
if (bundleContext != null) {
resolverTracker = new ServiceTracker(bundleContext, ArgumentResolver.class, null);
resolverTracker.open(true);
}
}
/**
* Resolves the arguments of the given handler method.
*
* @param method
* The handler method.
* @param handler
* The handler itself.
* @param request
* @param response
* @return The arguments to invoke handlerMethod with.
*/
public Object[] resolveHandlerMethodArguments(Method method, final Object handler, final WebScriptRequest request,
final WebScriptResponse response) {
Assert.notNull(method, "Method cannot be null.");
Assert.notNull(request, "Request cannot be null.");
Assert.notNull(response, "Response cannot be null.");
final Class>[] parameterTypes = method.getParameterTypes();
final Object[] arguments = new Object[parameterTypes.length];
if (AopUtils.isAopProxy(handler)) {
method = AopUtils.getMostSpecificMethod(method, AopUtils.getTargetClass(handler));
}
final Annotation[][] parameterAnnotations = method.getParameterAnnotations();
final String[] methodParameterNames = parameterNameDiscoverer.getParameterNames(method);
for (int index = 0; index < parameterTypes.length; index++) {
Annotation mappingAnnotation = null;
ArgumentResolver
© 2015 - 2025 Weber Informatics LLC | Privacy Policy