Permalink
Browse files

Fixing tests and checkstyle

Next is to add the tests for Catch
  • Loading branch information...
1 parent 46285dc commit 262571572a1ec0ae608fe74250e8e6367b6fbae7 @LightGuard committed Apr 10, 2012
@@ -28,16 +28,17 @@
import java.util.Set;
/**
- * Comparator to sort exception handlers according qualifier ({@link org.apache.deltaspike.core.api.exception.control.BeforeHandles} first), ordinal
+ * Comparator to sort exception handlers according qualifier
+ * ({@link org.apache.deltaspike.core.api.exception.control.BeforeHandles} first), ordinal
* (highest to lowest) and finally hierarchy (least to most specific).
*/
-@SuppressWarnings({"MethodWithMoreThanThreeNegations"})
+@SuppressWarnings({ "MethodWithMoreThanThreeNegations" })
public final class ExceptionHandlerComparator implements Comparator<HandlerMethod<?>>
{
-
/**
* {@inheritDoc}
*/
+ @Override
public int compare(HandlerMethod<?> lhs, HandlerMethod<?> rhs)
{
if (lhs.equals(rhs))
@@ -23,7 +23,7 @@
import org.apache.deltaspike.core.api.exception.control.ExceptionStack;
import org.apache.deltaspike.core.api.exception.control.ExceptionToCatch;
import org.apache.deltaspike.core.api.exception.control.HandlerMethod;
-import org.apache.deltaspike.core.api.exception.control.HandlerMethodStorage;
+import org.apache.deltaspike.core.impl.exception.control.extension.CatchExtension;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
@@ -55,12 +55,12 @@
*
* @param eventException exception to be invoked
* @param bm active bean manager
- * @param handlerMethodStorage catch handlerMethodStorage instance to obtain handlers
* @throws Throwable If a handler requests the exception to be re-thrown.
*/
+ // CHECKSTYLE:OFF
@SuppressWarnings({"unchecked", "MethodWithMultipleLoops", "ThrowableResultOfMethodCallIgnored"})
- public void executeHandlers(@Observes @Any ExceptionToCatch eventException, final BeanManager bm,
- HandlerMethodStorage handlerMethodStorage) throws Throwable
+ // CHECKSTYLE:ON
+ public void executeHandlers(@Observes @Any ExceptionToCatch eventException, final BeanManager bm) throws Throwable
{
log.entering(ExceptionHandlerDispatch.class.getName(), "executeHandlers", eventException.getException());
@@ -69,6 +69,8 @@ public void executeHandlers(@Observes @Any ExceptionToCatch eventException, fina
Throwable throwException = null;
+ final HandlerMethodStorage handlerMethodStorage = CatchExtension.createStorage();
+
try
{
ctx = bm.createCreationalContext(null);
@@ -79,7 +81,7 @@ public void executeHandlers(@Observes @Any ExceptionToCatch eventException, fina
bm.fireEvent(stack); // Allow for modifying the exception stack
- inbound_cause:
+ inbound_cause:
while (stack.getCurrent() != null)
{
this.exceptionStack = stack;
@@ -126,13 +128,16 @@ public void executeHandlers(@Observes @Any ExceptionToCatch eventException, fina
break;
case THROW:
throwException = breadthFirstEvent.getThrowNewException();
+ break;
+ default:
+ throw new IllegalStateException("Unexpected enum type " + breadthFirstEvent.getFlow());
}
}
}
final Collection<HandlerMethod<? extends Throwable>> handlersForException =
handlerMethodStorage.getHandlersForException(stack.getCurrent().getClass(),
- bm, eventException.getQualifiers(), false);
+ bm, eventException.getQualifiers(), false);
final List<HandlerMethod<? extends Throwable>> depthFirstHandlerMethods =
new ArrayList<HandlerMethod<? extends Throwable>>(handlersForException);
@@ -178,6 +183,9 @@ public void executeHandlers(@Observes @Any ExceptionToCatch eventException, fina
break;
case THROW:
throwException = depthFirstEvent.getThrowNewException();
+ break;
+ default:
+ throw new IllegalStateException("Unexpected enum type " + depthFirstEvent.getFlow());
}
}
}
@@ -194,7 +202,8 @@ public void executeHandlers(@Observes @Any ExceptionToCatch eventException, fina
{
throw throwException;
}
- } finally
+ }
+ finally
{
if (ctx != null)
{
@@ -63,51 +63,6 @@
private BeanManager beanManager;
/**
- * Determines if the given method is a handler by looking for the {@link Handles} annotation on a parameter.
- *
- * @param method method to search
- * @return true if {@link Handles} is found, false otherwise
- */
- public static boolean isHandler(final AnnotatedMethod<?> method)
- {
- if (method == null)
- {
- throw new IllegalArgumentException("Method must not be null");
- }
-
- for (AnnotatedParameter<?> param : method.getParameters())
- {
- if (param.isAnnotationPresent(Handles.class) || param.isAnnotationPresent(BeforeHandles.class))
- {
- return true;
- }
- }
-
- return false;
- }
-
- public static AnnotatedParameter<?> findHandlerParameter(final AnnotatedMethod<?> method)
- {
- if (!isHandler(method))
- {
- throw new IllegalArgumentException("Method is not a valid handler");
- }
-
- AnnotatedParameter<?> returnParam = null;
-
- for (AnnotatedParameter<?> param : method.getParameters())
- {
- if (param.isAnnotationPresent(Handles.class) || param.isAnnotationPresent(BeforeHandles.class))
- {
- returnParam = param;
- break;
- }
- }
-
- return returnParam;
- }
-
- /**
* Sole Constructor.
*
* @param method found handler
@@ -131,7 +86,8 @@ public HandlerMethodImpl(final AnnotatedMethod<?> method, final BeanManager bm)
this.handlerParameter = findHandlerParameter(method);
- if (!this.handlerParameter.isAnnotationPresent(Handles.class) && !this.handlerParameter.isAnnotationPresent(BeforeHandles.class))
+ if (!this.handlerParameter.isAnnotationPresent(Handles.class)
+ && !this.handlerParameter.isAnnotationPresent(BeforeHandles.class))
{
throw new IllegalArgumentException("Method is not annotated with @Handles or @BeforeHandles");
}
@@ -160,16 +116,55 @@ public HandlerMethodImpl(final AnnotatedMethod<?> method, final BeanManager bm)
}
/**
- * {@inheritDoc}
+ * Determines if the given method is a handler by looking for the {@link Handles} annotation on a parameter.
+ *
+ * @param method method to search
+ * @return true if {@link Handles} is found, false otherwise
*/
+ public static boolean isHandler(final AnnotatedMethod<?> method)
+ {
+ if (method == null)
+ {
+ throw new IllegalArgumentException("Method must not be null");
+ }
+
+ for (AnnotatedParameter<?> param : method.getParameters())
+ {
+ if (param.isAnnotationPresent(Handles.class) || param.isAnnotationPresent(BeforeHandles.class))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static AnnotatedParameter<?> findHandlerParameter(final AnnotatedMethod<?> method)
+ {
+ if (!isHandler(method))
+ {
+ throw new IllegalArgumentException("Method is not a valid handler");
+ }
+
+ AnnotatedParameter<?> returnParam = null;
+
+ for (AnnotatedParameter<?> param : method.getParameters())
+ {
+ if (param.isAnnotationPresent(Handles.class) || param.isAnnotationPresent(BeforeHandles.class))
+ {
+ returnParam = param;
+ break;
+ }
+ }
+
+ return returnParam;
+ }
+
public Class<?> getBeanClass()
{
return this.beanClass;
}
- /**
- * {@inheritDoc}
- */
public synchronized Bean<?> getBean(BeanManager bm)
{
if (this.bean == null)
@@ -182,6 +177,7 @@ public HandlerMethodImpl(final AnnotatedMethod<?> method, final BeanManager bm)
/**
* {@inheritDoc}
*/
+ @Override
public Set<Annotation> getQualifiers()
{
return Collections.unmodifiableSet(this.qualifiers);
@@ -190,6 +186,7 @@ public HandlerMethodImpl(final AnnotatedMethod<?> method, final BeanManager bm)
/**
* {@inheritDoc}
*/
+ @Override
public Type getExceptionType()
{
return this.exceptionType;
@@ -198,6 +195,7 @@ public Type getExceptionType()
/**
* {@inheritDoc}
*/
+ @Override
public void notify(final CaughtException<T> event)
{
CreationalContext<?> ctx = null;
@@ -207,7 +205,8 @@ public void notify(final CaughtException<T> event)
Object handlerInstance = beanManager.getReference(this.getBean(beanManager), this.beanClass, ctx);
InjectableMethod<?> im = createInjectableMethod(this.handler, this.getBean(beanManager), beanManager);
im.invoke(handlerInstance, ctx, new OutboundParameterValueRedefiner(event, beanManager, this));
- } finally
+ }
+ finally
{
if (ctx != null)
{
@@ -216,11 +215,15 @@ public void notify(final CaughtException<T> event)
}
}
- private <X> InjectableMethod<X> createInjectableMethod(AnnotatedMethod<X> handlerMethod, Bean<?> bean, BeanManager manager)
+ private <X> InjectableMethod<X> createInjectableMethod(AnnotatedMethod<X> handlerMethod,
+ Bean<?> bean, BeanManager manager)
{
return new InjectableMethod<X>(handlerMethod, bean, manager);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean isBefore()
{
@@ -230,14 +233,12 @@ public boolean isBefore()
/**
* {@inheritDoc}
*/
+ @Override
public int getOrdinal()
{
return this.ordinal;
}
- /**
- * {@inheritDoc}
- */
public Method getJavaMethod()
{
return this.javaMethod;
@@ -17,7 +17,9 @@
* under the License.
*/
-package org.apache.deltaspike.core.api.exception.control;
+package org.apache.deltaspike.core.impl.exception.control;
+
+import org.apache.deltaspike.core.api.exception.control.HandlerMethod;
import javax.enterprise.inject.spi.BeanManager;
import java.lang.annotation.Annotation;
@@ -26,7 +28,8 @@
import java.util.Set;
/**
- * Injectable storage to support programmatic registration and lookup of {@link HandlerMethod} instances.
+ * Injectable storage to support programmatic registration and lookup of
+ * {@link org.apache.deltaspike.core.api.exception.control.HandlerMethod} instances.
*/
public interface HandlerMethodStorage
{
Oops, something went wrong. Retry.

0 comments on commit 2625715

Please sign in to comment.