[Swift-commit] r4719 - in trunk: libexec src/org/griphyn/vdl/engine src/org/griphyn/vdl/karajan/lib/swiftscript

jonmon at ci.uchicago.edu jonmon at ci.uchicago.edu
Thu Jun 30 18:59:17 CDT 2011


Author: jonmon
Date: 2011-06-30 18:59:17 -0500 (Thu, 30 Jun 2011)
New Revision: 4719

Added:
   trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/ReadStructured.java
Removed:
   trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/ReadData2.java
Modified:
   trunk/libexec/vdl-lib.xml
   trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
Log:
o Renamed readData2 to readStructured. Kept readData2 as an alias to avoid breaking code already using readData2. This alias should be removed eventually.


Modified: trunk/libexec/vdl-lib.xml
===================================================================
--- trunk/libexec/vdl-lib.xml	2011-06-30 16:49:54 UTC (rev 4718)
+++ trunk/libexec/vdl-lib.xml	2011-06-30 23:59:17 UTC (rev 4719)
@@ -4,7 +4,8 @@
 	<!-- string functions library -->
 	<export name="extractint"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.ExtractInt"/></export>
 	<export name="readdata"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.ReadData"/></export>
-	<export name="readdata2"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.ReadData2"/></export>
+	<export name="readdata2"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.ReadStructured"/></export>
+	<export name="readstructured"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.ReadStructured"/></export>
 	<export name="writedata"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.WriteData"/></export>
 	<export name="strcat"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="strcut"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>

Modified: trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java	2011-06-30 16:49:54 UTC (rev 4718)
+++ trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java	2011-06-30 23:59:17 UTC (rev 4719)
@@ -136,6 +136,14 @@
 		readData2.setInvocationMode(INVOCATION_INTERNAL);
 		proceduresMap.put("readData2", readData2);
 
+		ProcedureSignature readStructured = new ProcedureSignature("readStructured");
+		FormalArgumentSignature rStInputArg = new FormalArgumentSignature(true);
+		readStructured.addInputArg(rStInputArg);
+		FormalArgumentSignature rStOutputArg = new FormalArgumentSignature(true);
+		readStructured.addOutputArg(rStOutputArg);
+		readStructured.setInvocationMode(INVOCATION_INTERNAL);
+		proceduresMap.put("readStructured", readStructured);
+
 		ProcedureSignature trace = new ProcedureSignature("trace");
 		trace.setAnyNumOfInputArgs();
 		trace.setInvocationMode(INVOCATION_INTERNAL);

Deleted: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/ReadData2.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/ReadData2.java	2011-06-30 16:49:54 UTC (rev 4718)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/ReadData2.java	2011-06-30 23:59:17 UTC (rev 4719)
@@ -1,122 +0,0 @@
-/*
- * Created on Oct 8, 2007
- */
-package org.griphyn.vdl.karajan.lib.swiftscript;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-
-import org.apache.log4j.Logger;
-import org.globus.cog.karajan.arguments.Arg;
-import org.globus.cog.karajan.stack.VariableStack;
-import org.globus.cog.karajan.workflow.ExecutionException;
-import org.griphyn.vdl.karajan.lib.VDLFunction;
-import org.griphyn.vdl.mapping.AbsFile;
-import org.griphyn.vdl.mapping.DSHandle;
-import org.griphyn.vdl.mapping.HandleOpenException;
-import org.griphyn.vdl.mapping.Path;
-import org.griphyn.vdl.mapping.PhysicalFormat;
-import org.griphyn.vdl.type.Types;
-
-public class ReadData2 extends VDLFunction {
-	public static final Logger logger = Logger.getLogger(ReadData2.class);
-
-	public static final Arg DEST = new Arg.Positional("dest");
-	public static final Arg SRC = new Arg.Positional("src");
-	public static boolean warning;
-
-	static {
-		setArguments(ReadData2.class, new Arg[] { DEST, SRC });
-	}
-
-	protected Object function(VariableStack stack) throws ExecutionException, HandleOpenException {
-		DSHandle dest = (DSHandle) DEST.getValue(stack);
-		DSHandle src = (DSHandle) SRC.getValue(stack);
-		waitFor(stack, src);
-		if (src.getType().equals(Types.STRING)) {
-			readData(dest, (String) src.getValue());
-		}
-		else {
-			PhysicalFormat pf = src.getMapper().map(Path.EMPTY_PATH);
-			if (pf instanceof AbsFile) {
-				AbsFile af = (AbsFile) pf;
-				if (!af.getProtocol().equalsIgnoreCase("file")) {
-					throw new ExecutionException("readData2 only supports local files");
-				}
-				readData(dest, af.getPath());
-			}
-			else {
-				throw new ExecutionException("readData2 only supports reading from files");
-			}
-		}
-		return null;
-	}
-
-	private void readData(DSHandle dest, String path) throws ExecutionException {
-		File f = new File(path);
-		try {
-			BufferedReader br = new BufferedReader(new FileReader(f));
-			try {
-				readLines(dest, br, path);
-			}
-			finally {
-				try {
-					br.close();
-				}
-				catch (IOException e) {
-					e.printStackTrace();
-				}
-			}
-		}
-		catch (Exception e) {
-			throw new ExecutionException(e);
-		}
-	}
-
-	private void readLines(DSHandle dest, BufferedReader br, String path)
-			throws ExecutionException, IOException {
-		int count = 1;
-		String line = br.readLine();
-		while (line != null) {
-			line = line.trim();
-			if (!line.startsWith("#") && !line.equals("")) {
-				try {
-					String[] sp = line.split("=", 2);
-					setValue(dest.getField(Path.parse(sp[0].trim())), sp[1].trim());
-				}
-				catch (Exception e) {
-					throw new ExecutionException(e.getMessage() + " in " + path + ", line " + count
-							+ ": " + line, e);
-				}
-			}
-			line = br.readLine();
-			count++;
-		}
-	}
-
-	private void setValue(DSHandle dest, String s) throws ExecutionException {
-		try {
-			if (dest.getType().equals(Types.INT)) {
-				dest.setValue(new Double(Integer.parseInt(s.trim())));
-			}
-			else if (dest.getType().equals(Types.FLOAT)) {
-				dest.setValue(new Double(s.trim()));
-			}
-			else if (dest.getType().equals(Types.BOOLEAN)) {
-				dest.setValue(new Boolean(s.trim()));
-			}
-			else if (dest.getType().equals(Types.STRING)) {
-				dest.setValue(s);
-			}
-			else {
-				throw new ExecutionException("Don't know how to read type " + dest.getType()
-						+ " for path " + dest.getPathFromRoot());
-			}
-		}
-		catch (NumberFormatException e) {
-			throw new ExecutionException("Could not convert value to number: " + s);
-		}
-	}
-}

