From: <mwl...@us...> - 2008-07-08 21:31:59
|
Revision: 787 http://cishell.svn.sourceforge.net/cishell/?rev=787&view=rev Author: mwlinnem Date: 2008-07-08 14:30:47 -0700 (Tue, 08 Jul 2008) Log Message: ----------- Damned new version of Eclipse made me not include the new file. Added Paths: ----------- trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableAlgorithm.java Added: trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableAlgorithm.java =================================================================== --- trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableAlgorithm.java (rev 0) +++ trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableAlgorithm.java 2008-07-08 21:30:47 UTC (rev 787) @@ -0,0 +1,80 @@ +package org.cishell.templates.staticexecutable; + +import java.io.IOException; +import java.net.URL; +import java.util.Dictionary; +import java.util.Properties; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmExecutionException; +import org.cishell.framework.algorithm.ProgressMonitor; +import org.cishell.framework.algorithm.ProgressTrackable; +import org.cishell.framework.data.Data; +import org.osgi.framework.BundleContext; +import org.osgi.service.log.LogService; + +public class StaticExecutableAlgorithm implements Algorithm, ProgressTrackable { + + + Data[] data; + Dictionary parameters; + CIShellContext context; + LogService logger; + + private BundleContext bContext; + private String algName; + + private ProgressMonitor monitor; + + public StaticExecutableAlgorithm(Data[] data, Dictionary parameters, CIShellContext context, BundleContext bContext, String algName) + { + this.data = data; + this.parameters = parameters; + this.context = context; + this.bContext = bContext; + this.algName = algName; + + logger = (LogService)context.getService(LogService.class.getName()); + } + + public Data[] execute() throws AlgorithmExecutionException { + try { + //prepare to run the static executable + + Properties serviceProps = getProperties("/"+algName+"/service.properties"); + Properties configProps = getProperties("/"+algName+"/config.properties"); + + serviceProps.putAll(configProps); + serviceProps.put("Algorithm-Directory", algName); + + StaticExecutableRunner runner = + new StaticExecutableRunner(bContext, context, serviceProps, parameters, data, monitor, algName); + + //run it! + return runner.execute(); + + } catch (IOException e) { + throw new AlgorithmExecutionException(e.getMessage(), e); + } + } + + private Properties getProperties(String entry) throws IOException { + URL url = bContext.getBundle().getEntry(entry); + Properties props = null; + + if (url != null) { + props = new Properties(); + props.load(url.openStream()); + } + return props; + } + + public ProgressMonitor getProgressMonitor() { + return this.monitor; + } + + public void setProgressMonitor(ProgressMonitor monitor) { + this.monitor = monitor; + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |