ParamNodeClass.php 5.29 KB
<?php

require_once "ParamClbManualNodeClass.php";
require_once "ParamGetAmdaParamNodeClass.php";
require_once "ParamGetDDBaseNodeClass.php";
require_once "ParamGetLocalBaseNodeClass.php";
require_once dirname(__FILE__)."/../Infos/InfoParamNodeClass.php";
require_once dirname(__FILE__)."/../Requests/RequestOutputPlotPanelNodeClass.php";

define ("PARAM_NAME", "param");
define ("PARAM_ID", "xml:id");
define ("PARAM_SAMPLING", "time_resolution");
define ("PARAM_GAP", "gap_threshold");
define ("PARAM_GET", "get");
define ("PARAM_PROCESS", "process");
define ("PARAM_PROCESS_DESCRIPTION", "description");
define ("PARAM_OUTPUT", "output");

abstract class ParamGetTypeEnum
{
	const AMDAPARAM   = "AmdaParam";
	const DDBASE      = "DDBase";
	const LOCALBASE   = "LocalBase";
}

/**
 * @class ParamNodeClass
 * @brief Definition of a parameter for AMDA_Kernel
 * @details
 */
class ParamNodeClass extends NodeClass
{
	public function __construct()
	{
		parent::__construct(PARAM_NAME);
	}

	public function setId($id)
	{
		$this->setAttribute(PARAM_ID, $id);
	}

	public function setSampling($sampling)
	{
		$node = $this->getChildInstanceByName(PARAM_SAMPLING,true);
		$node->setValue($sampling);
	}

	public function setGap($gap)
	{

		$node = $this->getChildInstanceByName(PARAM_GAP,true);
		$node->setValue($gap);
	}

	public function getInfo()
	{
		$infoNode = $this->getChildInstanceByName(INFOPARAM_TAGNAME, false);
		if ($infoNode)
			return $infoNode;
		
		$infoNode = new InfoParamNodeClass();
		$this->addChild($infoNode);
		
		return $infoNode;
	}
	
	public function addClbManual($name = "")
	{
		$clbManualNode = new ParamClbManualNodeClass();
		$clbManualNode->setClbName($name);
		$this->addChildBefore($clbManualNode, PARAM_GET);
		return $clbManualNode;
	}
	
	public function addParamGet($type)
	{
		$node = $this->getChildInstanceByName(PARAM_GET, true);

		switch ($type)
		{
			case ParamGetTypeEnum::AMDAPARAM :
				$paramGet = new ParamGetAmdaParamNodeClass();
				break;
			case ParamGetTypeEnum::DDBASE :
				$paramGet = new ParamGetDDBaseNodeClass();
				break;
			case ParamGetTypeEnum::LOCALBASE :
				$paramGet = new ParamGetLocalBaseNodeClass();
				break;
			default :
				throw new Exception('Param get node not implemented');
		}

		$node->addChild($paramGet);

		return $paramGet;
	}
	
	public function getParamGet()
	{
		$getNode = $this->getChildInstanceByName(PARAM_GET, false);
		if (!$getNode)
			return NULL;
		if (count($getNode->getChildren()) > 0) {
			$getNodes = $getNode->getChildren();
			return $getNodes[0];
		}
		return NULL;
	}

	public function setProcess($process, $process_info)
	{
		$node = $this->getChildInstanceByName(PARAM_PROCESS, true);
		$node->setValue($process);
		$node->setAttribute(PARAM_PROCESS_DESCRIPTION, $process_info);
	}

	public function setOutput()
	{
		$node = $this->getChildInstanceByName(PARAM_OUTPUT, true);
		return $node;
	}
	
	public function getOutput()
	{
		return $this->getChildInstanceByName(PARAM_OUTPUT, false);
	}
	
	public function loadFromNode($xmlNode) 
	{
		$this->setId($this->getXmlNodeAttribute($xmlNode, PARAM_ID));
		
		$samplingXmlNode = $this->getXmlNodeChildByTagName($xmlNode, PARAM_SAMPLING);
		if (isset($samplingXmlNode))
			$this->setSampling($this->getXmlNodeValue($samplingXmlNode));
		
		$gapXmlNode = $this->getXmlNodeChildByTagName($xmlNode, PARAM_GAP);
		if (isset($gapXmlNode))
			$this->setGap($this->getXmlNodeValue($gapXmlNode));
		
		$infoXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_TAGNAME);
		if (isset($infoXmlNode))
			$this->getInfo()->loadFromNode($infoXmlNode);

		foreach ($this->getXmlNodeChildrenByTagName($xmlNode, PARAMCLBMANUAL_TAGNAME) as $clbXmlNode) {
			$this->addClbManual()->loadFromNode($clbXmlNode);
		}
		
		$paramGetXmlNode = $this->getXmlNodeChildByTagName($xmlNode, PARAM_GET);
		if (isset($paramGetXmlNode)) {
			foreach ($this->getXmlNodeChildren($paramGetXmlNode) as $paramGetDefXmlNode) {
				switch ($this->getXmlNodeName($paramGetDefXmlNode)) {
					case PARAMGETAMDAPARAM_NAME :
						$this->addParamGet(ParamGetTypeEnum::AMDAPARAM)->loadFromNode($paramGetDefXmlNode);
						break;
					case PARAMGETDDBASE_NAME :
						$this->addParamGet(ParamGetTypeEnum::DDBASE)->loadFromNode($paramGetDefXmlNode);
						break;
					case PARAMGETLOCALBASE_VI :
						$this->addParamGet(ParamGetTypeEnum::LOCALBASE)->loadFromNode($paramGetDefXmlNode);
						break;
				}
			}
		}
		
		$processXmlNode = $this->getXmlNodeChildByTagName($xmlNode, PARAM_PROCESS);
		if (isset($processXmlNode))
			$this->setProcess($this->getXmlNodeValue($processXmlNode),$this->getXmlNodeAttribute($processXmlNode,PARAM_PROCESS_DESCRIPTION));
		
		$outputNode = $this->setOutput();
		$outputXmlNode = $this->getXmlNodeChildByTagName($xmlNode, PARAM_OUTPUT);
		if (isset($outputXmlNode))
		{
			foreach ($this->getXmlNodeChildren($outputXmlNode) as $outputTypeXmlNode) {
				switch ($this->getXmlNodeName($outputTypeXmlNode))
				{
					case "plot" :
						$plotNode = $outputNode->getChildInstanceByName("plot", TRUE);
						$node = new RequestOutputPlotPanelNodeClass();
						$plotNode->addChild($node);
						$node->loadFromNode($outputTypeXmlNode);
						break;
				}
			}
		}
			
	}
}

?>