You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by li...@apache.org on 2012/04/11 17:38:20 UTC
[6/6] git commit: Fixing tests and checkstyle
Fixing tests and checkstyle
Next is to add the tests for Catch
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/26257157
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/26257157
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/26257157
Branch: refs/heads/master
Commit: 262571572a1ec0ae608fe74250e8e6367b6fbae7
Parents: 46285dc
Author: Jason Porter <li...@apache.org>
Authored: Mon Apr 9 23:24:30 2012 -0600
Committer: Jason Porter <li...@apache.org>
Committed: Tue Apr 10 16:31:05 2012 -0600
----------------------------------------------------------------------
.../exception/control/HandlerMethodStorage.java | 52 ------
.../control/ExceptionHandlerComparator.java | 7 +-
.../control/ExceptionHandlerDispatch.java | 23 ++-
.../impl/exception/control/HandlerMethodImpl.java | 111 +++++++------
.../exception/control/HandlerMethodStorage.java | 55 ++++++
.../control/HandlerMethodStorageImpl.java | 129 +++++++++++++++
.../control/OutboundParameterValueRedefiner.java | 12 +-
.../control/extension/CatchExtension.java | 116 ++++----------
8 files changed, 298 insertions(+), 207 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/26257157/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/HandlerMethodStorage.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/HandlerMethodStorage.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/HandlerMethodStorage.java
deleted file mode 100644
index 100c6fb..0000000
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/HandlerMethodStorage.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.deltaspike.core.api.exception.control;
-
-import javax.enterprise.inject.spi.BeanManager;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.Set;
-
-/**
- * Injectable storage to support programmatic registration and lookup of {@link HandlerMethod} instances.
- */
-public interface HandlerMethodStorage
-{
- /**
- * Registers the given handlerMethod to the storage.
- *
- * @param handlerMethod HandlerMethod implementation to register with the storage
- */
- <T extends Throwable> void registerHandlerMethod(HandlerMethod<T> handlerMethod);
-
- /**
- * Obtains the applicable handlers for the given type or super type of the given type to order the handlers.
- *
- * @param exceptionClass Type of exception to narrow handler list
- * @param bm active BeanManager
- * @param handlerQualifiers additional handlerQualifiers to limit handlers
- * @param isBefore traversal limiter
- * @return An order collection of handlers for the given type.
- */
- Collection<HandlerMethod<? extends Throwable>> getHandlersForException(Type exceptionClass, BeanManager bm,
- Set<Annotation> handlerQualifiers,
- boolean isBefore);
-}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/26257157/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerComparator.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerComparator.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerComparator.java
index c5523f7..c9dd39a 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerComparator.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerComparator.java
@@ -28,16 +28,17 @@ import java.util.Comparator;
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))
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/26257157/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerDispatch.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerDispatch.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerDispatch.java
index af14cd6..a1e9333 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerDispatch.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerDispatch.java
@@ -23,7 +23,7 @@ import org.apache.deltaspike.core.api.exception.control.CaughtException;
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 @@ public class ExceptionHandlerDispatch implements java.io.Serializable
*
* @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 class ExceptionHandlerDispatch implements java.io.Serializable
Throwable throwException = null;
+ final HandlerMethodStorage handlerMethodStorage = CatchExtension.createStorage();
+
try
{
ctx = bm.createCreationalContext(null);
@@ -79,7 +81,7 @@ public class ExceptionHandlerDispatch implements java.io.Serializable
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 class ExceptionHandlerDispatch implements java.io.Serializable
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 class ExceptionHandlerDispatch implements java.io.Serializable
break;
case THROW:
throwException = depthFirstEvent.getThrowNewException();
+ break;
+ default:
+ throw new IllegalStateException("Unexpected enum type " + depthFirstEvent.getFlow());
}
}
}
@@ -194,7 +202,8 @@ public class ExceptionHandlerDispatch implements java.io.Serializable
{
throw throwException;
}
- } finally
+ }
+ finally
{
if (ctx != null)
{
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/26257157/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java
index 4eef88c..a2ac057 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java
@@ -63,51 +63,6 @@ public class HandlerMethodImpl<T extends Throwable> implements HandlerMethod<T>
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 class HandlerMethodImpl<T extends Throwable> implements HandlerMethod<T>
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 class HandlerMethodImpl<T extends Throwable> implements HandlerMethod<T>
}
/**
- * {@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 class HandlerMethodImpl<T extends Throwable> implements HandlerMethod<T>
/**
* {@inheritDoc}
*/
+ @Override
public Set<Annotation> getQualifiers()
{
return Collections.unmodifiableSet(this.qualifiers);
@@ -190,6 +186,7 @@ public class HandlerMethodImpl<T extends Throwable> implements HandlerMethod<T>
/**
* {@inheritDoc}
*/
+ @Override
public Type getExceptionType()
{
return this.exceptionType;
@@ -198,6 +195,7 @@ public class HandlerMethodImpl<T extends Throwable> implements HandlerMethod<T>
/**
* {@inheritDoc}
*/
+ @Override
public void notify(final CaughtException<T> event)
{
CreationalContext<?> ctx = null;
@@ -207,7 +205,8 @@ public class HandlerMethodImpl<T extends Throwable> implements HandlerMethod<T>
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 class HandlerMethodImpl<T extends Throwable> implements HandlerMethod<T>
}
}
- 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 class HandlerMethodImpl<T extends Throwable> implements HandlerMethod<T>
/**
* {@inheritDoc}
*/
+ @Override
public int getOrdinal()
{
return this.ordinal;
}
- /**
- * {@inheritDoc}
- */
public Method getJavaMethod()
{
return this.javaMethod;
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/26257157/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorage.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorage.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorage.java
new file mode 100644
index 0000000..20f78ee
--- /dev/null
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorage.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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;
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * Injectable storage to support programmatic registration and lookup of
+ * {@link org.apache.deltaspike.core.api.exception.control.HandlerMethod} instances.
+ */
+public interface HandlerMethodStorage
+{
+ /**
+ * Registers the given handlerMethod to the storage.
+ *
+ * @param handlerMethod HandlerMethod implementation to register with the storage
+ */
+ <T extends Throwable> void registerHandlerMethod(HandlerMethod<T> handlerMethod);
+
+ /**
+ * Obtains the applicable handlers for the given type or super type of the given type to order the handlers.
+ *
+ * @param exceptionClass Type of exception to narrow handler list
+ * @param bm active BeanManager
+ * @param handlerQualifiers additional handlerQualifiers to limit handlers
+ * @param isBefore traversal limiter
+ * @return An order collection of handlers for the given type.
+ */
+ Collection<HandlerMethod<? extends Throwable>> getHandlersForException(Type exceptionClass, BeanManager bm,
+ Set<Annotation> handlerQualifiers,
+ boolean isBefore);
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/26257157/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorageImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorageImpl.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorageImpl.java
new file mode 100644
index 0000000..6d75b81
--- /dev/null
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorageImpl.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.core.impl.exception.control;
+
+import org.apache.deltaspike.core.api.exception.control.HandlerMethod;
+import org.apache.deltaspike.core.api.literal.AnyLiteral;
+import org.apache.deltaspike.core.impl.exception.control.extension.CatchExtension;
+import org.apache.deltaspike.core.util.HierarchyDiscovery;
+
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.BeanManager;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.logging.Logger;
+
+/**
+ * Basic implementation for {@link HandlerMethodStorage}.
+ */
+@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
+public class HandlerMethodStorageImpl implements HandlerMethodStorage
+{
+ private final Map<? super Type, Collection<HandlerMethod<? extends Throwable>>> allHandlers;
+
+ private Logger log = Logger.getLogger(HandlerMethodStorageImpl.class.toString());
+
+ public HandlerMethodStorageImpl(Map<? super Type, Collection<HandlerMethod<? extends Throwable>>> allHandlers)
+ {
+ this.allHandlers = allHandlers;
+ }
+
+ @Produces
+ public static HandlerMethodStorage create()
+ {
+ return CatchExtension.createStorage();
+ }
+
+ @Override
+ public <T extends Throwable> void registerHandlerMethod(HandlerMethod<T> handlerMethod)
+ {
+ log.fine(String.format("Adding handler %s to known handlers", handlerMethod));
+ if (this.allHandlers.containsKey(handlerMethod.getExceptionType()))
+ {
+ this.allHandlers.get(handlerMethod.getExceptionType()).add(handlerMethod);
+ }
+ else
+ {
+ this.allHandlers.put(handlerMethod.getExceptionType(),
+ new HashSet<HandlerMethod<? extends Throwable>>(Arrays.asList(handlerMethod)));
+ }
+ }
+
+ @Override
+ public Collection<HandlerMethod<? extends Throwable>> getHandlersForException(Type exceptionClass,
+ BeanManager bm,
+ Set<Annotation> handlerQualifiers,
+ boolean isBefore)
+ {
+ final Collection<HandlerMethod<? extends Throwable>> returningHandlers =
+ new TreeSet<HandlerMethod<? extends Throwable>>(new ExceptionHandlerComparator());
+ final HierarchyDiscovery h = new HierarchyDiscovery(exceptionClass);
+ final Set<Type> closure = h.getTypeClosure();
+
+ for (Type hierarchyType : closure)
+ {
+ if (this.allHandlers.get(hierarchyType) != null)
+ {
+ for (HandlerMethod<?> handler : this.allHandlers.get(hierarchyType))
+ {
+ if (handler.isBefore())
+ {
+ if (handler.getQualifiers().contains(new AnyLiteral()))
+ {
+ returningHandlers.add(handler);
+ }
+ else
+ {
+ if (!handlerQualifiers.isEmpty() && this.containsAny(handler.getQualifiers(),
+ handlerQualifiers))
+ {
+ returningHandlers.add(handler);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ log.fine(String.format("Found handlers %s for exception type %s, qualifiers %s", returningHandlers,
+ exceptionClass, handlerQualifiers));
+ return Collections.unmodifiableCollection(returningHandlers);
+ }
+
+ private boolean containsAny(final Collection<? extends Annotation> haystack,
+ final Collection<? extends Annotation> needles)
+ {
+ for (Annotation a : needles)
+ {
+ if (haystack.contains(a))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/26257157/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/OutboundParameterValueRedefiner.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/OutboundParameterValueRedefiner.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/OutboundParameterValueRedefiner.java
index 26210a7..6674e9e 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/OutboundParameterValueRedefiner.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/OutboundParameterValueRedefiner.java
@@ -32,10 +32,10 @@ import javax.enterprise.inject.spi.BeanManager;
*/
public class OutboundParameterValueRedefiner implements ParameterValueRedefiner
{
- final private CaughtException<?> event;
- final private BeanManager bm;
- final private Bean<?> declaringBean;
- final private HandlerMethodImpl<?> handlerMethod;
+ private final CaughtException<?> event;
+ private final BeanManager bm;
+ private final Bean<?> declaringBean;
+ private final HandlerMethodImpl<?> handlerMethod;
/**
* Sole constructor.
@@ -56,6 +56,7 @@ public class OutboundParameterValueRedefiner implements ParameterValueRedefiner
/**
* {@inheritDoc}
*/
+ @Override
public Object redefineParameterValue(ParameterValue value)
{
CreationalContext<?> ctx = this.bm.createCreationalContext(this.declaringBean);
@@ -67,7 +68,8 @@ public class OutboundParameterValueRedefiner implements ParameterValueRedefiner
return event;
}
return value.getDefaultValue(ctx);
- } finally
+ }
+ finally
{
if (ctx != null)
{
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/26257157/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/extension/CatchExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/extension/CatchExtension.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/extension/CatchExtension.java
index 964af98..601d30e 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/extension/CatchExtension.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/extension/CatchExtension.java
@@ -21,11 +21,11 @@ package org.apache.deltaspike.core.impl.exception.control.extension;
import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
import org.apache.deltaspike.core.api.exception.control.HandlerMethod;
-import org.apache.deltaspike.core.api.exception.control.HandlerMethodStorage;
-import org.apache.deltaspike.core.api.literal.AnyLiteral;
-import org.apache.deltaspike.core.impl.exception.control.ExceptionHandlerComparator;
import org.apache.deltaspike.core.impl.exception.control.HandlerMethodImpl;
-import org.apache.deltaspike.core.util.HierarchyDiscovery;
+import org.apache.deltaspike.core.impl.exception.control.HandlerMethodStorage;
+import org.apache.deltaspike.core.impl.exception.control.HandlerMethodStorageImpl;
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.util.ClassDeactivationUtils;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.InjectionException;
@@ -34,13 +34,11 @@ import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.BeforeShutdown;
import javax.enterprise.inject.spi.Decorator;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.Interceptor;
import javax.enterprise.inject.spi.ProcessBean;
-import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
@@ -50,22 +48,21 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import java.util.TreeSet;
import java.util.logging.Logger;
/**
* CDI extension to find handlers at startup.
*/
-@SuppressWarnings({"unchecked", "CdiManagedBeanInconsistencyInspection"})
-public class CatchExtension implements Extension, HandlerMethodStorage
+@SuppressWarnings({ "unchecked", "CdiManagedBeanInconsistencyInspection" })
+public class CatchExtension implements Extension, Deactivatable
{
private static Map<? super Type, Collection<HandlerMethod<? extends Throwable>>> allHandlers;
- private final Logger log = Logger.getLogger(CatchExtension.class.toString());
+ private Logger log = Logger.getLogger(CatchExtension.class.toString());
public CatchExtension()
{
- this.allHandlers = new HashMap<Type, Collection<HandlerMethod<? extends Throwable>>>();
+ CatchExtension.allHandlers = new HashMap<Type, Collection<HandlerMethod<? extends Throwable>>>();
}
/**
@@ -73,15 +70,20 @@ public class CatchExtension implements Extension, HandlerMethodStorage
*
* @param pmb Event from CDI SPI
* @param bm Activated Bean Manager
- * @throws TypeNotPresentException if any of the actual type arguments refers to a non-existent type declaration when
- * trying to obtain the actual type arguments from a {@link ParameterizedType}
+ * @throws TypeNotPresentException if any of the actual type arguments refers to a non-existent type declaration
+ * when trying to obtain the actual type arguments from a {@link ParameterizedType}
* @throws java.lang.reflect.MalformedParameterizedTypeException
- * if any of the actual type parameters refer to a parameterized type that cannot be
- * instantiated for any reason when trying to obtain the actual type arguments from a
- * {@link ParameterizedType}
+ * if any of the actual type parameters refer to a parameterized type that cannot
+ * be instantiated for any reason when trying to obtain the actual type arguments
+ * from a {@link ParameterizedType}
*/
public <T> void findHandlers(@Observes final ProcessBean<?> pmb, final BeanManager bm)
{
+ if (!ClassDeactivationUtils.isActivated(CatchExtension.class))
+ {
+ return;
+ }
+
if (!(pmb.getAnnotated() instanceof AnnotatedType) || pmb.getBean() instanceof Interceptor ||
pmb.getBean() instanceof Decorator)
{
@@ -104,7 +106,8 @@ public class CatchExtension implements Extension, HandlerMethodStorage
pmb.addDefinitionError(new IllegalArgumentException(
String.format("Handler method %s must not throw exceptions", method.getJavaMember())));
}
- final Class<? extends Throwable> exceptionType = (Class<? extends Throwable>) ((ParameterizedType) param.getBaseType()).getActualTypeArguments()[0];
+ final Class<? extends Throwable> exceptionType = (Class<? extends Throwable>) ((ParameterizedType)
+ param.getBaseType()).getActualTypeArguments()[0];
registerHandlerMethod(new HandlerMethodImpl(method, bm));
}
@@ -120,7 +123,12 @@ public class CatchExtension implements Extension, HandlerMethodStorage
*/
public void verifyInjectionPoints(@Observes final AfterDeploymentValidation adv, final BeanManager bm)
{
- for (Map.Entry<? super Type, Collection<HandlerMethod<? extends Throwable>>> entry : this.allHandlers.entrySet())
+ if (!ClassDeactivationUtils.isActivated(CatchExtension.class))
+ {
+ return;
+ }
+
+ for (Map.Entry<? super Type, Collection<HandlerMethod<? extends Throwable>>> entry : allHandlers.entrySet())
{
for (HandlerMethod<? extends Throwable> handler : entry.getValue())
{
@@ -129,84 +137,22 @@ public class CatchExtension implements Extension, HandlerMethodStorage
try
{
bm.validate(ip);
- } catch (InjectionException e)
- {
- adv.addDeploymentProblem(e);
}
- }
- }
- }
- }
-
- /**
- * Obtains the applicable handlers for the given type or super type of the given type. Also makes use of {@link
- * org.apache.deltaspike.core.impl.exception.control.ExceptionHandlerComparator} to order the handlers.
- *
- * @param exceptionClass Type of exception to narrow handler list
- * @param bm active BeanManager
- * @param handlerQualifiers additional handlerQualifiers to limit handlers
- * @param isBefore traversal limiter
- * @return An order collection of handlers for the given type.
- */
- public Collection<HandlerMethod<? extends Throwable>> getHandlersForException(Type exceptionClass, BeanManager bm,
- Set<Annotation> handlerQualifiers,
- boolean isBefore)
- {
- final Collection<HandlerMethod<? extends Throwable>> returningHandlers =
- new TreeSet<HandlerMethod<? extends Throwable>>(new ExceptionHandlerComparator());
- final HierarchyDiscovery h = new HierarchyDiscovery(exceptionClass);
- final Set<Type> closure = h.getTypeClosure();
-
- for (Type hierarchyType : closure)
- {
- if (CatchExtension.allHandlers.get(hierarchyType) != null)
- {
- for (HandlerMethod<?> handler : CatchExtension.allHandlers.get(hierarchyType))
- {
- if (handler.isBefore())
+ catch (InjectionException e)
{
- if (handler.getQualifiers().contains(new AnyLiteral()))
- {
- returningHandlers.add(handler);
- }
- else
- {
- if (!handlerQualifiers.isEmpty() && this.containsAny(handler.getQualifiers(),
- handlerQualifiers))
- {
- returningHandlers.add(handler);
- }
- }
+ adv.addDeploymentProblem(e);
}
}
}
}
-
- log.fine(String.format("Found handlers %s for exception type %s, qualifiers %s", returningHandlers,
- exceptionClass, handlerQualifiers));
- return Collections.unmodifiableCollection(returningHandlers);
- }
-
- public void cleanup(@Observes BeforeShutdown beforeShutdown)
- {
- CatchExtension.allHandlers.clear();
}
- private boolean containsAny(final Collection<? extends Annotation> haystack,
- final Collection<? extends Annotation> needles)
+ public static HandlerMethodStorage createStorage()
{
- for (Annotation a : needles)
- {
- if (haystack.contains(a))
- {
- return true;
- }
- }
- return false;
+ return new HandlerMethodStorageImpl(Collections.unmodifiableMap(CatchExtension.allHandlers));
}
- @Override
- public <T extends Throwable> void registerHandlerMethod(HandlerMethod<T> handlerMethod)
+ private <T extends Throwable> void registerHandlerMethod(HandlerMethod<T> handlerMethod)
{
log.fine(String.format("Adding handler %s to known handlers", handlerMethod));
if (CatchExtension.allHandlers.containsKey(handlerMethod.getExceptionType()))