use of org.apache.deltaspike.core.util.HierarchyDiscovery in project deltaspike by apache.
the class HandlerMethodStorageImpl method getHandlersForException.
@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 (allHandlers.get(hierarchyType) != null) {
for (HandlerMethod<?> handler : allHandlers.get(hierarchyType)) {
if (handler.isBeforeHandler() && isBefore) {
if (handler.getQualifiers().contains(new AnyLiteral())) {
returningHandlers.add(handler);
} else {
if (!handlerQualifiers.isEmpty() && handlerQualifiers.equals(handler.getQualifiers())) {
returningHandlers.add(handler);
}
}
} else if (!handler.isBeforeHandler() && !isBefore) {
if (handler.getQualifiers().contains(new AnyLiteral())) {
returningHandlers.add(handler);
} else {
if (!handlerQualifiers.isEmpty() && handlerQualifiers.equals(handler.getQualifiers())) {
returningHandlers.add(handler);
}
}
}
}
}
}
log.fine(String.format("Found handlers %s for exception type %s, qualifiers %s", returningHandlers, exceptionClass, handlerQualifiers));
return Collections.unmodifiableCollection(returningHandlers);
}
use of org.apache.deltaspike.core.util.HierarchyDiscovery in project deltaspike by apache.
the class ExceptionHandlerComparator method compareHierarchies.
private int compareHierarchies(Type lhsExceptionType, Type rhsExceptionType) {
HierarchyDiscovery lhsHierarchy = new HierarchyDiscovery(lhsExceptionType);
Set<Type> lhsTypeclosure = lhsHierarchy.getTypeClosure();
if (lhsTypeclosure.contains(rhsExceptionType)) {
final int indexOfLhsType = new ArrayList<Type>(lhsTypeclosure).indexOf(lhsExceptionType);
final int indexOfRhsType = new ArrayList<Type>(lhsTypeclosure).indexOf(rhsExceptionType);
if (indexOfLhsType > indexOfRhsType) {
return 1;
}
}
return -1;
}
Aggregations