"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main/java/com/rapidminer/operator/UserError.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.

UserError.java  (rapidminer-studio-9.4.1-src):UserError.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 java.text.MessageFormat;
import java.util.ResourceBundle;
import com.rapidminer.NoBugError; import com.rapidminer.NoBugError;
import com.rapidminer.tools.I18N;
import com.rapidminer.tools.Tools; import com.rapidminer.tools.Tools;
/** /**
* Exception class whose instances are thrown due to a user error, for example m issing files or * Exception class whose instances are thrown due to a user error, for example m issing files or
* wrong operator architecture. <br> * wrong operator architecture. <br>
* In order to create a UserError, do the following: * In order to create a UserError, do the following:
* <ul> * <ul>
* <li>Open the file <code>UserErrorMessages.properties</code> in the <code>reso urces</code> * <li>Open the file <code>UserErrorMessages.properties</code> in the <code>reso urces</code>
* directory. Look for an appropriate message. If you find one, remember its id. If not, create a * directory. Look for an appropriate message. If you find one, remember its id. If not, create a
* new one in the correct group</li> * new one in the correct group</li>
skipping to change at line 58 skipping to change at line 54
* use Strings for separating their self defined errors from the errors defined in the core. You * use Strings for separating their self defined errors from the errors defined in the core. You
* should prepend the namespace of the extension like this: error.<extensions * should prepend the namespace of the extension like this: error.<extensions
* namespace>.error_id.short = ... * namespace>.error_id.short = ...
* *
* @author Simon Fischer, Ingo Mierswa, Sebastian Land * @author Simon Fischer, Ingo Mierswa, Sebastian Land
*/ */
public class UserError extends OperatorException implements NoBugError { public class UserError extends OperatorException implements NoBugError {
private static final long serialVersionUID = -8441036860570180869L; private static final long serialVersionUID = -8441036860570180869L;
private static ResourceBundle messages = I18N.getUserErrorMessagesBundle(
);
private static final MessageFormat formatter = new MessageFormat("");
private String errorIdentifier = null;
private final int code; private final int code;
private transient Operator operator; private transient Operator operator;
private final Object[] arguments;
/** /**
* Creates a new UserError. * Creates a new UserError.
* *
* @param operator * @param operator
* The {@link Operator} in which the exception occured. * The {@link Operator} in which the exception occured.
* @param cause * @param cause
* The exception that caused the user error. May be null. Usin g this makes debugging * The exception that caused the user error. May be null. Usin g this makes debugging
* a lot easier. * a lot easier.
* @param code * @param code
* The error code referring to a message in the file * The error code referring to a message in the file
* <code>UserErrorMessages.properties</code> * <code>UserErrorMessages.properties</code>
* @param arguments * @param arguments
* Arguments for the short or long message. * Arguments for the short or long message.
*/ */
public UserError(Operator operator, Throwable cause, int code, Object... arguments) { public UserError(Operator operator, Throwable cause, int code, Object... arguments) {
super(getErrorMessage(code, arguments), cause); super(code + "", cause, arguments);
this.code = code; this.code = code;
this.operator = operator; this.operator = operator;
this.arguments = arguments;
} }
/** Convenience constructor for messages with no arguments and cause. */ /** Convenience constructor for messages with no arguments and cause. */
public UserError(Operator operator, Throwable cause, int code) { public UserError(Operator operator, Throwable cause, int code) {
this(operator, code, new Object[0], cause); this(operator, code, new Object[0], cause);
} }
public UserError(Operator operator, int code, Object... arguments) { public UserError(Operator operator, int code, Object... arguments) {
this(operator, null, code, arguments); this(operator, null, code, arguments);
} }
/** Convenience constructor for messages with no arguments. */ /** Convenience constructor for messages with no arguments. */
public UserError(Operator operator, int code) { public UserError(Operator operator, int code) {
this(operator, null, code, new Object[0]); this(operator, null, code, new Object[0]);
} }
public UserError(Operator operator, Throwable cause, String errorId, Obje ct... arguments) { public UserError(Operator operator, Throwable cause, String errorId, Obje ct... arguments) {
super(getErrorMessage(errorId, arguments), cause); super(errorId, cause, arguments);
this.code = -1; this.code = -1;
this.errorIdentifier = errorId;
this.operator = operator; this.operator = operator;
this.arguments = arguments;
} }
/** /**
* Convenience constructor for messages with no arguments and cause. This constructor is in fact * Convenience constructor for messages with no arguments and cause. This constructor is in fact
* equivalent to the call of the above constructor but must kept for comp atibility issues for * equivalent to the call of the above constructor but must kept for comp atibility issues for
* existing compiled extensions. * existing compiled extensions.
*/ */
public UserError(Operator operator, Throwable cause, String errorId) { public UserError(Operator operator, Throwable cause, String errorId) {
this(operator, cause, errorId, new Object[0]); this(operator, cause, errorId, new Object[0]);
} }
skipping to change at line 133 skipping to change at line 118
this(operator, null, errorId, arguments); this(operator, null, errorId, arguments);
} }
/** Convenience constructor for messages with no arguments. */ /** Convenience constructor for messages with no arguments. */
public UserError(Operator operator, String errorId) { public UserError(Operator operator, String errorId) {
this(operator, null, errorId, new Object[0]); this(operator, null, errorId, new Object[0]);
} }
@Override @Override
public String getDetails() { public String getDetails() {
if (errorIdentifier == null) { return OperatorException.getErrorMessage(getErrorIdentifier(),
String details = getResourceString(code, "long", "Descrip "long",
tion missing."); "Description missing.",
return addArguments(arguments, details); getArguments());
} else {
// allow arguments for error details of new user errors
String message = getResourceString(errorIdentifier, "long
", "Description missing.");
return addArguments(arguments, message);
}
} }
@Override @Override
public String getErrorName() { public String getErrorName() {
if (errorIdentifier == null) { return OperatorException.getErrorMessage(getErrorIdentifier(),
return getResourceString(code, "name", "Unnamed error."); "name",
} else { "Unnamed error.",
return getResourceString(errorIdentifier, "name", "Unname getArguments());
d error.");
}
} }
@Override @Override
public int getCode() { public int getCode() {
return code; return code;
} }
/** @Override
* Returns the ErrorIdentifier if the UserError was created with a constr
uctor that specifies
* an error ID. Returns null if the UserError was created with a construc
tor that specifies an
* error code.
*/
public String getErrorIdentifier() { public String getErrorIdentifier() {
return errorIdentifier; return super.getErrorIdentifier();
} }
@Override
public String getHTMLMessage() {
return "<html>Error in: <b>" + getOperator() + "</b><br>" + Tools
.escapeXML(getMessage()) + "</html>";
}
/**
* Returns the operator which caused this error
*
* @return the operator associated with this exception
*/
public Operator getOperator() { public Operator getOperator() {
return operator; return operator;
} }
/**
* Sets the operator which caused this error
*
* @param operator the operator
*/
public void setOperator(Operator operator) { public void setOperator(Operator operator) {
this.operator = operator; this.operator = operator;
} }
/**
* Returns the short message for the given error code
*
* @param code the error code
* @param arguments the arguments for the message
* @return the formatted message or "No message."
* @deprecated since 9.5.0 use {@link OperatorException#getErrorMessage(S
tring, Object[])} instead
*/
@Deprecated
public static String getErrorMessage(int code, Object[] arguments) { public static String getErrorMessage(int code, Object[] arguments) {
String message = getResourceString(code, "short", "No message."); return getErrorMessage("" + code, arguments);
return addArguments(arguments, message);
}
public static String getErrorMessage(String identifier, Object[] argument
s) {
String message = getResourceString(identifier, "short", "No messa
ge.");
return addArguments(arguments, message);
} }
/** /**
* Adds the arguments to the message. * Returns the short message for the given error code
* *
* @param arguments * @param identifier the error identifier
* @param message * @param arguments the arguments for the message
* @return the message including the arguments or the message of the exce * @return the formatted message or "No message."
ption if one occurs * @deprecated since 9.5.0 use {@link OperatorException#getErrorMessage(S
tring, Object[])} instead
*/ */
private static String addArguments(Object[] arguments, String message) { @Deprecated
try { public static String getErrorMessage(String identifier, Object[] argument
formatter.applyPattern(message); s) {
String formatted = formatter.format(arguments); return OperatorException.getErrorMessage(identifier, arguments);
return formatted;
} catch (Throwable t) {
return message;
}
} }
/** /**
* Returns a resource message for the given error code. * Returns a resource message for the given error code.
* *
* @param key * @param key
* one out of &quot;name&quot;, &quot;short&quot;, &quot;long& quot; * one out of &quot;name&quot;, &quot;short&quot;, &quot;long& quot;
* @return the unformatted resource string
* @deprecated since 9.5.0 use {@link OperatorException#getResourceString
} instead
*/ */
@Deprecated
public static String getResourceString(int code, String key, String deflt ) { public static String getResourceString(int code, String key, String deflt ) {
return getResourceString(code + "", key, deflt); return getResourceString(code + "", key, deflt);
} }
/** /**
* 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 * 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 * 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 * 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 * part of the key, just after error. For example: error.rmx_web.operator .unusable = This
* operator {0} is unusable. * 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.
* @deprecated since 9.5.0 use OperatorException#getResourceString instea d
*/ */
@Deprecated
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 OperatorException.getResourceString(id, key, deflt);
return deflt;
}
try {
return messages.getString("error." + id + "." + key);
} catch (java.util.MissingResourceException e) {
return deflt;
}
} }
@Override
public String getHTMLMessage() {
// return "<html>Error in: <b>" + getOperator() + "</b><br>" + To
ols.escapeXML(getMessage())
// + "<hr>" + Tools.escapeXML(getDetails()) +
// "</html>";
return "<html>Error in: <b>" + getOperator() + "</b><br>" + Tools
.escapeXML(getMessage()) + "</html>";
}
} }
 End of changes. 26 change blocks. 
82 lines changed or deleted 56 lines changed or added

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