<?php
/**
 * @class RemoteDataCenterClass
 * @brief  
 * @details
 */
abstract class RemoteDataCenterClass
{
	protected $url = null, $treeXML = null;	
   protected $baseID = null;
   
   protected $needsArgs = false;
   protected $hasAccessUrl = false;
   
   public $domAmda = null, $dataCenter = null;  
   public $domAmdaName = "base.xml";
   public $additionalArgs = null;
   
   public $tree = null;
   
	/*
	 * @brief Constructor
	*/
	function __construct()
	{		
		$this->baseID = get_class($this);							
	}		
	
	public function param2dd($paramID) 
	{
			$pairs = array(" " => "_","-" => "_","/" => "_","%" => "_","\\" => "_","$" => "_",":" => "_","+" =>"_","#" => "_","@" => "_","." => "_", ">" => "_", "<" => "_", "," => "_", ")" => "", "(" => "_");    
			return strtr($paramID,$pairs); 
	}
	
	public function saveProxy()
	{		
		$this->domAmda->save(RemoteData.$this->baseID."/".$this->domAmdaName);		 		
	}
	
	abstract public function init(); 
	
	
	abstract protected function getRemoteTree();
	abstract protected function setDataCenterAttributes();
	abstract protected function createMissionNodes();
	abstract protected function makeArgumentsList();
// 	abstract protected function createDatasetNodes();
// 	abstract protected function createParameterNodes();
// 	abstract protected function createDatasetGroupNodes($data);
	
	public function initProxy() 
	{	 
		if (!is_dir(RemoteData.$this->baseID))
			mkdir(RemoteData.$this->baseID);
			
		chmod(RemoteData.$this->baseID,0775);	
		
		$this->getRemoteTree();
	} 
	
	public function makeProxy()
	{	
		$this->domAmda = new DOMDocument('1.0', 'utf-8');
		$this->domAmda->formatOutput = TRUE;
		$this->domAmda->preserveWhiteSpace = FALSE;
		
		$dataRoot = $this->domAmda->createElement('dataRoot');
		$dataRoot->setAttribute('xml:id', 'myRemoteData-treeRootNode');
		$this->domAmda->appendChild($dataRoot);	
		
		$this->dataCenter=$this->domAmda->createElement('dataCenter');

		$this->dataCenter->setAttribute('xml:id', $this->baseID);
		$this->dataCenter->setAttribute('name', $this->baseID);		 
		
		$dataRoot->appendChild($this->dataCenter);
		
		$this->setDataCenterAttributes();	
		
		$missionNodes = $this->createMissionNodes();
		
		foreach ($missionNodes as $missionNode)
			$this->dataCenter->appendChild($missionNode);
	}
}
?>