All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dynamicextensionsalfresco.webscripts.HandlerMethods Maven / Gradle / Ivy

Go to download

Adds an OSGi container to alfresco repository supporting dynamic code reloading, classpath isolation and a bunch of other useful features

There is a newer version: 3.1.0
Show newest version
package com.github.dynamicextensionsalfresco.webscripts;

import com.github.dynamicextensionsalfresco.webscripts.annotations.Attribute;
import com.github.dynamicextensionsalfresco.webscripts.annotations.Before;
import com.github.dynamicextensionsalfresco.webscripts.annotations.ResponseTemplate;
import com.github.dynamicextensionsalfresco.webscripts.annotations.Uri;
import org.springframework.core.annotation.AnnotationUtils;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * Parameter object for specifying {@link Uri}, {@link Before} and {@link Attribute}-annotated Web Script handler
 * methods.
 * 
 * @author Laurens Fridael
 * 
 */
public class HandlerMethods {

	private final List beforeMethods = new ArrayList();

	private final List attributeMethods = new ArrayList();

	private Method uriMethod;

	private final List exceptionHandlerMethods = new ArrayList();

	public List getBeforeMethods() {
		return beforeMethods;
	}

	public List getAttributeMethods() {
		return attributeMethods;
	}

	public Method getUriMethod() {
		return uriMethod;
	}

	public List getExceptionHandlerMethods() {
		return exceptionHandlerMethods;
	}

	public List findExceptionHandlers(final Throwable exception) {
		final List handlerMethods = new ArrayList(1);
		for (final ExceptionHandlerMethod exceptionHandlerMethod : getExceptionHandlerMethods()) {
			if (exceptionHandlerMethod.canHandle(exception)) {
				handlerMethods.add(exceptionHandlerMethod.getMethod());
			}
		}
		return handlerMethods;
	}

	public boolean useResponseTemplate() {
		return (AnnotationUtils.findAnnotation(uriMethod, ResponseTemplate.class) != null);
	}

	public String getResponseTemplateName() {
		final ResponseTemplate responseTemplate = AnnotationUtils.findAnnotation(uriMethod, ResponseTemplate.class);
		return (responseTemplate != null ? responseTemplate.value() : null);
	}

	/**
	 * Creates a new instance for the specified {@link Uri}-annotated method.
	 * 
	 * @param uriMethod
	 */
	public HandlerMethods createForUriMethod(final Method uriMethod) {
		final HandlerMethods handlerMethods = new HandlerMethods();
		handlerMethods.beforeMethods.addAll(getBeforeMethods());
		handlerMethods.attributeMethods.addAll(getAttributeMethods());
		handlerMethods.uriMethod = uriMethod;
		handlerMethods.exceptionHandlerMethods.addAll(getExceptionHandlerMethods());
		return handlerMethods;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy