From: <tho...@us...> - 2008-03-26 21:28:39
|
Revision: 10535 http://cdk.svn.sourceforge.net/cdk/?rev=10535&view=rev Author: thomaskuhn Date: 2008-03-26 14:28:20 -0700 (Wed, 26 Mar 2008) Log Message: ----------- Some clean up and upgrade to Java 5 standards Modified Paths: -------------- cdk-taverna/trunk/src/main/java/org/openscience/cdk/applications/taverna/io/WriteToMDLMolFile.java Modified: cdk-taverna/trunk/src/main/java/org/openscience/cdk/applications/taverna/io/WriteToMDLMolFile.java =================================================================== --- cdk-taverna/trunk/src/main/java/org/openscience/cdk/applications/taverna/io/WriteToMDLMolFile.java 2008-03-26 19:43:54 UTC (rev 10534) +++ cdk-taverna/trunk/src/main/java/org/openscience/cdk/applications/taverna/io/WriteToMDLMolFile.java 2008-03-26 21:28:20 UTC (rev 10535) @@ -25,14 +25,12 @@ */ package org.openscience.cdk.applications.taverna.io; import java.io.BufferedWriter; -import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -40,9 +38,9 @@ import org.openscience.cdk.CDKConstants; import org.openscience.cdk.applications.taverna.CMLChemFile; import org.openscience.cdk.applications.taverna.LocalWorkerCDK; +import org.openscience.cdk.applications.taverna.basicutilities.CMLChemFileWrapper; import org.openscience.cdk.applications.taverna.basicutilities.FileNameGenerator; import org.openscience.cdk.interfaces.IMolecule; -import org.openscience.cdk.interfaces.IMoleculeSet; import org.openscience.cdk.io.MDLWriter; import org.openscience.cdk.math.RandomNumbersTool; @@ -52,7 +50,7 @@ private String[] inputNames = new String[] { "inputStructures"}; private String[] outputNames = new String[] { "Comment" }; - // Region: input and outpout definition + // Region: input and output definition public String[] inputNames() { return inputNames; @@ -71,30 +69,29 @@ // End of region // Region: local worker execution - public Map execute(Map inputs) throws TaskExecutionException { - List inputList = null; - List matchedList = new ArrayList(); + public Map<String, DataThing> execute(Map<String, DataThing> inputs) throws TaskExecutionException { + List<CMLChemFile> inputList = null; + List<String> commentList = new ArrayList<String>(); FileNameGenerator fileNameGenerator = new FileNameGenerator(); int counter = 0; String comment = "false"; - if(inputs.get("inputStructures") != null) { - inputList = (List)((DataThing)(inputs.get("inputStructures"))).getDataObject(); + Map<String, DataThing> outputs = new HashMap<String, DataThing>(); + if(inputs.get(inputNames[0]) != null) { + inputList = CMLChemFileWrapper.getListOfCMLChemfileFromDataThing(inputs.get(inputNames[0])); if (inputList.isEmpty()){ - matchedList.add("no entry in list"); - Map outputs = new HashMap(); - outputs.put(outputNames[0], new DataThing(matchedList)); + commentList.add("no entry in list"); + + outputs.put(outputNames[0], new DataThing(commentList)); return outputs; } } else { - matchedList.add("no entry in map"); - Map outputs = new HashMap(); - outputs.put(outputNames[0], new DataThing(matchedList)); + commentList.add("no entry in map"); + outputs.put(outputNames[0], new DataThing(commentList)); return outputs; } try { String[] mdlContent = new String[1]; - for (Iterator iter = inputList.iterator(); iter.hasNext(); ) { - CMLChemFile file = (CMLChemFile)iter.next(); + for (CMLChemFile file : inputList) { StringWriter writer = new StringWriter(); MDLWriter molWriter = new MDLWriter(writer); for (int i = 0; i < file.getChemSequenceCount(); i++) { @@ -117,7 +114,7 @@ counter++; } comment = "true " + count; - matchedList.add((String)comment); + commentList.add((String)comment); } } } @@ -125,8 +122,7 @@ } catch (Exception exception) { throw new TaskExecutionException(exception); } - Map outputs = new HashMap(); - outputs.put(outputNames[0], new DataThing(matchedList)); + outputs.put(outputNames[0], new DataThing(commentList)); return outputs; } // End of region @@ -155,21 +151,4 @@ } } } - /** - * Method which checks if the path exists and if not if it is possible to - * build. If it is possible to build the path it will be done. - * - * @param path - * Path which will be check - * @throws Exception - */ - private void checkPath(String path) throws Exception { - File file = new File(path); - if (!file.exists()) { - if (!file.mkdirs()) { - throw new Exception("Could not create the directory: " - + file.getPath()); - } - } - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |