/*
 * Created on Dec 26, 2006
 */
package org.griphyn.vdl.karajan.lib.swiftscript;

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.DSHandle;
import org.griphyn.vdl.mapping.RootDataNode;
import org.griphyn.vdl.type.Types;

public class FileNames extends VDLFunction {
	static {
		setArguments(FileNames.class, new Arg[] { PA_VAR });
	}

	public Object function(VariableStack stack) throws ExecutionException {
		String[] f = filename(stack);
		DSHandle[] h = new DSHandle[f.length];
		for (int i = 0; i < f.length; i++) {
			h[i] = RootDataNode.newNode(Types.STRING, relativize(f[i]));
		}
		return h;
	}
}

@@ -352,20 +352,160 @@
 mapping.
-Root
+InvalidPathException;%0Aimport org.griphyn.vdl.mapping.Path;%0Aimport org.griphyn.vdl.mapping.RootDataNode;%0Aimport org.griphyn.vdl.mapping.RootArray
 DataNode
@@ -775,156 +775,376 @@
 ndle
-%5B%5D h = new DSHandle%5Bf.length%5D;%0A%09%09for (int i = 0; i %3C f.length; i++) %7B%0A%09%09%09h%5Bi%5D = RootDataNode.newNode(Types.STRING, relativize(f%5Bi%5D));%0A%09%09%7D%0A%09%09return h
+ returnArray = new RootArrayDataNode(Types.STRING.arrayType());%0A%09%09try %7B%0A%09%09%09for (int i = 0; i %3C f.length; i++) %7B%0A%09%09%09%09Path p = parsePath(%22%5B%22+i+%22%5D%22, stack);%0A%09%09%09%09DSHandle h = returnArray.getField(p);%0A%09%09%09%09h.setValue(relativize(f%5Bi%5D));%0A%09%09%09%7D%0A%09%09%7D catch (InvalidPathException e) %7B%0A%09%09%09throw new ExecutionException(%22Unexpected invalid path exception%22,e);%0A%09%09%7D%0A%09%09return returnArray
 ;%0A%09%7D

Make @filenames return a DSHandle representing an array of strings, rather than a (Java level) array containing DSHandles representing strings.