Package org.syrup.functions

Source Code of org.syrup.functions.Abort

package org.syrup.functions;

import org.syrup.Context;
import org.syrup.Function;
import org.syrup.Result;
import org.syrup.helpers.NetworkImpl;
import org.syrup.helpers.NetworkParser;
import org.syrup.helpers.ResultImpl;
import org.syrup.helpers.Utils;
import org.syrup.helpers.WorkflowImpl;

import java.util.logging.Logger;

/**
* Copies the first or second input to the first output but if the second input is full, all Link connections will be broken afterwards. Used mostly in
* conjunction with Finish to terminate Workflows.
*
* @author Robbert van Dalen
*/
public class Abort 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.Abort");

    private final static String nullWorkflow = "<workflow><binding out-1='b-1' out-2='b-2'/><task name='b' functionClass='org.syrup.functions.Abort' orType='true'/></workflow>";

    /**
     */
    public Result execute(Context context)
    {
        try
        {
            ResultImpl im = null;

            if (Utils.isFull(context.in_1_link()))
            {
                im = new ResultImpl(context, true, true, context.in_1_link().content(), null);

            }
            if (Utils.isFull(context.in_2_link()))
            {
                im = new ResultImpl(context, true, true, context.in_2_link().content(), null);
                // [TODO: optimize by prefabricating the NetworkImpl]
                NetworkImpl i = new NetworkParser().parse(nullWorkflow.getBytes());
                // Returns the Workflow.
                return new WorkflowImpl(im, i);
            }
            else
            {
                return im;
            }
        }
        catch (Throwable e1)
        {
            return new ResultImpl(context, true, true, null, org.syrup.helpers.Utils.manageError(logger, e1, "Concat error"));
        }
    }
}
TOP

Related Classes of org.syrup.functions.Abort

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.