/*
 * Created on 2004-8-7
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package workflow.live.xpdl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import workflow.wfmc.xpdl.WorkflowApplication;
import workflow.wfmc.xpdl.WorkflowPackage;
import workflow.wfmc.xpdl.WorkflowPackageHeader;
import workflow.wfmc.xpdl.WorkflowParameter;
import workflow.wfmc.xpdl.WorkflowProcess;
import workflow.wfmc.xpdl.WorkflowScript;
import workflow.live.LiveElement;
import workflow.live.LiveService;

/**
 * @author reic
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class LivePackage extends LiveElement
{

	private WorkflowScript script;
	private WorkflowPackageHeader packageHeader = null;

	private Map attributes = new HashMap();

	private List applications = new ArrayList();
	private List parameters = new ArrayList();
	private List processes = new ArrayList();

	private transient LiveService workflow;

	public LivePackage()
	{
	}

	public LivePackage(WorkflowPackage workflowPackage)
	{
		super(workflowPackage);
		
		this.script=workflowPackage.getWorkflowScript();
		this.packageHeader=workflowPackage.getPackageHeader();
		
		this.attributes=workflowPackage.getExtendedAttributes();
		this.applications=workflowPackage.getWorkflowApplications();
		this.parameters=workflowPackage.getWorkflowParameters();
		
		WorkflowProcess workflowProcess = null;
		for (int i = 0; i < workflowPackage.getWorkflowProcesses().size(); ++i)
		{
			workflowProcess = (WorkflowProcess) workflowPackage.getWorkflowProcesses().get(i);
			processes.add(new LiveProcess(workflowProcess));
		}
	}
	
	public WorkflowPackageHeader getPackageHeader()
	{
		return (this.packageHeader);
	}
	public WorkflowApplication findWorkflowApplication(String appId)
	{
		int sizeApp = applications.size();
		WorkflowApplication app = null;
		for (int i = 0; i < sizeApp; ++i)
		{
			app = (WorkflowApplication) applications.get(i);
			if (app.getUUID().equals(appId))
			{
				return app;
			}
		}
		return null;
	}

	public WorkflowParameter findWorkflowParameter(String paramId)
	{
		int sizeParam = parameters.size();
		WorkflowParameter parameter = null;
		for (int i = 0; i < sizeParam; ++i)
		{
			parameter = (WorkflowParameter) parameters.get(i);
			if (parameter.getUUID().equals(paramId))
			{
				return parameter;
			}
		}
		return null;
	}

	public LiveProcess findLiveProcess(String processId)
	{
		int sizeProcess = processes.size();
		LiveProcess workflowProcess = null;
		for (int i = 0; i < sizeProcess; ++i)
		{
			workflowProcess = (LiveProcess) processes.get(i);
			if (workflowProcess.getUUID().equals(processId))
			{
				return workflowProcess;
			}
		}
		return null;
	}

	public Map getExtendedAttributes()
	{
		return (this.attributes);
	}
	public WorkflowScript getWorkflowScript()
	{
		return (this.script);
	}
}
