polishing

This commit is contained in:
Mark Fisher
2010-11-13 09:04:12 -05:00
parent c5f1e9d8e4
commit 4bad4f13de

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,51 +18,54 @@ package org.springframework.integration.dispatcher;
import org.springframework.integration.Message;
import org.springframework.integration.MessageDeliveryException;
import org.springframework.util.StringUtils;
import java.util.Collections;
import java.util.List;
/**
* An Exception that encapsulates an aggregated group of Exceptions for use by dispatchers that may try multiple handler
* invocations within a single dispatch operation.
*
* An Exception that encapsulates an aggregated group of Exceptions for use by dispatchers
* that may try multiple handler invocations within a single dispatch operation.
*
* @author Mark Fisher
* @since 1.0.3
*/
@SuppressWarnings("serial")
public class AggregateMessageDeliveryException extends MessageDeliveryException {
private final List<? extends Exception> aggregatedExceptions;
private final List<? extends Exception> aggregatedExceptions;
public AggregateMessageDeliveryException(Message<?> undeliveredMessage,
String description, List<? extends Exception> aggregatedExceptions) {
super(undeliveredMessage, description);
this.initCause(aggregatedExceptions.get(0));
this.aggregatedExceptions = aggregatedExceptions;
}
public AggregateMessageDeliveryException(Message<?> undeliveredMessage,
String description, List<? extends Exception> aggregatedExceptions) {
super(undeliveredMessage, description);
this.initCause(aggregatedExceptions.get(0));
this.aggregatedExceptions = aggregatedExceptions;
}
public List<? extends Exception> getAggregatedExceptions() {
return Collections.unmodifiableList(this.aggregatedExceptions);
}
public List<? extends Exception> getAggregatedExceptions() {
return Collections.unmodifiableList(this.aggregatedExceptions);
}
@Override
public String getMessage() {
String baseMessage = super.getMessage();
StringBuilder message = new StringBuilder(appendPeriodIfNecessary(baseMessage) + " Multiple causes:\n");
for (Exception exception : aggregatedExceptions) {
message.append(" " + exception.getMessage() + "\n");
}
message.append("See below for the stacktrace of the first cause.");
return message.toString();
}
@Override
public String getMessage() {
String baseMessage = super.getMessage();
StringBuilder message = new StringBuilder(endingWithPeriod(baseMessage) + " Multiple causes are:\n");
for (Exception exception : aggregatedExceptions) {
message.append(" " + exception.getMessage() + "\n");
}
message.append("See below for the stacktrace of the first cause.");
return message.toString();
}
private String appendPeriodIfNecessary(String baseMessage) {
if (!StringUtils.hasText(baseMessage)) {
baseMessage = "";
}
else if (!baseMessage.endsWith(".")) {
baseMessage = baseMessage + ".";
}
return baseMessage;
}
private String endingWithPeriod(String baseMessage) {
if (baseMessage.endsWith(".")) {
return baseMessage;
} else {
return baseMessage + ".";
}
}
}