package org.museautomation.core.task;

import org.museautomation.core.*;
import org.museautomation.core.context.*;
import org.museautomation.core.events.*;
import org.museautomation.core.resource.*;
import org.museautomation.core.resource.types.*;
import org.museautomation.core.task.state.*;

/**
 * @author Christopher L Merrill (see LICENSE.txt for license details)
 */
public abstract class BaseMuseTask extends BaseMuseResource implements MuseTask
    {
    @Override
    public boolean execute(TaskExecutionContext context)
        {
        try
            {
            return executeImplementation(context);
            }
        catch (Throwable e)
            {
            MuseEvent event = TaskErrorEventType.create("An exception was thrown: " + e.getMessage());
            context.raiseEvent(event);
            return false;
            }
        }

    @Override
    public String getDescription()
        {
        return getId();
        }

    protected abstract boolean executeImplementation(TaskExecutionContext context);

    @Override
    public TaskInputSet getInputSet()
        {
        if (_inputs == null)
            _inputs = new TaskInputSet();
        return _inputs;
        }

    public void setInputSet(TaskInputSet inputs)
        {
        _inputs = inputs;
        }

    @Deprecated  // temporarily kept for serialization compatability
    public TaskInputSet getInputs()
        {
        return getInputSet();
        }
    @Deprecated  // temporarily kept for serialization compatability
    public void setInputs(TaskInputSet inputs)
        {
        _inputs = inputs;
        }

    @Override
    public TaskOutputSet getOutputSet()
        {
        return _outputs;
        }

    public void setOutputSet(TaskOutputSet outputs)
        {
        _outputs = outputs;
        }

    public TaskInputStates getInputStates()
        {
        return _in_states;
        }

    public void setInputStates(TaskInputStates in_states)
        {
        _in_states = in_states;
        }

    public TaskOutputStates getOutputStates()
        {
        return _out_states;
        }

    public void setOutputStates(TaskOutputStates out_states)
        {
        _out_states = out_states;
        }

    @Override
    public ResourceType getType()
        {
        return new MuseTask.TaskResourceType();
        }

    private TaskInputSet _inputs = new TaskInputSet();
    private TaskOutputSet _outputs = new TaskOutputSet();
    private TaskInputStates _in_states = new TaskInputStates();
    private TaskOutputStates _out_states = new TaskOutputStates();
    }
@@ -1378,34 +1378,35 @@
 %0A    public Task
-In
+Out
 putSet getInputs
@@ -1399,18 +1399,19 @@
 tSet get
-In
+Out
 puts()%0A 
@@ -1433,26 +1433,27 @@
   return get
-In
+Out
 putSet();%0A  
@@ -1548,18 +1548,19 @@
 void set
-In
+Out
 puts(Tas
@@ -1556,35 +1556,37 @@
 Outputs(Task
-In
+Out
 putSet 
-in
+out
 puts)%0A      
@@ -1594,35 +1594,37 @@
  %7B%0A        _
-in
+out
 puts = 
-in
+out
 puts;%0A      
@@ -1821,32 +1821,350 @@
 uts;%0A        %7D%0A%0A
+    @Deprecated  // temporarily kept for serialization compatability%0A    public TaskInputSet getInputs()%0A        %7B%0A        return getInputSet();%0A        %7D%0A    @Deprecated  // temporarily kept for serialization compatability%0A    public void setInputs(TaskInputSet inputs)%0A        %7B%0A        _inputs = inputs;%0A        %7D%0A%0A
     public TaskI

FIX - fix task serialization problem.