Browse Source

Special processing for extra "Well Known" parent classes.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2197 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 12 years ago
parent
commit
03cd5deb1b
1 changed files with 38 additions and 7 deletions
  1. 38 7
      setup/modelfactory.class.inc.php

+ 38 - 7
setup/modelfactory.class.inc.php

@@ -132,9 +132,7 @@ class ModelFactory
 		$this->oRoot->AppendChild($this->oClasses);
 		foreach (self::$aWellKnownParents as $sWellKnownParent)
 		{
-			$oWKClass = $this->oDOMDocument->CreateElement('class');
-			$oWKClass->setAttribute('id', $sWellKnownParent);
-			$this->oClasses->AppendChild($oWKClass);
+			$this->AddWellKnownParent($sWellKnownParent);
 		}
 		$this->oMenus = $this->oDOMDocument->CreateElement('menus');
 		$this->oRoot->AppendChild($this->oMenus);
@@ -200,9 +198,19 @@ class ModelFactory
 	
 				if (!$oTargetParentNode)
 				{
-					echo "Dumping target doc - looking for '$sPath'<br/>\n";
-					$this->oDOMDocument->firstChild->Dump();
-					throw new Exception("XML datamodel loader: could not find parent node for $oSourceNode->tagName/".$oSourceNode->getAttribute('id')." with parent id $sParentId");
+					if (substr($sParentId, 0, 1) == '/') // Convention for well known classes
+					{
+						$oTargetParentNode = $this->AddWellKnownParent(substr($sParentId, 1));
+						// Remove the leading slash character
+						$oParentNameNode = $oSourceNode->GetOptionalElement('parent')->firstChild; // Get the DOMCharacterData node
+						$oParentNameNode->data = substr($sParentId, 1);
+					}
+					else
+					{
+						echo "Dumping target doc - looking for '$sPath'<br/>\n";
+						$this->oDOMDocument->firstChild->Dump();
+						throw new Exception("XML datamodel loader: could not find parent node for $oSourceNode->tagName / ".$oSourceNode->getAttribute('id')." with parent id $sParentId");
+					}
 				}
 			}
 			else 
@@ -465,6 +473,13 @@ class ModelFactory
 				$oClassNode->SetAttribute('_created_in', $sModuleName);
 			}
 			$oParentNode->AddChildNode($this->oDOMDocument->importNode($oClassNode, true));
+			
+			if (substr($sParentClass, 0, 1) == '/') // Convention for well known parent classes
+			{
+				// Remove the leading slash character
+				$oParentNameNode = $oClassNode->GetOptionalElement('parent')->firstChild; // Get the DOMCharacterData node
+				$oParentNameNode->data = substr($sParentClass, 1);
+			}
 		}
 	}
 	
@@ -601,7 +616,15 @@ EOF
 		$oClassNode = $this->GetNodes("/itop_design/classes//class[@id='$sClassName']")->item(0);
 		if ($oClassNode == null)
 		{
-			return null;
+			if (substr($sClassName, 0, 1) == '/') // Convention: this class is a "well known" parent
+			{
+				return $this->AddWellKnownParent(substr($sClassName, 1));
+			}
+			else
+			{
+				return null;
+			}
+			
 		}
 		elseif ($bFlattenLayers)
 		{
@@ -614,6 +637,14 @@ EOF
 		return $oClassNode;
 	}
 	
+	public function AddWellKnownParent($sWellKnownParent)
+	{
+		$oWKClass = $this->oDOMDocument->CreateElement('class');
+		$oWKClass->setAttribute('id', $sWellKnownParent);
+		$this->oClasses->AppendChild($oWKClass);
+		return $oWKClass;	
+	}
+	
 	public function GetChildClasses($oClassNode, $bFlattenLayers = true)
 	{
 		$sXPath = "class";