Author: erans Date: Fri Nov 12 23:41:02 2010 New Revision: 1034601 URL: http://svn.apache.org/viewvc?rev=1034601&view=rev Log: MATH-440 "MathUserException": Using "Localizable" argument in constructor.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java?rev=1034601&r1=1034600&r2=1034601&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java Fri Nov 12 23:41:02 2010 @@ -76,7 +76,6 @@ public class MathIllegalArgumentExceptio * Get the message in a specified locale. * * @param locale Locale in which the message should be translated. - * * @return the localized message. */ public String getMessage(final Locale locale) { Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java?rev=1034601&r1=1034600&r2=1034601&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java Fri Nov 12 23:41:02 2010 @@ -16,6 +16,13 @@ */ package org.apache.commons.math.exception; +import java.util.Locale; + +import org.apache.commons.math.exception.util.ArgUtils; +import org.apache.commons.math.exception.util.MessageFactory; +import org.apache.commons.math.exception.util.Localizable; +import org.apache.commons.math.exception.util.LocalizedFormats; + /** * This class is intended as a sort of communication channel between * layers of <em>user</em> code separated from each other by calls to @@ -26,31 +33,67 @@ package org.apache.commons.math.exceptio * @version $Revision$ $Date$ */ public class MathUserException extends RuntimeException { + /** Serializable version Id. */ + private static final long serialVersionUID = -6024911025449780478L; /** - * Default constructor. + * Pattern used to build the message (problem description). */ - public MathUserException() {} + private final Localizable pattern; + /** + * Arguments used to build the message. + */ + private final Object[] arguments; /** - * @param msg Error message. + * Default constructor. */ - public MathUserException(String msg) { - super(msg); + public MathUserException() { + this(null); } /** - * @param msg Error message. * @param cause Cause of the error. + * @param args Arguments. */ - public MathUserException(String msg, - Throwable cause) { - super(msg, cause); + public MathUserException(Throwable cause, + Object ... args) { + this(null, cause, args); } /** + * @param pattern Message pattern explaining the cause of the error. * @param cause Cause of the error. + * @param args Arguments. + */ + public MathUserException(Localizable pattern, + Throwable cause, + Object ... args) { + this.pattern = pattern; + arguments = ArgUtils.flatten(args); + } + + /** + * Get the message in a specified locale. + * + * @param locale Locale in which the message should be translated. + * @return the localized message. */ - public MathUserException(Throwable cause) { - super(cause); + public String getMessage(final Locale locale) { + return MessageFactory.buildMessage(locale, + pattern, + LocalizedFormats.USER_EXCEPTION, + arguments); + } + + /** {...@inheritdoc} */ + @Override + public String getMessage() { + return getMessage(Locale.US); + } + + /** {...@inheritdoc} */ + @Override + public String getLocalizedMessage() { + return getMessage(Locale.getDefault()); } } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java?rev=1034601&r1=1034600&r2=1034601&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java Fri Nov 12 23:41:02 2010 @@ -303,6 +303,7 @@ public enum LocalizedFormats implements UNPARSEABLE_REAL_VECTOR("unparseable real vector: \"{0}\""), UNSUPPORTED_EXPANSION_MODE("unsupported expansion mode {0}, supported modes are {1} ({2}) and {3} ({4})"), UNSUPPORTED_OPERATION("unsupported operation"), /* keep */ + USER_EXCEPTION("exception generated in user code"), /* keep */ URL_CONTAINS_NO_DATA("URL {0} contains no data"), VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC("{0} values have been added before statistic is configured"), VECTOR_LENGTH_MISMATCH("vector length mismatch: got {0} but expected {1}"), Modified: commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties?rev=1034601&r1=1034600&r2=1034601&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties (original) +++ commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties Fri Nov 12 23:41:02 2010 @@ -275,6 +275,7 @@ UNPARSEABLE_FRACTION_NUMBER = nombre fra UNPARSEABLE_REAL_VECTOR = vecteur r\u00e9el non analysable : "{0}" UNSUPPORTED_EXPANSION_MODE = mode d''extension {0} non support\u00e9, les modes support\u00e9s sont {1} ({2}) et {3} ({4}) UNSUPPORTED_OPERATION = op\u00e9ration non disponible +USER_EXCEPTION = erreur g\u00e9n\u00e9r\u00e9e par le code utilisateur URL_CONTAINS_NO_DATA = l''adresse {0} ne contient aucune donn\u00e9e VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC = {0} valeurs ont \u00e9t\u00e9 ajout\u00e9es VECTOR_LENGTH_MISMATCH = taille de vecteur invalide : {0} au lieu de {1} attendue