<?php

// imports
require_once 'AlarmManagement/DataTypes/EventSel.php';

/**
 * DataType EventSpec
 *
 * @author     WagnerTech UG <mail@wagnertech.de>
 * @package    SysAl.AlarmManagement.DataType
 */

class EventSpec {
	
	/**
	 * selector:
	 * @var        EventSel
	 */
	private $selector;
	
	/**
	 * value
	 * @var        string
	 */
	private $value;

	/**
	 * constructor: checks validity
	 * 
	 * @param strOrSel  both constructions possible: with complete string or by selector/value pair 
	 * @param value     only if selector/value are specified separately
	 */
	function __construct($strOrSel, $value = null){
	    $this->init($strOrSel, $value);
	}
	function init($strOrSel, $value = null){
	    if ($strOrSel === null) {
	        // default value required for gui handling
	        $this->selector = new EventSel(4);
	        $this->value = "DEFAULT";
	        return $this;
	    }
	    if ($value == null) {
	        $aux_arr = explode ('/', $strOrSel);
	        if (count($aux_arr) != 2)
	            throw new Exception("Invalid EventSpec string: $strOrSel");
	    } else {
	        $aux_arr[0] = $strOrSel;
	        $aux_arr[1] = $value;
	    }
	    $this->selector = new EventSel($aux_arr[0]);
	    $this->value = $aux_arr[1];
	}
	
	function getSelector(){
		return $this->selector;
	}
	
	function getValue(){
		return $this->value;
	}
	
	function __toString(){
		return $this->selector . "/" . $this->value;
	}
}