//----------------------------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.WorkflowPackageHeader;
/**
* Represents a WfMC DTD element that has the similar name.
*/
public class XPDLVersion extends XPDLSimpleComponent
{
	public XPDLVersion(XPDLComplexComponent parent)
	{
		super("XPDLVersion",parent);
	}
	
//==================================================================
	/**
	* The classes that are derived from this class has to give its
	* definition for this method. It is used to insert all members
	* of those classes that are derived from XPDLComp
	* class (or classes that are derived from that class) into
	* one list, and the members that are derived from
	* XPDLAttribute class also to insert into other list.
	* Many methods of this class uses those lists:
	* <code>toXPDL</code> method uses them to properly write an element
	* tag to the XPDL file,
	* <code>fromXPDL</code> method uses them to properly read an element
	* tag from the XPDL file,
	* <code>getPanel</code> method uses them to properly display members
	* of this class,
	* <code>get</code> and <code>set</code> uses them to properly
	* retrieve/set the elements from list, ... and so on
	* <p>NOTE: The order of inserted elements is relevant for XPDL to be
	*          valid (members of classes derived from this class must be
	*          inserted into first mentioned list in the same order that
	*          they are within a corresponding tag for those classes
	*          within WfMC XPDL).
	*/
	public void initComponent()
	{
//	-----------------------------------------------
		super.initComponent();
//	-----------------------------------------------	
	}

	public void structComponent()
	{
		//	-----------------------------------------------
		super.structComponent();
		//	-----------------------------------------------
	}
	
	/**
	* Supposed to be overriden by derived classes to implement
	* element specific reading from an XPDL Model. This implementation
	* satisfies only "simple" elements.
	*/
	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 WorkflowPackageHeader)
			{
				setValue(((WorkflowPackageHeader) workflow_component).getXPDLVersion());
			}
		}
	}

	/**
	* 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 WorkflowPackageHeader)
			{
				((WorkflowPackageHeader) workflow_component).setXPDLVersion(toString());
			}
		}
	}
	
	public void saveComponent(WorkflowComponent workflow_component) 
	{
//	-----------------------------------------------
		super.saveComponent(workflow_component);
//	-----------------------------------------------
		if (workflow_component == null)
		{
			return;
		}

		if (workflow_component instanceof WorkflowPackageHeader)
		{
			((WorkflowPackageHeader) workflow_component).setXPDLVersion(toString());
		}
	}
//==================================================================
}
