package org.syrup.functions;
import org.syrup.Context;
import org.syrup.Function;
import org.syrup.PTask;
import org.syrup.Result;
import org.syrup.helpers.DataImpl;
import org.syrup.helpers.ResultImpl;
import org.syrup.helpers.Utils;
import java.util.logging.Logger;
/**
* Checks if the Task that is connected to the first input is done and if not,
* the first input will be copied to the first output. Otherwise, the first
* input will be copied to first and the second output. Used to detect the termination of
* (partial) Workflows. Could be considered as non-pure(?).
*
* @author Robbert van Dalen
*/
public class Finish implements Function
{
static final String COPYRIGHT = "Copyright 2005 Robbert van Dalen."
+ "At your option, you may copy, distribute, or make derivative works under "
+ "the terms of The Artistic License. This License may be found at "
+ "http://www.opensource.org/licenses/artistic-license.php. "
+ "THERE IS NO WARRANTY; USE THIS PRODUCT AT YOUR OWN RISK.";
private final static Logger logger = Logger.getLogger("org.syrup.functions.Finish");
/**
*/
public Result execute(Context context)
{
try
{
if (Utils.isFull(context.in_1_link()))
{
byte[] i1 = context.in_1_link().content().bytes();
if (context.in_1_link().from().task() != null)
{
if (((PTask) context.in_1_link().from().task()).done())
{
return new ResultImpl(context, true, true, new DataImpl(i1), new DataImpl(i1));
}
else
{
return new ResultImpl(context, true, true, new DataImpl(i1), null);
}
}
else
{
return new ResultImpl(context, true, true, new DataImpl(i1), new DataImpl(i1));
}
}
else
{
throw new Exception("first input needs to be full");
}
}
catch (Throwable e1)
{
return new ResultImpl(context, true, true, null, org.syrup.helpers.Utils.manageError(logger, e1, "Concat error"));
}
}
}