[Swift-commit] r2506 - trunk/src/org/griphyn/vdl/karajan/lib

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Fri Feb 6 16:22:01 CST 2009


Author: benc
Date: 2009-02-06 16:22:00 -0600 (Fri, 06 Feb 2009)
New Revision: 2506

Added:
   trunk/src/org/griphyn/vdl/karajan/lib/ExpandArguments.java
Log:
r2498 forgot to add this file

Added: trunk/src/org/griphyn/vdl/karajan/lib/ExpandArguments.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/ExpandArguments.java	                        (rev 0)
+++ trunk/src/org/griphyn/vdl/karajan/lib/ExpandArguments.java	2009-02-06 22:22:00 UTC (rev 2506)
@@ -0,0 +1,72 @@
+package org.griphyn.vdl.karajan.lib;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.TreeSet;
+import java.util.Set;
+import java.util.Iterator;
+
+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.globus.cog.karajan.workflow.futures.FutureNotYetAvailable;
+
+import org.griphyn.vdl.mapping.ArrayDataNode;
+import org.griphyn.vdl.mapping.DSHandle;
+import org.griphyn.vdl.mapping.HandleOpenException;
+import org.griphyn.vdl.mapping.InvalidPathException;
+import org.griphyn.vdl.mapping.Path;
+
+public class ExpandArguments extends VDLFunction {
+	public static final Logger logger = Logger.getLogger(ExpandArguments.class);
+
+	static {
+		setArguments(ExpandArguments.class, new Arg[] { Arg.VARGS });
+	}
+
+	public Object function(VariableStack stack) throws ExecutionException {
+		ArrayList l = new ArrayList();
+		Object[] items = Arg.VARGS.asArray(stack);
+		for (int i = 0; i < items.length; i++) {
+			Object item = items[i];
+			if(!(item instanceof DSHandle)) {
+				throw new RuntimeException("Cannot handle argument implemented by "+item.getClass());
+			}
+
+			if(item instanceof ArrayDataNode) {
+				ArrayDataNode array = (ArrayDataNode) item;
+				Map m=array.getArrayValue();
+				Set keySet = m.keySet();
+				TreeSet sortedKeySet = new TreeSet(new StringsAsIntegersComparator());
+				sortedKeySet.addAll(keySet);
+				Iterator it = sortedKeySet.iterator();
+				while(it.hasNext()) {
+					Object key = it.next();
+					l.add(m.get(key));
+				}
+			} else {
+                       		l.add(item);
+			}
+			// TODO this does not correctly handle structs or
+			// externals - at the moment, probably neither of
+			// those should be usable as a string. It also
+			// does not handle nested arrays. However, none of
+			// those should get here in normal operation due
+			// to static type-checking
+                }
+		return l;
+	}
+
+	class StringsAsIntegersComparator implements Comparator {
+		public int compare(Object l, Object r) {
+			Integer lnum = new Integer((String)l);
+			Integer rnum = new Integer((String)r);
+			return lnum.compareTo(rnum);
+		}
+	}
+
+}
+




More information about the Swift-commit mailing list