From 4bad4f13de6d8f5444bc266cf62a133ee7bbe6e4 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sat, 13 Nov 2010 09:04:12 -0500 Subject: [PATCH] polishing --- .../AggregateMessageDeliveryException.java | 65 ++++++++++--------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryException.java b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryException.java index 46d25966f1..07a1202f9c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryException.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryException.java @@ -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 aggregatedExceptions; + private final List aggregatedExceptions; - public AggregateMessageDeliveryException(Message undeliveredMessage, - String description, List aggregatedExceptions) { - super(undeliveredMessage, description); - this.initCause(aggregatedExceptions.get(0)); - this.aggregatedExceptions = aggregatedExceptions; - } + public AggregateMessageDeliveryException(Message undeliveredMessage, + String description, List aggregatedExceptions) { + super(undeliveredMessage, description); + this.initCause(aggregatedExceptions.get(0)); + this.aggregatedExceptions = aggregatedExceptions; + } + public List getAggregatedExceptions() { + return Collections.unmodifiableList(this.aggregatedExceptions); + } - public List 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 + "."; - } - } }