"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main/java/com/rapidminer/operator/OperatorException.java" between
rapidminer-studio-9.4.1-src.tar.gz and rapidminer-studio-9.5.0-src.tar.gz

About: RapidMiner Studio is a code-free environment for designing advanced analytic processes with machine learning, data mining, text mining, predictive analytics and business analytics. Java source.

OperatorException.java  (rapidminer-studio-9.4.1-src):OperatorException.java  (rapidminer-studio-9.5.0-src)
skipping to change at line 21 skipping to change at line 21
* *
* This program is distributed in the hope that it will be useful, but WITHOUT A NY WARRANTY; without * This program is distributed in the hope that it will be useful, but WITHOUT A NY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURP OSE. See the GNU * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURP OSE. See the GNU
* Affero General Public License for more details. * Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License alon g with this program. * You should have received a copy of the GNU Affero General Public License alon g with this program.
* If not, see http://www.gnu.org/licenses/. * If not, see http://www.gnu.org/licenses/.
*/ */
package com.rapidminer.operator; package com.rapidminer.operator;
import com.rapidminer.tools.I18N; import java.util.MissingResourceException;
import java.text.MessageFormat; import com.rapidminer.tools.I18N;
import java.util.ResourceBundle;
/** /**
* Exception class whose instances are thrown by instances of the class {@link O perator} or of one * Exception class whose instances are thrown by instances of the class {@link O perator} or of one
* of its subclasses. * of its subclasses.
* *
* This exception also allows using i18n keys, but it is not obligatory to do so . Currently only the * This exception also allows using i18n keys, but it is not obligatory to do so . Currently only the
* .short tag will be used, but this should be changed in future, so adding the other descriptions * .short tag will be used, but this should be changed in future, so adding the other descriptions
* could be wise. * could be wise.
* *
* TODO: Change usage to i18n keys. * TODO: Change usage to i18n keys.
* *
* @author Ingo Mierswa, Simon Fischer, Sebastian Land * @author Ingo Mierswa, Simon Fischer, Sebastian Land
*/ */
public class OperatorException extends Exception { public class OperatorException extends Exception {
private static final long serialVersionUID = 3626738574540303240L; private static final long serialVersionUID = 3626738574540303240L;
private static ResourceBundle messages = I18N.getUserErrorMessagesBundle( private final String errorIdentifier;
); // ErrorBundle(); private final Object[] arguments;
private static final MessageFormat formatter = new MessageFormat("");
public OperatorException(String message) { public OperatorException(String message) {
super(message); super(message);
this.errorIdentifier = null;
this.arguments = new Object[0];
} }
public OperatorException(String message, Throwable cause) { public OperatorException(String message, Throwable cause) {
super(message, cause); super(message, cause);
this.errorIdentifier = null;
this.arguments = new Object[0];
} }
public OperatorException(String errorKey, Throwable cause, Object... argu ments) { public OperatorException(String errorKey, Throwable cause, Object... argu ments) {
super(getErrorMessage(errorKey, arguments), cause); super(getErrorMessage(errorKey, arguments), cause);
this.errorIdentifier = errorKey;
this.arguments = arguments;
} }
public static String getErrorMessage(String identifier, Object[] argument /**
s) { * The errorKey used to access the error.{errorKey}.short message of the
String message = getResourceString(identifier, "short", "No messa getUserErrorMessage bundle
ge."); *
try { * @return The error key which was used to create this exception, or {@co
formatter.applyPattern(message); de null}
String formatted = formatter.format(arguments); * @since 9.5.0
return formatted; */
} catch (Throwable t) { public String getErrorIdentifier() {
return message; return errorIdentifier;
} }
/**
* @return the i18n arguments
* @since 9.5.0
*/
protected Object[] getArguments() {
return arguments;
}
/**
* Returns the short error message from the {@link I18N#getUserErrorMessa
ge UserErrorBundle}
*
* @param identifier part of the error.{identifier}.short i18n key
* @param arguments optional arguments for message formatter
* @return the formatted string or "No message." if no i18n entry exists
*/
public static String getErrorMessage(String identifier, Object[] argument
s) {
return getErrorMessage(identifier, "short", "No message.", argume
nts);
} }
/** /**
* This returns a resource message of the internationalized error message s identified by an id. * This returns a resource message of the internationalized error message s identified by an id.
* Compared to the legacy method {@link #getResourceString(int, String, S
tring)} this supports a
* more detailed identifier. This makes it easier to ensure extensions do
n't reuse already
* defined core errors. It is common sense to add the extensions namespac
e identifier as second
* part of the key, just after error. For example: error.rmx_web.operator
.unusable = This
* operator {0} is unusable.
* *
* @param id * @param id
* The identifier of the error. "error." will be automatically prepended- * The identifier of the error. "error." will be automatically prepended-
* @param key * @param key
* The part of the error description that should be shown. * The part of the error description that should be shown.
* @param deflt * @param deflt
* The default if no resource bundle is available. * The default if no resource bundle is available.
*/ */
public static String getResourceString(String id, String key, String defl t) { public static String getResourceString(String id, String key, String defl t) {
if (messages == null) {
return deflt;
}
try { try {
return messages.getString("error." + id + "." + key); return I18N.getUserErrorMessagesBundle().getString("error
} catch (java.util.MissingResourceException e) { ." + id + "." + key);
} catch (MissingResourceException | NullPointerException e) {
return deflt; return deflt;
} }
} }
/**
* Returns the formatted message from the {@link I18N#getUserErrorMessage
sBundle() UserError} bundle
* key: error.{identifier}.{type}
*
* @param identifier the error identifier
* @param type
* the type, either "name", "short" or "long"
* @param defaultMessage
* the message if no entry for the given key exists
* @param arguments i18n arguments
* @return the message or the defaultMessage
* @since 9.5.0
*/
protected static String getErrorMessage(String identifier, String type, S
tring defaultMessage, Object... arguments) {
String message = I18N.getUserErrorMessageOrNull("error." + identi
fier + "." + type, arguments);
return message == null ? defaultMessage : message;
}
} }
 End of changes. 12 change blocks. 
31 lines changed or deleted 66 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)