//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010 huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/god4j
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : god4j@lists.sourceforge.net 
 */
//----------------------------END  LICENSE-----------------------------
package org.huihoo.god4j.editor.elements.atoms;
import org.huihoo.god4j.editor.XPDLComplexComponent;
import org.huihoo.god4j.editor.XPDLSimpleComponent;
import org.huihoo.workflow.WorkflowComponent;
import org.huihoo.workflow.xpdl.WorkflowParameter;
/**
* Represents a WfMC DTD element that has the similar name.
*
* @see XPDL
*/
public class XPDLInitialValue extends XPDLSimpleComponent
{
	public XPDLInitialValue(XPDLComplexComponent parent)
	{
		super("InitialValue", parent);
	}

	//==================================================================
	public void initComponent()
	{
		//	-----------------------------------------------
		super.initComponent();
		//	-----------------------------------------------	
	}

	public void structComponent()
	{
		//	-----------------------------------------------
		super.structComponent();
		//	-----------------------------------------------
	}
	
	public void loadComponent()
	{
		//	-----------------------------------------------
		super.loadComponent();
		//	-----------------------------------------------

		XPDLComplexComponent parent_component = getParentComponent();
		if (parent_component !=null )
		{
			WorkflowComponent workflow_component =  parent_component.getWorkflowComponent();

			if (workflow_component == null)
			{
				return;
			}

			if (workflow_component instanceof WorkflowParameter)
			{
				setValue(((WorkflowParameter) workflow_component).getValue());
			}
		}
	}

	/**
	* Supposed to be overriden by derived classes to implement
	* element specific writting to an XPDL Model.
	*
	*/
	public void saveComponent()
	{
    if(isReadOnly())
    {
      return;
    }
    
		//	-----------------------------------------------
		super.saveComponent();
		//	-----------------------------------------------

		XPDLComplexComponent parent_component = getParentComponent();
		if (parent_component !=null )
		{
			WorkflowComponent workflow_component =  parent_component.getWorkflowComponent();

			if (workflow_component == null)
			{
				return;
			}

			if (workflow_component instanceof WorkflowParameter)
			{
				((WorkflowParameter) workflow_component).setValue(toString());
			}
		}
	}

	public void saveComponent(WorkflowComponent workflow_component)
	{
		//	-----------------------------------------------
		super.saveComponent(workflow_component);
		//  -----------------------------------------------
		
		if (workflow_component == null)
		{
			return;
		}
		
		if (workflow_component instanceof WorkflowParameter)
		{
			((WorkflowParameter) workflow_component).setValue(toString());
		}
	}

	//==================================================================
}
