Location: PHPKode > scripts > UML 2 Classes > uml-2-classes/src/Classes/Dependencies/GeneralizationParser.class.php
<?
/**
 * Parser for the XMI Generalizations
 *
 *@author	Teoni Valois da Mota Silva
 *@name		GeneralizationParser
 *@package	Dependencies
 *@version 	0.1.2
 *
 */

class GeneralizationParser extends XMIParser {
	
	/**
	 * GeneralizationParser's Object constructor
	 *
	 * @param String $xmiFile
	 */
	function GeneralizationParser($data){
		$this->data = $data['UML:Generalization'];
	}
	
	/**
	 * GeneralizationParser's Object destructor
	 *
	 */
	function __destruct(){
		$this->data = null;
	}
	
	/**
	 * Returns the Child's ID of the Generalization
	 *
	 * @param Int $generalizationId
	 * @return String
	 */
	function getChild($generalizationId){
		return $this->data[$generalizationId]['UML:Generalization.child'][0]['UML:Class'][0]['xmi.idref'];
	}
	
	/**
	 * Returns the Parent's ID of the Generalization
	 *
	 * @param Int $generalizationId
	 * @return String
	 */
	function getParent($generalizationId){
		return $this->data[$generalizationId]['UML:Generalization.parent'][0]['UML:Class'][0]['xmi.idref'];
	}
	
	/**
	 * Returns an array containing all
	 * the Childrens's ID  of a given Parent ID
	 * in the file
	 *
	 * @param String $parentXmiID
	 * @return Array
	 */
	function getChildren($parentXmiID){
		$parents = array();
		$numberOfChildren = count($this->data);
		for($i=0;$i<$numberOfChildren;$i++){
			if($this->getParent($i)==$parentXmiID){
				array_push($parents,$this->getChild($i));
			}
		}
		return $parents;
	}
	
	/**
	 * Returns an array containing all
	 * the Parents' ID  of a given Child ID
	 * in the file
	 *
	 * @param String $childXmiID
	 * @return Array
	 */
	function getParents($childXmiID){
		$parents = array();
		$numberOfParents = count($this->data);
		for($i=0;$i<$numberOfParents;$i++){
			if($this->getChild($i)==$childXmiID){
				array_push($parents,$this->getParent($i));
			}
		}
		return $parents;
	}
}
?>
Return current item: UML 2 Classes