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

import java.util.ArrayList;
import java.util.List;

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.mapping.DSHandle;

public class UnwrapClosedList extends VDLFunction {
	public static final Logger logger = Logger.getLogger(UnwrapClosedList.class);
	
	public static final Arg.Positional PA_LIST = new Arg.Positional("list");

	static {
		setArguments(UnwrapClosedList.class, new Arg[] { PA_LIST });
	}

	public Object function(VariableStack stack) throws ExecutionException {
		@SuppressWarnings("unchecked")
        List<DSHandle> l = (List<DSHandle>) PA_LIST.getValue(stack);
		
		List<Object> r = new ArrayList<Object>(l.size());
		
		for (DSHandle h : l) {
		    r.add(h.getValue());
		}
		
		return r;
	}
}

@@ -115,16 +115,38 @@
 il.List;
+%0Aimport java.util.Map;
 %0A%0Aimport
@@ -917,16 +917,222 @@
 %7B%0A%09%09    
+if (h.getType().isArray()) %7B%0A%09%09        Map%3CString, DSHandle%3E m = h.getArrayValue();%0A%09%09        for (DSHandle h2 : m.values()) %7B%0A%09%09            r.add(h2.getValue());%0A%09%09        %7D%0A%09%09    %7D%0A%09%09    else %7B%0A%09%09        
 r.add(h.
@@ -1144,16 +1144,24 @@
 lue());%0A
+%09%09    %7D%0A
 %09%09%7D%0A%09%09%0A%09

deal with array returns such as the ones from @filenames