From 9f722a52cac00ea4189c60056a84da4873b78ecf Mon Sep 17 00:00:00 2001 From: Emerson Oliveira Date: Mon, 5 Aug 2013 15:38:29 -0300 Subject: [PATCH] Adicionado javadoc para a classe br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor --- impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java index 5253a33..04dfc19 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java @@ -51,12 +51,65 @@ import javax.interceptor.InvocationContext; import org.slf4j.Logger; +import exception.custom.CustomException; + import br.gov.frameworkdemoiselle.DemoiselleException; import br.gov.frameworkdemoiselle.stereotype.Controller; import br.gov.frameworkdemoiselle.util.Beans; import br.gov.frameworkdemoiselle.util.NameQualifier; import br.gov.frameworkdemoiselle.util.ResourceBundle; +/** + *

+ * Intercepts some thrown exceptions, and calls the appropriate method. These interceptor works only in + * classes annotated with @Contoller. Above we discribe which kind of exception is intercepted and + * what is an appropriate method. + *

+ * To be interceptable, the thrown exception must be from a type which is annotated with + * @ApplicationException. + *

+ * An appropriate method must be annotated with @ExceptionHandler, and receive as parameter some + * exception that could be thrown for it's class (which have to be annotated with @ApplicationException). + * So, when this method is called, it's receive the thrown exception as parameter. In the same class shouldn't + * be more than one method annotated with @ExceptionHandler and receiving the same type of exception. + *

+ *

+ * The examples below shows how these interceptor works: + *

+ * + *

+ * + *
+ * @ApplicationException
+ * public class CustomException extends RuntimeException {
+ * }
+ * 
+ * @Controller
+ * public class CustomExceptionHandler {
+ * 
+ * 	public void throwException() {
+ *		throw new CustomException();
+ *	}
+ *	
+ *	@ExceptionHandler
+ *	public void handler(CustomException exception) {
+ *		...
+ *	}
+ *
+ * }
+ * 
+ *
+ * + *

+ * When the method throwException throw a CustomException, once CustomException is annotated + * with @ApplicationException and CustomExceptionHandle is annotated with @Controller, the interceptor will + * looking for some method (in CustomExceptionHandle) annotated with @ExceptionHandle and that receive a + * CustomException as parameter to call. In the case shown, the method handler is called when a + * CustomException is thrown. + *

+ * + * @author SERPRO + */ @Interceptor @Controller public class ExceptionHandlerInterceptor implements Serializable { @@ -68,7 +121,7 @@ public class ExceptionHandlerInterceptor implements Serializable { private static transient Logger logger; private final Map, Map, Method>> cache = new HashMap, Map, Method>>(); - + private boolean handleException(final Exception cause, final Object target) throws Exception { getLogger().info(getBundle().getString("handling-exception", cause.getClass().getCanonicalName())); -- libgit2 0.21.2