|
From: <pat...@us...> - 2011-02-11 13:26:24
|
Revision: 1203
http://cishell.svn.sourceforge.net/cishell/?rev=1203&view=rev
Author: pataphil
Date: 2011-02-11 13:26:16 +0000 (Fri, 11 Feb 2011)
Log Message:
-----------
* Added loadFileOfType methods to FileLoaderService and implementation.
* Removed AlgorithmFactory2
* Potential redesign of AlgorithmInvocationService?
Modified Paths:
--------------
trunk/core/org.cishell.framework/META-INF/MANIFEST.MF
trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoaderService.java
trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/AlgorithmInvocationService.java
trunk/core/org.cishell.reference/META-INF/MANIFEST.MF
trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/AlgorithmInvocationServiceImpl.java
trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/datamanager/DataManagerServiceImpl.java
trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java
trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/PrettyLabeler.java
trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/ValidatorSelectorRunnable.java
Added Paths:
-----------
trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/FakeAlgorithmInvocationService.java
trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/FakeAlgorithmInvocationServiceImpl.java
Removed Paths:
-------------
trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory2.java
Modified: trunk/core/org.cishell.framework/META-INF/MANIFEST.MF
===================================================================
--- trunk/core/org.cishell.framework/META-INF/MANIFEST.MF 2011-02-09 18:22:52 UTC (rev 1202)
+++ trunk/core/org.cishell.framework/META-INF/MANIFEST.MF 2011-02-11 13:26:16 UTC (rev 1203)
@@ -17,6 +17,7 @@
org.cishell.framework.algorithm;version="1.0.0",
org.cishell.framework.data;version="1.0.0",
org.cishell.framework.userprefs;version="1.0.0",
+ org.cishell.service.algorithminvocation,
org.cishell.service.conversion;version="1.0.0",
org.cishell.service.guibuilder;version="1.0.0"
Bundle-ActivationPolicy: lazy
Modified: trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoaderService.java
===================================================================
--- trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoaderService.java 2011-02-09 18:22:52 UTC (rev 1202)
+++ trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoaderService.java 2011-02-11 13:26:16 UTC (rev 1203)
@@ -3,6 +3,7 @@
import java.io.File;
import org.cishell.framework.CIShellContext;
+import org.cishell.framework.algorithm.AlgorithmFactory;
import org.cishell.framework.algorithm.ProgressMonitor;
import org.cishell.framework.data.Data;
import org.osgi.framework.BundleContext;
@@ -29,4 +30,19 @@
LogService logger,
ProgressMonitor progressMonitor,
File file) throws FileLoadException;
+ public Data[] loadFileOfType(
+ BundleContext bundleContext,
+ CIShellContext ciShellContext,
+ LogService logger,
+ ProgressMonitor progressMonitor,
+ File file,
+ String fileExtension,
+ String mimeType) throws FileLoadException;
+ public Data[] loadFileOfType(
+ BundleContext bundleContext,
+ CIShellContext ciShellContext,
+ LogService logger,
+ ProgressMonitor progressMonitor,
+ File file,
+ AlgorithmFactory validator) throws FileLoadException;
}
\ No newline at end of file
Deleted: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory2.java
===================================================================
--- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory2.java 2011-02-09 18:22:52 UTC (rev 1202)
+++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory2.java 2011-02-11 13:26:16 UTC (rev 1203)
@@ -1,7 +0,0 @@
-package org.cishell.framework.algorithm;
-
-import org.osgi.framework.ServiceReference;
-
-public interface AlgorithmFactory2 {
- public void setServiceReference(ServiceReference serviceReference);
-}
\ No newline at end of file
Modified: trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/AlgorithmInvocationService.java
===================================================================
--- trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/AlgorithmInvocationService.java 2011-02-09 18:22:52 UTC (rev 1202)
+++ trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/AlgorithmInvocationService.java 2011-02-11 13:26:16 UTC (rev 1203)
@@ -1,126 +1,20 @@
+package org.cishell.service.algorithminvocation;
-/* TODO: When we have time, we should talk about the design of the Algorithm Invocation Service (if
- * we even use that name in the end).
- * It's somewhat apparent that there is a use for this service, but exactly how it fits into
- * CIShell and all of the tools remains to be fully clarified.
- * This is all commented out for now because the design/use need discussion.
- */
+import java.util.Dictionary;
-//package org.cishell.service.algorithminvocation;
-//
-//import java.util.Dictionary;
-//
-//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.data.Data;
-//
-///**
-// * Provides the caller with various ways of creating algorithms, executing them, and
-// * gathering/mutating parameters.
-// * When creating an algorithm (from a factory), if the factory implements ParameterMutator,
-// * mutateParameters() will be called on it.
-// * All methods can optionally operate on a new thread, which is determined by shouldUseNewThread.
-// */
-//public interface AlgorithmInvocationService {
-// /**
-// * Uses factory to create an algorithm, presenting the user with a GUI for parameters.
-// */
-// public Algorithm createAlgorithm(
-// final AlgorithmFactory factory,
-// final Data[] data,
-// final CIShellContext ciShellContext,
-// boolean shouldUseNewThread)
-// throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException;
-//
-// /**
-// * Uses factory to create an algorithm, using parameters (instead of presenting the user with a
-// * GUI for them).
-// */
-// public Algorithm createAlgorithm(
-// final AlgorithmFactory factory,
-// final Data[] data,
-// final Dictionary<String, Object> parameters,
-// final CIShellContext ciShellContext,
-// boolean shouldUseNewThread)
-// throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException;
-//
-// /**
-// * Invokes algorithm, returning the Data[] result of algorithm.execute().
-// * If logExceptionThrown is true, any exception thrown will be logged to the
-// * default LogService.
-// * If displayRuntimeException is true, the stack trace of any exception thrown will be
-// * displayed in an error message box.
-// */
-// public Data[] invokeAlgorithm(
-// final Algorithm algorithm,
-// final boolean logExceptionThrown,
-// final boolean displayRuntimeException,
-// boolean shouldUseNewThread)
-// throws AlgorithmCanceledException, AlgorithmExecutionException;
-//
-// /**
-// * Invokes algorithm, assuming sensible defaults for inline algorithm execution (that is,
-// * not explicitly invoked from a menu/etc.), and return the Data[] result of
-// * algorithm.execute().
-// * Most likely wraps invokeAlgorithm().
-// */
-// public Data[] simpleInvokeAlgorithm(final Algorithm algorithm, Thread thread)
-// throws AlgorithmCanceledException, AlgorithmExecutionException;
-//
-// /**
-// * Given factory, presents the user with a GUI for parameters to use for creating and executing
-// * an algorithm.
-// * Most likely wraps createAlgorithm() and invokeAlgorithm().
-// */
-// public Data[] createAndInvokeAlgorithm(
-// final AlgorithmFactory factory,
-// final Data[] data,
-// final CIShellContext ciShellContext,
-// final boolean logExceptionThrown,
-// final boolean displayRuntimeException,
-// boolean shouldUseNewThread) throws
-// AlgorithmCreationCanceledException,
-// AlgorithmCreationFailedException,
-// AlgorithmCanceledException,
-// AlgorithmExecutionException;
-//
-// /**
-// * Given factory, uses parameters to create and execute an algorithm.
-// * Most likely wraps createAlgorithm() and invokeAlgorithm().
-// */
-// public Data[] createAndInvokeAlgorithm(
-// final AlgorithmFactory factory,
-// final Data[] data,
-// final Dictionary<String, Object> parameters,
-// final CIShellContext ciShellContext,
-// final boolean logExceptionThrown,
-// final boolean displayRuntimeException,
-// boolean shouldUseNewThread) throws
-// AlgorithmCreationCanceledException,
-// AlgorithmCreationFailedException,
-// AlgorithmCanceledException,
-// AlgorithmExecutionException;
-//
-// /**
-// * Given factory, uses parameters to create and execute an algorithm.
-// * Sensible defaults for inline algorithm execution (that is, not explicitly invoked from a
-// * menu/etc.) are used.
-// * Returns the Data[] result of algorithm.execute().
-// * Most likely wraps createAlgorithm() and simpleInvokeAlgorithm().
-// */
-// public Data[] simpleCreateAndInvokeAlgorithm(
-// final AlgorithmFactory factory,
-// final Data[] data,
-// final Dictionary<String, Object> parameters,
-// CIShellContext ciShellContext,
-// boolean shouldUseNewThread) throws
-// AlgorithmCreationCanceledException,
-// AlgorithmCreationFailedException,
-// AlgorithmCanceledException,
-// AlgorithmExecutionException;
-//}
\ No newline at end of file
+import org.cishell.framework.CIShellContext;
+import org.cishell.framework.algorithm.AlgorithmExecutionException;
+import org.cishell.framework.data.Data;
+import org.osgi.framework.ServiceReference;
+
+public interface AlgorithmInvocationService {
+ public Data[] runAlgorithm(String pid, Data[] inputData) throws AlgorithmExecutionException;
+ public Data[] wrapAlgorithm(
+ String pid,
+ CIShellContext callerCIShellContext,
+ Data[] inputData,
+ Dictionary<String, Object> parameters) throws AlgorithmExecutionException;
+
+ public ServiceReference createUniqueServiceReference(ServiceReference actualServiceReference);
+ public CIShellContext createUniqueCIShellContext(ServiceReference uniqueServiceReference);
+}
\ No newline at end of file
Copied: trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/FakeAlgorithmInvocationService.java (from rev 1194, trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/AlgorithmInvocationService.java)
===================================================================
--- trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/FakeAlgorithmInvocationService.java (rev 0)
+++ trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/FakeAlgorithmInvocationService.java 2011-02-11 13:26:16 UTC (rev 1203)
@@ -0,0 +1,126 @@
+
+/* TODO: When we have time, we should talk about the design of the Algorithm Invocation Service (if
+ * we even use that name in the end).
+ * It's somewhat apparent that there is a use for this service, but exactly how it fits into
+ * CIShell and all of the tools remains to be fully clarified.
+ * This is all commented out for now because the design/use need discussion.
+ */
+
+package org.cishell.service.algorithminvocation;
+
+import java.util.Dictionary;
+
+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.data.Data;
+
+/**
+ * Provides the caller with various ways of creating algorithms, executing them, and
+ * gathering/mutating parameters.
+ * When creating an algorithm (from a factory), if the factory implements ParameterMutator,
+ * mutateParameters() will be called on it.
+ * All methods can optionally operate on a new thread, which is determined by shouldUseNewThread.
+ */
+public interface FakeAlgorithmInvocationService {
+ /**
+ * Uses factory to create an algorithm, presenting the user with a GUI for parameters.
+ */
+ public Algorithm createAlgorithm(
+ final AlgorithmFactory factory,
+ final Data[] data,
+ final CIShellContext ciShellContext,
+ boolean shouldUseNewThread)
+ throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException;
+
+ /**
+ * Uses factory to create an algorithm, using parameters (instead of presenting the user with a
+ * GUI for them).
+ */
+ public Algorithm createAlgorithm(
+ final AlgorithmFactory factory,
+ final Data[] data,
+ final Dictionary<String, Object> parameters,
+ final CIShellContext ciShellContext,
+ boolean shouldUseNewThread)
+ throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException;
+
+ /**
+ * Invokes algorithm, returning the Data[] result of algorithm.execute().
+ * If logExceptionThrown is true, any exception thrown will be logged to the
+ * default LogService.
+ * If displayRuntimeException is true, the stack trace of any exception thrown will be
+ * displayed in an error message box.
+ */
+ public Data[] invokeAlgorithm(
+ final Algorithm algorithm,
+ final boolean logExceptionThrown,
+ final boolean displayRuntimeException,
+ boolean shouldUseNewThread)
+ throws AlgorithmCanceledException, AlgorithmExecutionException;
+
+ /**
+ * Invokes algorithm, assuming sensible defaults for inline algorithm execution (that is,
+ * not explicitly invoked from a menu/etc.), and return the Data[] result of
+ * algorithm.execute().
+ * Most likely wraps invokeAlgorithm().
+ */
+ public Data[] simpleInvokeAlgorithm(final Algorithm algorithm, Thread thread)
+ throws AlgorithmCanceledException, AlgorithmExecutionException;
+
+ /**
+ * Given factory, presents the user with a GUI for parameters to use for creating and executing
+ * an algorithm.
+ * Most likely wraps createAlgorithm() and invokeAlgorithm().
+ */
+ public Data[] createAndInvokeAlgorithm(
+ final AlgorithmFactory factory,
+ final Data[] data,
+ final CIShellContext ciShellContext,
+ final boolean logExceptionThrown,
+ final boolean displayRuntimeException,
+ boolean shouldUseNewThread) throws
+ AlgorithmCreationCanceledException,
+ AlgorithmCreationFailedException,
+ AlgorithmCanceledException,
+ AlgorithmExecutionException;
+
+ /**
+ * Given factory, uses parameters to create and execute an algorithm.
+ * Most likely wraps createAlgorithm() and invokeAlgorithm().
+ */
+ public Data[] createAndInvokeAlgorithm(
+ final AlgorithmFactory factory,
+ final Data[] data,
+ final Dictionary<String, Object> parameters,
+ final CIShellContext ciShellContext,
+ final boolean logExceptionThrown,
+ final boolean displayRuntimeException,
+ boolean shouldUseNewThread) throws
+ AlgorithmCreationCanceledException,
+ AlgorithmCreationFailedException,
+ AlgorithmCanceledException,
+ AlgorithmExecutionException;
+
+ /**
+ * Given factory, uses parameters to create and execute an algorithm.
+ * Sensible defaults for inline algorithm execution (that is, not explicitly invoked from a
+ * menu/etc.) are used.
+ * Returns the Data[] result of algorithm.execute().
+ * Most likely wraps createAlgorithm() and simpleInvokeAlgorithm().
+ */
+ public Data[] simpleCreateAndInvokeAlgorithm(
+ final AlgorithmFactory factory,
+ final Data[] data,
+ final Dictionary<String, Object> parameters,
+ CIShellContext ciShellContext,
+ boolean shouldUseNewThread) throws
+ AlgorithmCreationCanceledException,
+ AlgorithmCreationFailedException,
+ AlgorithmCanceledException,
+ AlgorithmExecutionException;
+}
\ No newline at end of file
Property changes on: trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/FakeAlgorithmInvocationService.java
___________________________________________________________________
Added: svn:mergeinfo
+
Modified: trunk/core/org.cishell.reference/META-INF/MANIFEST.MF
===================================================================
--- trunk/core/org.cishell.reference/META-INF/MANIFEST.MF 2011-02-09 18:22:52 UTC (rev 1202)
+++ trunk/core/org.cishell.reference/META-INF/MANIFEST.MF 2011-02-11 13:26:16 UTC (rev 1203)
@@ -9,6 +9,7 @@
org.cishell.framework.algorithm;version="1.0.0",
org.cishell.framework.data;version="1.0.0",
org.cishell.reference.gui.common,
+ org.cishell.service.algorithminvocation,
org.cishell.service.conversion;version="1.0.0",
org.cishell.service.guibuilder;version="1.0.0",
org.osgi.framework,
Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/AlgorithmInvocationServiceImpl.java
===================================================================
--- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/AlgorithmInvocationServiceImpl.java 2011-02-09 18:22:52 UTC (rev 1202)
+++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/AlgorithmInvocationServiceImpl.java 2011-02-11 13:26:16 UTC (rev 1203)
@@ -1,85 +1,35 @@
-//package org.cishell.reference.app.service.algorithminvocation;
-//
-//import java.util.Dictionary;
-//import java.util.Hashtable;
-//
-//import org.cishell.framework.CIShellContext;
-//import org.cishell.framework.algorithm.Algorithm;
-//import org.cishell.framework.algorithm.AlgorithmCreationCanceledException;
-//import org.cishell.framework.algorithm.AlgorithmCreationFailedException;
-//import org.cishell.framework.algorithm.AlgorithmFactory;
-//import org.cishell.framework.data.Data;
-//import org.cishell.service.algorithminvocation.AlgorithmInvocationService;
-//import org.osgi.service.log.LogService;
-//
-//public class AlgorithmInvocationServiceImpl implements AlgorithmInvocationService {
-// private LogService logger;
-//
-// public AlgorithmInvocationServiceImpl(LogService logger) {
-// this.logger = logger;
-// }
-//
-// @SuppressWarnings("unchecked")
-// public Algorithm createAlgorithm(
-// final AlgorithmFactory factory,
-// final Data[] data,
-// final CIShellContext ciShellContext,
-// boolean shouldUseNewThread)
-// throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException {
-// /* TODO: Refactor org.cishell.utilities into several plugins so there are no
-// * circular dependencies!
-// */
-//
-// final AlgorithmCreationCanceledException[] canceledException =
-// new AlgorithmCreationCanceledException[1];
-// final AlgorithmCreationFailedException[] failedException =
-// new AlgorithmCreationFailedException[1];
-// final Algorithm[] algorithm = new Algorithm[1];
-//
-// Runnable operator = new Runnable() {
-// public void run() {
-// /* TODO: Refactor algorithm creation code out of
-// * org.cishell.reference.gui.menumanager, and call it here.
-// */
-//
-// try {
-// // TODO: readFromMetadataFile
-// Dictionary<String, Object> parameters = new Hashtable<String, Object>();
-// // TODO: mutateParameters
-// Dictionary<String, Object> mutatedParameters = parameters;
-// // TODO: Invoke GUI builder service, getting user-entered parameters.
-// Dictionary<String, Object> userEnteredParameters = mutatedParameters;
-//
-// algorithm[0] =
-// factory.createAlgorithm(data, userEnteredParameters, ciShellContext);
-// } catch (AlgorithmCreationCanceledException e) {
-// canceledException[0] = e;
-// } catch (AlgorithmCreationFailedException e) {
-// failedException[0] = e;
-// }
-// }
-// };
-//
-// if (shouldUseNewThread) {
-// new Thread(operator).start();
-// } else {
-// operator.run();
-// }
-//
-// return algorithm[0];
-// }
-//
-// public Algorithm createAlgorithm(
-// final AlgorithmFactory factory,
-// final Data[] data,
-// final Dictionary<String, Object> parameters,
-// final CIShellContext ciShellContext,
-// boolean shouldUseNewThread)
-// throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException {
-// final AlgorithmCreationCanceledException[] canceledException =
-// new AlgorithmCreationCanceledException[1];
-// final AlgorithmCreationFailedException[] failedException =
-// new AlgorithmCreationFailedException[1];
-//
-// }
-//}
\ No newline at end of file
+package org.cishell.reference.app.service.algorithminvocation;
+
+import java.util.Dictionary;
+
+import org.cishell.framework.CIShellContext;
+import org.cishell.framework.algorithm.AlgorithmExecutionException;
+import org.cishell.framework.data.Data;
+import org.cishell.service.algorithminvocation.AlgorithmInvocationService;
+import org.osgi.framework.ServiceReference;
+
+public class AlgorithmInvocationServiceImpl implements AlgorithmInvocationService {
+ public Data[] runAlgorithm(String pid, Data[] inputData) throws AlgorithmExecutionException {
+ // TODO: AlgorithmWrapper, etc.
+ return null;
+ }
+
+ public Data[] wrapAlgorithm(
+ String pid,
+ CIShellContext callerCIShellContext,
+ Data[] inputData,
+ Dictionary<String, Object> parameters) throws AlgorithmExecutionException {
+ // TODO: Get the algorithm, call it, etc.
+ return null;
+ }
+
+ public ServiceReference createUniqueServiceReference(ServiceReference actualServiceReference) {
+ // TODO
+ return null;
+ }
+
+ public CIShellContext createUniqueCIShellContext(ServiceReference uniqueServiceReference) {
+ // TODO:
+ return null;
+ }
+}
\ No newline at end of file
Copied: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/FakeAlgorithmInvocationServiceImpl.java (from rev 1191, trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/AlgorithmInvocationServiceImpl.java)
===================================================================
--- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/FakeAlgorithmInvocationServiceImpl.java (rev 0)
+++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/FakeAlgorithmInvocationServiceImpl.java 2011-02-11 13:26:16 UTC (rev 1203)
@@ -0,0 +1,86 @@
+package org.cishell.reference.app.service.algorithminvocation;
+//package org.cishell.reference.app.service.algorithminvocation;
+//
+//import java.util.Dictionary;
+//import java.util.Hashtable;
+//
+//import org.cishell.framework.CIShellContext;
+//import org.cishell.framework.algorithm.Algorithm;
+//import org.cishell.framework.algorithm.AlgorithmCreationCanceledException;
+//import org.cishell.framework.algorithm.AlgorithmCreationFailedException;
+//import org.cishell.framework.algorithm.AlgorithmFactory;
+//import org.cishell.framework.data.Data;
+//import org.cishell.service.algorithminvocation.FakeAlgorithmInvocationService;
+//import org.osgi.service.log.LogService;
+//
+//public class AlgorithmInvocationServiceImpl implements FakeAlgorithmInvocationService {
+// private LogService logger;
+//
+// public AlgorithmInvocationServiceImpl(LogService logger) {
+// this.logger = logger;
+// }
+//
+// @SuppressWarnings("unchecked")
+// public Algorithm createAlgorithm(
+// final AlgorithmFactory factory,
+// final Data[] data,
+// final CIShellContext ciShellContext,
+// boolean shouldUseNewThread)
+// throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException {
+// /* TODO: Refactor org.cishell.utilities into several plugins so there are no
+// * circular dependencies!
+// */
+//
+// final AlgorithmCreationCanceledException[] canceledException =
+// new AlgorithmCreationCanceledException[1];
+// final AlgorithmCreationFailedException[] failedException =
+// new AlgorithmCreationFailedException[1];
+// final Algorithm[] algorithm = new Algorithm[1];
+//
+// Runnable operator = new Runnable() {
+// public void run() {
+// /* TODO: Refactor algorithm creation code out of
+// * org.cishell.reference.gui.menumanager, and call it here.
+// */
+//
+// try {
+// // TODO: readFromMetadataFile
+// Dictionary<String, Object> parameters = new Hashtable<String, Object>();
+// // TODO: mutateParameters
+// Dictionary<String, Object> mutatedParameters = parameters;
+// // TODO: Invoke GUI builder service, getting user-entered parameters.
+// Dictionary<String, Object> userEnteredParameters = mutatedParameters;
+//
+// algorithm[0] =
+// factory.createAlgorithm(data, userEnteredParameters, ciShellContext);
+// } catch (AlgorithmCreationCanceledException e) {
+// canceledException[0] = e;
+// } catch (AlgorithmCreationFailedException e) {
+// failedException[0] = e;
+// }
+// }
+// };
+//
+// if (shouldUseNewThread) {
+// new Thread(operator).start();
+// } else {
+// operator.run();
+// }
+//
+// return algorithm[0];
+// }
+//
+// public Algorithm createAlgorithm(
+// final AlgorithmFactory factory,
+// final Data[] data,
+// final Dictionary<String, Object> parameters,
+// final CIShellContext ciShellContext,
+// boolean shouldUseNewThread)
+// throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException {
+// final AlgorithmCreationCanceledException[] canceledException =
+// new AlgorithmCreationCanceledException[1];
+// final AlgorithmCreationFailedException[] failedException =
+// new AlgorithmCreationFailedException[1];
+//
+// }
+//}
\ No newline at end of file
Property changes on: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/FakeAlgorithmInvocationServiceImpl.java
___________________________________________________________________
Added: svn:mergeinfo
+
Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/datamanager/DataManagerServiceImpl.java
===================================================================
--- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/datamanager/DataManagerServiceImpl.java 2011-02-09 18:22:52 UTC (rev 1202)
+++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/datamanager/DataManagerServiceImpl.java 2011-02-11 13:26:16 UTC (rev 1203)
@@ -16,7 +16,6 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -27,85 +26,76 @@
public class DataManagerServiceImpl implements DataManagerService {
- private Map modelToLabelMap;
- private Map labelToModelMap;
- private Map labelToNumOccurrences;
- private Set models;
- private Set selectedModels;
-
- private Set listeners;
-
- /**
- * Creates a new BasicModelManager Object.
- */
- public DataManagerServiceImpl() {
- modelToLabelMap = new HashMap();
- labelToModelMap = new HashMap();
- labelToNumOccurrences = new HashMap();
- models = new HashSet();
- listeners = new HashSet();
- }
+ private Map<Data, String> datumToLabel = new HashMap<Data, String>();
+ private Map<String, Data> labelToDatum = new HashMap<String, Data>();
+ private Map<String, Integer> labelToOccurrenceCount = new HashMap<String, Integer>();
+ private Set<Data> data = new HashSet<Data>();
+ private Set<Data> selectedData = new HashSet<Data>();
+ private Set<DataManagerListener> listeners = new HashSet<DataManagerListener>();
- /**
- * @see edu.iu.iv.core.ModelManager#addData(java.lang.Object)
- */
- public void addData(Data model) {
- if(model == null){
+ public void addData(Data datum) {
+ if (datum == null) {
return;
}
- String label = (String)model.getMetadata().get(DataProperty.LABEL);
- String type = (String)model.getMetadata().get(DataProperty.TYPE);
+
+ String label = (String) datum.getMetadata().get(DataProperty.LABEL);
+ String type = (String) datum.getMetadata().get(DataProperty.TYPE);
- if(type == null){
+ if (type == null) {
type = DataProperty.OTHER_TYPE;
- model.getMetadata().put(DataProperty.TYPE, type);
+ datum.getMetadata().put(DataProperty.TYPE, type);
}
- //generate label if needed
- if(label == null || label.equals("")){
- StackTraceElement[] stack = new Throwable().getStackTrace();
-
- if (stack.length > 2) {
- String className = stack[2].getClassName();
- int lastDot = className.lastIndexOf(".");
-
- if (className.length() > lastDot) {
- lastDot++;
- className = className.substring(lastDot);
-
- if (className.endsWith("Algorithm")) {
- className = className.substring(0,className.lastIndexOf("Algorithm"));
- }
-
- if (className.endsWith("Factory")) {
- className = className.substring(0,className.lastIndexOf("Factory"));
- }
- }
- label = className;
- } else {
- label = "Unknown";
- }
-
- label = label + "." + type;
+ // Generate label if needed.
+ if ((label == null) || "".equals(label)) {
+ label = generateDefaultLabel(type);
}
- addModel(model, label);
-
- for (Iterator iter=listeners.iterator(); iter.hasNext();) {
- ((DataManagerListener) iter.next()).dataAdded(model, label);
+ addModel(datum, label);
+
+ for (DataManagerListener listener : this.listeners) {
+ listener.dataAdded(datum, label);
}
}
- private void addModel(Data model, String label) {
+ private void addModel(Data datum, String label) {
label = findUniqueLabel(label);
- model.getMetadata().put(DataProperty.LABEL, label);
- //set the model to be unsaved initially
- model.getMetadata().put(DataProperty.MODIFIED, new Boolean(true));
+ datum.getMetadata().put(DataProperty.LABEL, label);
+ // Set the model to be unsaved initially.
+ datum.getMetadata().put(DataProperty.MODIFIED, new Boolean(true));
- modelToLabelMap.put(model, label);
- labelToModelMap.put(label, model);
- models.add(model);
+ this.datumToLabel.put(datum, label);
+ this.labelToDatum.put(label, datum);
+ this.data.add(datum);
}
+
+ private String generateDefaultLabel(String dataType) {
+ String label;
+ StackTraceElement[] stack = new Throwable().getStackTrace();
+
+ if (stack.length > 2) {
+ String className = stack[2].getClassName();
+ int lastDot = className.lastIndexOf(".");
+
+ if (className.length() > lastDot) {
+ lastDot++;
+ className = className.substring(lastDot);
+
+ if (className.endsWith("Algorithm")) {
+ className = className.substring(0,className.lastIndexOf("Algorithm"));
+ }
+
+ if (className.endsWith("Factory")) {
+ className = className.substring(0,className.lastIndexOf("Factory"));
+ }
+ }
+ label = className;
+ } else {
+ label = "Unknown";
+ }
+
+ return String.format("%s.%s", label, dataType);
+ }
/**
* Ensures that the label is unique by comparing it to the labels
@@ -117,16 +107,17 @@
*/
private String findUniqueLabel(String label) {
- Integer numOccurences = (Integer) labelToNumOccurrences.get(label);
+ Integer occurenceCount = this.labelToOccurrenceCount.get(label);
- if (numOccurences == null) {
+ if (occurenceCount == null) {
//the label is unique
- labelToNumOccurrences.put(label, new Integer(1));
+ this.labelToOccurrenceCount.put(label, new Integer(1));
+
return label;
} else {
- //the label is not unique
- int numOccurrencesVal = numOccurences.intValue();
+ // The label is not unique.
+ int numOccurrencesVal = occurenceCount.intValue();
int newNumOccurrencesVal = numOccurrencesVal + 1;
@@ -146,8 +137,7 @@
/*
* remember how many occurrences of the original label we have.
*/
- labelToNumOccurrences.put(label,
- new Integer(newNumOccurrencesVal));
+ this.labelToOccurrenceCount.put(label, new Integer(newNumOccurrencesVal));
/*
* also, remember that we now have a new label which might be
@@ -159,7 +149,7 @@
* of whatever.xml). Maybe not the best way to do this, but
* it makes sense.
*/
- labelToNumOccurrences.put(newLabel, new Integer(1));
+ this.labelToOccurrenceCount.put(newLabel, new Integer(1));
return newLabel;
}
@@ -206,69 +196,65 @@
}
- public void removeData(Data model) {
- String label = getLabel(model);
+ public void removeData(Data datum) {
+ String label = getLabel(datum);
- labelToModelMap.remove(label);
- modelToLabelMap.remove(model);
- labelToNumOccurrences.remove(label);
- models.remove(model);
-
- for (Iterator iter=listeners.iterator(); iter.hasNext();) {
- ((DataManagerListener) iter.next()).dataRemoved(model);
+ this.labelToDatum.remove(label);
+ this.datumToLabel.remove(datum);
+ this.labelToOccurrenceCount.remove(label);
+ this.data.remove(datum);
+
+ for (DataManagerListener listener : this.listeners) {
+ listener.dataRemoved(datum);
}
}
public Data[] getSelectedData() {
- if (selectedModels == null) {
- selectedModels = new HashSet();
- }
-
- return (Data[]) selectedModels.toArray(new Data[]{});
+ return this.selectedData.toArray(new Data[0]);
}
- public void setSelectedData(Data[] inModels) {
- selectedModels = new HashSet(Arrays.asList(inModels));
+ public void setSelectedData(Data[] data) {
+ this.selectedData.clear();
+ this.selectedData.addAll(Arrays.asList(data));
- for (int i=0; i < inModels.length; i++) {
- if (!this.models.contains(inModels[i])) {
- addData(inModels[i]);
+ for (int ii = 0; ii < data.length; ii++) {
+ if (!this.data.contains(data[ii])) {
+ addData(data[ii]);
}
}
-
- for (Iterator iter=listeners.iterator(); iter.hasNext();) {
- ((DataManagerListener) iter.next()).dataSelected(inModels);
+
+ for (DataManagerListener listener : this.listeners) {
+ listener.dataSelected(data);
}
}
- private Data getModelForLabel(String label){
- return (Data)labelToModelMap.get(label);
+ private Data getModelForLabel(String label) {
+ return this.labelToDatum.get(label);
}
- public String getLabel(Data model){
- return (String)modelToLabelMap.get(model);
+ public String getLabel(Data datum) {
+ return this.datumToLabel.get(datum);
}
- public synchronized void setLabel(Data model, String label) {
- label = findUniqueLabel(label);
-
- modelToLabelMap.put(model, label);
- labelToModelMap.put(label, model);
-
- for (Iterator iter=listeners.iterator(); iter.hasNext();) {
- ((DataManagerListener) iter.next()).dataLabelChanged(model, label);
+ public synchronized void setLabel(Data datum, String label) {
+ String uniqueLabel = findUniqueLabel(label);
+ this.datumToLabel.put(datum, uniqueLabel);
+ this.labelToDatum.put(uniqueLabel, datum);
+
+ for (DataManagerListener listener : this.listeners) {
+ listener.dataLabelChanged(datum, label);
}
}
public Data[] getAllData() {
- return (Data[]) models.toArray(new Data[]{});
+ return this.data.toArray(new Data[0]);
}
public void addDataManagerListener(DataManagerListener listener) {
- listeners.add(listener);
+ this.listeners.add(listener);
}
public void removeDataManagerListener(DataManagerListener listener) {
- listeners.remove(listener);
+ this.listeners.remove(listener);
}
}
Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java
===================================================================
--- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java 2011-02-09 18:22:52 UTC (rev 1202)
+++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java 2011-02-11 13:26:16 UTC (rev 1203)
@@ -20,6 +20,8 @@
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.osgi.service.log.LogService;
@@ -89,6 +91,62 @@
bundleContext, ciShellContext, logger, progressMonitor, new File[] { file });
}
+ public Data[] loadFileOfType(
+ BundleContext bundleContext,
+ CIShellContext ciShellContext,
+ LogService logger,
+ ProgressMonitor progressMonitor,
+ File file,
+ String fileExtension,
+ String mimeType) throws FileLoadException {
+ try {
+ String format =
+ "(& " +
+ "(type=validator)" +
+ "(| (in_data=file-ext:%1$s) (also_validates=%1$s))" +
+ "(out_data=%2$s))";
+ String validatorsQuery = String.format(format, fileExtension, mimeType);
+ ServiceReference[] supportingValidators = bundleContext.getAllServiceReferences(
+ AlgorithmFactory.class.getName(), validatorsQuery);
+
+ if (supportingValidators == null) {
+ throw new FileLoadException(String.format(
+ "The file %s cannot be loaded as type %s.", file.getName(), mimeType));
+ } else {
+ AlgorithmFactory validator =
+ (AlgorithmFactory) bundleContext.getService(supportingValidators[0]);
+
+ return loadFileOfType(
+ bundleContext, ciShellContext, logger, progressMonitor, file, validator);
+ }
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+
+ throw new FileLoadException(e.getMessage(), e);
+ }
+ }
+
+ public Data[] loadFileOfType(
+ BundleContext bundleContext,
+ CIShellContext ciShellContext,
+ LogService logger,
+ ProgressMonitor progressMonitor,
+ File file,
+ AlgorithmFactory validator) throws FileLoadException {
+ try {
+ Data[] loadedFileData = loadFileInternal(
+ bundleContext, ciShellContext, logger, progressMonitor, file, validator);
+
+ for (FileLoadListener listener : this.listeners) {
+ listener.fileLoaded(file);
+ }
+
+ return loadedFileData;
+ } catch (AlgorithmExecutionException e) {
+ throw new FileLoadException(e.getMessage(), e);
+ }
+ }
+
public void updated(Dictionary preferences) throws ConfigurationException {
if (preferences != null) {
this.preferences = preferences;
@@ -123,15 +181,26 @@
for (File file : files) {
try {
- Data[] validatedFileData = validateFile(
+ AlgorithmFactory validator =
+ getValidatorFromUser(bundleContext, window, display, file);
+
+// Data[] validatedFileData = validateFile(
+// bundleContext,
+// ciShellContext,
+// logger,
+// progressMonitor,
+// window,
+// display,
+// file,
+// validator);
+// Data[] labeledFileData = labelFileData(file, validatedFileData);
+ Data[] labeledFileData = loadFileInternal(
bundleContext,
ciShellContext,
logger,
progressMonitor,
- window,
- display,
- file);
- Data[] labeledFileData = labelFileData(file, validatedFileData);
+ file,
+ validator);
for (Data data : labeledFileData) {
finalLabeledFileData.add(data);
@@ -152,6 +221,29 @@
}
}
+ private Data[] loadFileInternal(
+ BundleContext bundleContext,
+ CIShellContext ciShellContext,
+ LogService logger,
+ ProgressMonitor progressMonitor,
+ File file,
+ AlgorithmFactory validator) throws AlgorithmExecutionException, FileLoadException {
+ IWorkbenchWindow window = getFirstWorkbenchWindow();
+ Display display = PlatformUI.getWorkbench().getDisplay();
+ Data[] validatedFileData = validateFile(
+ bundleContext,
+ ciShellContext,
+ logger,
+ progressMonitor,
+ window,
+ display,
+ file,
+ validator);
+ Data[] labeledFileData = labelFileData(file, validatedFileData);
+
+ return labeledFileData;
+ }
+
private IWorkbenchWindow getFirstWorkbenchWindow() throws FileLoadException {
final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
@@ -182,15 +274,18 @@
ProgressMonitor progressMonitor,
IWorkbenchWindow window,
Display display,
- File file) throws AlgorithmExecutionException {
- AlgorithmFactory validator = null;
- validator = getValidatorFromUser(bundleContext, window, display, file);
-
+ File file,
+ AlgorithmFactory validator) throws AlgorithmExecutionException {
if ((file == null) || (validator == null)) {
String logMessage = "File loading canceled";
logger.log(LogService.LOG_WARNING, logMessage);
} else {
try {
+ System.err.println("file: " + file);
+ System.err.println("validator: " + validator);
+ System.err.println("progressMonitor: " + progressMonitor);
+ System.err.println("ciShellContext: " + ciShellContext);
+ System.err.println("logger: " + logger);
return FileValidator.validateFile(
file, validator, progressMonitor, ciShellContext, logger);
} catch (AlgorithmExecutionException e) {
Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/PrettyLabeler.java
===================================================================
--- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/PrettyLabeler.java 2011-02-09 18:22:52 UTC (rev 1202)
+++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/PrettyLabeler.java 2011-02-11 13:26:16 UTC (rev 1203)
@@ -73,11 +73,17 @@
for (Data datum : data) {
Dictionary<String, Object> labeledDatumMetadata = datum.getMetadata();
- Data dataParent = getParent(labeledDatumMetadata);
- if (!possibleParents.contains(dataParent)) {
- labeledDatumMetadata.put(DataProperty.LABEL, prefix + absoluteFile.getName());
+ Object labelObject = labeledDatumMetadata.get(DataProperty.LABEL);
+
+ if ((labelObject == null) || ("".equals(labelObject.toString()))) {
+ Data dataParent = getParent(labeledDatumMetadata);
+
+ if (!possibleParents.contains(dataParent)) {
+ labeledDatumMetadata.put(DataProperty.LABEL, prefix + absoluteFile.getName());
+ }
+
+ possibleParents.add(datum);
}
- possibleParents.add(datum);
}
return data;
Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/ValidatorSelectorRunnable.java
===================================================================
--- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/ValidatorSelectorRunnable.java 2011-02-09 18:22:52 UTC (rev 1202)
+++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/ValidatorSelectorRunnable.java 2011-02-11 13:26:16 UTC (rev 1203)
@@ -13,38 +13,40 @@
private BundleContext bundleContext;
private File file;
- private AlgorithmFactory validator;
+ private AlgorithmFactory chosenValidator;
public ValidatorSelectorRunnable(
IWorkbenchWindow window, BundleContext bundleContext, File file) {
this.window = window;
this.bundleContext = bundleContext;
this.file = file;
+
}
public AlgorithmFactory getValidator() {
- return this.validator;
+ return this.chosenValidator;
}
public void run() {
String fileExtension =
getFileExtension(this.file.getAbsolutePath()).toLowerCase().substring(1);
- ServiceReference[] supportingValidators = getSupportingValidators(fileExtension);
+ ServiceReference[] supportingValidators =
+ getSupportingValidators(this.bundleContext, fileExtension);
// If there are no supporting validators...
if (supportingValidators.length == 0) {
// Let the user choose from all the validators available.
- ServiceReference[] allValidators = getAllValidators();
+ ServiceReference[] allValidators = getAllValidators(this.bundleContext);
FileFormatSelector validatorSelector = new FileFormatSelector(
"Load", window.getShell(), this.bundleContext, allValidators, this.file);
validatorSelector.open();
- this.validator = validatorSelector.getValidator();
+ this.chosenValidator = validatorSelector.getValidator();
} else if (supportingValidators.length == 1) {
ServiceReference onlyPossibleValidator = supportingValidators[0];
- this.validator =
+ this.chosenValidator =
(AlgorithmFactory)this.bundleContext.getService(onlyPossibleValidator);
}
@@ -52,49 +54,50 @@
FileFormatSelector validatorSelector = new FileFormatSelector(
"Load", window.getShell(), this.bundleContext, supportingValidators, this.file);
validatorSelector.open();
- this.validator = validatorSelector.getValidator();
+ this.chosenValidator = validatorSelector.getValidator();
}
}
- private ServiceReference[] getSupportingValidators(String fileExtension) {
+ public static ServiceReference[] getAllValidators(BundleContext bundleContext) {
try {
- String validatorsQuery =
- "(& (type=validator)" +
- "(|" +
- "(in_data=file-ext:" + fileExtension + ")" +
- "(also_validates=" + fileExtension + ")" +
- "))";
-
- ServiceReference[] supportingValidators = this.bundleContext.getAllServiceReferences(
+ String validatorsQuery = "(&(type=validator)(in_data=file-ext:*))";
+ ServiceReference[] allValidators = bundleContext.getAllServiceReferences(
AlgorithmFactory.class.getName(), validatorsQuery);
- if (supportingValidators == null) {
+ if (allValidators == null) {
return new ServiceReference[0];
} else {
- return supportingValidators;
+ return allValidators;
}
} catch (InvalidSyntaxException e) {
e.printStackTrace();
- return new ServiceReference[]{};
+ return new ServiceReference[0];
}
}
- private ServiceReference[] getAllValidators() {
+ public static ServiceReference[] getSupportingValidators(
+ BundleContext bundleContext, String fileExtension) {
try {
- String validatorsQuery = "(&(type=validator)(in_data=file-ext:*))";
- ServiceReference[] allValidators = this.bundleContext.getAllServiceReferences(
+ String validatorsQuery =
+ "(& (type=validator)" +
+ "(|" +
+ "(in_data=file-ext:" + fileExtension + ")" +
+ "(also_validates=" + fileExtension + ")" +
+ "))";
+
+ ServiceReference[] supportingValidators = bundleContext.getAllServiceReferences(
AlgorithmFactory.class.getName(), validatorsQuery);
- if (allValidators == null) {
+ if (supportingValidators == null) {
return new ServiceReference[0];
} else {
- return allValidators;
+ return supportingValidators;
}
} catch (InvalidSyntaxException e) {
e.printStackTrace();
- return new ServiceReference[0];
+ return new ServiceReference[]{};
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|