Ray Milkey | fbfd2da | 2014-05-09 17:30:14 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.rest; |
| 2 | |
| 3 | import org.slf4j.helpers.FormattingTuple; |
| 4 | import org.slf4j.helpers.MessageFormatter; |
| 5 | |
| 6 | /** |
| 7 | * Utility class used for formatting Rest Error descriptions. |
| 8 | */ |
| 9 | public final class RestErrorFormatter { |
| 10 | |
| 11 | /** |
| 12 | * Hide default constructor for utility classes. |
| 13 | */ |
| 14 | private RestErrorFormatter() { } |
| 15 | |
| 16 | /** |
Ray Milkey | a8091b1 | 2014-05-16 14:42:47 -0700 | [diff] [blame] | 17 | * Takes a RestErrorCatalogEntry template and formats the description using a supplied |
Ray Milkey | fbfd2da | 2014-05-09 17:30:14 -0700 | [diff] [blame] | 18 | * list of replacement parameters. |
| 19 | * |
Ray Milkey | a8091b1 | 2014-05-16 14:42:47 -0700 | [diff] [blame] | 20 | * @param error the RestErrorCatalogEntry to format |
Ray Milkey | fbfd2da | 2014-05-09 17:30:14 -0700 | [diff] [blame] | 21 | * @param parameters parameter list to use as positional parameters in the |
| 22 | * result string |
| 23 | * |
| 24 | * @return the String object for the formatted message. |
| 25 | */ |
Ray Milkey | a8091b1 | 2014-05-16 14:42:47 -0700 | [diff] [blame] | 26 | static String formatErrorMessage(final RestErrorCatalogEntry error, |
Ray Milkey | fbfd2da | 2014-05-09 17:30:14 -0700 | [diff] [blame] | 27 | final Object... parameters) { |
| 28 | final FormattingTuple formattingResult = |
Ray Milkey | a8091b1 | 2014-05-16 14:42:47 -0700 | [diff] [blame] | 29 | MessageFormatter.arrayFormat(error.getDescriptionFormatString(), parameters); |
Ray Milkey | fbfd2da | 2014-05-09 17:30:14 -0700 | [diff] [blame] | 30 | return formattingResult.getMessage(); |
| 31 | } |
| 32 | } |