Added: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/ReadStructured.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/ReadStructured.java	                        (rev 0)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/ReadStructured.java	2011-06-30 23:59:17 UTC (rev 4719)
@@ -0,0 +1,122 @@
+/*
+ * Created on Oct 8, 2007
+ */
+package org.griphyn.vdl.karajan.lib.swiftscript;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+import org.globus.cog.karajan.arguments.Arg;
+import org.globus.cog.karajan.stack.VariableStack;
+import org.globus.cog.karajan.workflow.ExecutionException;
+import org.griphyn.vdl.karajan.lib.VDLFunction;
+import org.griphyn.vdl.mapping.AbsFile;
+import org.griphyn.vdl.mapping.DSHandle;
+import org.griphyn.vdl.mapping.HandleOpenException;
+import org.griphyn.vdl.mapping.Path;
+import org.griphyn.vdl.mapping.PhysicalFormat;
+import org.griphyn.vdl.type.Types;
+
+public class ReadStructured extends VDLFunction {
+	public static final Logger logger = Logger.getLogger(ReadStructured.class);
+
+	public static final Arg DEST = new Arg.Positional("dest");
+	public static final Arg SRC = new Arg.Positional("src");
+	public static boolean warning;
+
+	static {
+		setArguments(ReadStructured.class, new Arg[] { DEST, SRC });
+	}
+
+	protected Object function(VariableStack stack) throws ExecutionException, HandleOpenException {
+		DSHandle dest = (DSHandle) DEST.getValue(stack);
+		DSHandle src = (DSHandle) SRC.getValue(stack);
+		waitFor(stack, src);
+		if (src.getType().equals(Types.STRING)) {
+			readData(dest, (String) src.getValue());
+		}
+		else {
+			PhysicalFormat pf = src.getMapper().map(Path.EMPTY_PATH);
+			if (pf instanceof AbsFile) {
+				AbsFile af = (AbsFile) pf;
+				if (!af.getProtocol().equalsIgnoreCase("file")) {
+					throw new ExecutionException("readData2 only supports local files");
+				}
+				readData(dest, af.getPath());
+			}
+			else {
+				throw new ExecutionException("readData2 only supports reading from files");
+			}
+		}
+		return null;
+	}
+
+	private void readData(DSHandle dest, String path) throws ExecutionException {
+		File f = new File(path);
+		try {
+			BufferedReader br = new BufferedReader(new FileReader(f));
+			try {
+				readLines(dest, br, path);
+			}
+			finally {
+				try {
+					br.close();
+				}
+				catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+		catch (Exception e) {
+			throw new ExecutionException(e);
+		}
+	}
+
+	private void readLines(DSHandle dest, BufferedReader br, String path)
+			throws ExecutionException, IOException {
+		int count = 1;
+		String line = br.readLine();
+		while (line != null) {
+			line = line.trim();
+			if (!line.startsWith("#") && !line.equals("")) {
+				try {
+					String[] sp = line.split("=", 2);
+					setValue(dest.getField(Path.parse(sp[0].trim())), sp[1].trim());
+				}
+				catch (Exception e) {
+					throw new ExecutionException(e.getMessage() + " in " + path + ", line " + count
+							+ ": " + line, e);
+				}
+			}
+			line = br.readLine();
+			count++;
+		}
+	}
+
+	private void setValue(DSHandle dest, String s) throws ExecutionException {
+		try {
+			if (dest.getType().equals(Types.INT)) {
+				dest.setValue(new Double(Integer.parseInt(s.trim())));
+			}
+			else if (dest.getType().equals(Types.FLOAT)) {
+				dest.setValue(new Double(s.trim()));
+			}
+			else if (dest.getType().equals(Types.BOOLEAN)) {
+				dest.setValue(new Boolean(s.trim()));
+			}
+			else if (dest.getType().equals(Types.STRING)) {
+				dest.setValue(s);
+			}
+			else {
+				throw new ExecutionException("Don't know how to read type " + dest.getType()
+						+ " for path " + dest.getPathFromRoot());
+			}
+		}
+		catch (NumberFormatException e) {
+			throw new ExecutionException("Could not convert value to number: " + s);
+		}
+	}
+}




More information about the Swift-commit mailing list