|
From: <pat...@us...> - 2010-08-19 17:08:19
|
Revision: 1126
http://cishell.svn.sourceforge.net/cishell/?rev=1126&view=rev
Author: pataphil
Date: 2010-08-19 17:08:12 +0000 (Thu, 19 Aug 2010)
Log Message:
-----------
* AlgorithmFactories can now gracefully fail in mutateParameters() and gracefully cancel/fail in createAlgorithm().
* Reviewed by Micah.
Modified Paths:
--------------
trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java
Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java
===================================================================
--- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2010-08-18 20:39:52 UTC (rev 1125)
+++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2010-08-19 17:08:12 UTC (rev 1126)
@@ -26,6 +26,8 @@
import org.cishell.framework.CIShellContext;
import org.cishell.framework.algorithm.Algorithm;
import org.cishell.framework.algorithm.AlgorithmCanceledException;
+import org.cishell.framework.algorithm.AlgorithmCreationCanceledException;
+import org.cishell.framework.algorithm.AlgorithmCreationFailedException;
import org.cishell.framework.algorithm.AlgorithmExecutionException;
import org.cishell.framework.algorithm.AlgorithmFactory;
import org.cishell.framework.algorithm.AlgorithmProperty;
@@ -100,7 +102,7 @@
}
boolean inputIsValid = testDataValidityIfPossible(factory, data);
-
+
if (!inputIsValid) {
return null;
}
@@ -108,13 +110,28 @@
// Create algorithm parameters.
String metatypePID = getMetaTypeID(serviceReference);
- MetaTypeProvider provider =
- getPossiblyMutatedMetaTypeProvider(metatypePID, pid, factory);
+ // TODO: Refactor this.
+ MetaTypeProvider provider = null;
+
+ try {
+ provider = getPossiblyMutatedMetaTypeProvider(metatypePID, pid, factory);
+ } catch (AlgorithmCreationFailedException e) {
+ String format =
+ "An error occurred when creating the algorithm \"%s\" with the data you " +
+ "provided. (Reason: %s)";
+ String logMessage = String.format(
+ format,
+ serviceReference.getProperty(AlgorithmProperty.LABEL),
+ e.getMessage());
+ log(LogService.LOG_WARNING, logMessage, e);
+
+ return null;
+ }
Dictionary<String, Object> parameters =
getUserEnteredParameters(metatypePID, provider);
- // Check to see if the user cancelled the operation.
+ // Check to see if the user canceled the operation.
if (parameters == null) {
return null;
}
@@ -184,13 +201,31 @@
Data[] data,
Dictionary<String, Object> parameters,
CIShellContext ciContext) {
+ final String algorithmName =
+ (String) serviceReference.getProperty(AlgorithmProperty.LABEL);
// TODO: Call on algorithm invocation service here.
try {
return factory.createAlgorithm(data, parameters, ciContext);
+ } catch (AlgorithmCreationCanceledException e) {
+ String logMessage = String.format(
+ "The algorithm \"%s\" was canceled by the user.",
+ algorithmName,
+ e.getMessage());
+ log(LogService.LOG_WARNING, logMessage, e);
+
+ return null;
+ } catch (AlgorithmCreationFailedException e) {
+ String format = "An error occurred when creating algorithm \"%s\". (Reason: %s)";
+ String errorMessage = String.format(format, algorithmName, e.getMessage());
+ GUIBuilderService builder =
+ (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName());
+ builder.showError("Error!", errorMessage, e);
+ log(LogService.LOG_ERROR, errorMessage, e);
+
+ return null;
} catch (Exception e) {
- String errorMessage =
- "Unexpected error occurred while creating algorithm " + " \"" +
- serviceReference.getProperty(AlgorithmProperty.LABEL) + ".\"";
+ String errorMessage = String.format(
+ "Unexpected error occurred while creating algorithm \"%s\".", algorithmName);
GUIBuilderService builder =
(GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName());
// TODO: This is where uncaught exceptions are displayed.
@@ -244,7 +279,7 @@
outData = algorithm.execute();
} catch (AlgorithmCanceledException e) {
String logMessage = String.format(
- "The algorithm: \"%s\" was canceled by the user. (Reason: %s)",
+ "The algorithm: \"%s\" was canceled by the user.",
algorithmName,
e.getMessage());
log(LogService.LOG_WARNING, logMessage, e);
@@ -327,7 +362,8 @@
}
protected MetaTypeProvider getPossiblyMutatedMetaTypeProvider(
- String metatypePID, String pid, AlgorithmFactory factory) {
+ String metatypePID, String pid, AlgorithmFactory factory)
+ throws AlgorithmCreationFailedException {
MetaTypeProvider provider = null;
MetaTypeService metaTypeService = (MetaTypeService)
Activator.getService(MetaTypeService.class.getName());
@@ -335,18 +371,21 @@
provider = metaTypeService.getMetaTypeInformation(serviceReference.getBundle());
}
- if (factory instanceof ParameterMutator && provider != null) {
+ if ((factory instanceof ParameterMutator) && (provider != null)) {
try {
- ObjectClassDefinition ocd =
- provider.getObjectClassDefinition(metatypePID, null);
- if (ocd == null) logNullOCDWarning(pid, metatypePID);
+ ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatypePID, null);
+
+ if (ocd == null) {
+ logNullOCDWarning(pid, metatypePID);
+ }
+
ocd = ((ParameterMutator) factory).mutateParameters(data, ocd);
+
if (ocd != null) {
provider = new BasicMetaTypeProvider(ocd);
}
} catch (IllegalArgumentException e) {
- log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: "
- + metatypePID, e);
+ log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: " + metatypePID, e);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|