Fixed namespace problem when joining non-SF namespace files. Merge can now process fragement sysdefs of the same rank. HighFidelityModel
authorBob Rosenberg <bob.rosenberg@nokia.com>
Mon, 19 Apr 2010 18:29:46 +0100
branchHighFidelityModel
changeset 164 8309dda95234
parent 163 c004c9299c6f
child 165 ba562c1e2717
Fixed namespace problem when joining non-SF namespace files. Merge can now process fragement sysdefs of the same rank.
sysdeftools/joinsysdef-module.xsl
sysdeftools/joinsysdef.pl
sysdeftools/mergesysdef-module.xsl
sysdeftools/mergesysdef.xsl
--- a/sysdeftools/joinsysdef-module.xsl	Thu Apr 15 16:45:13 2010 +0100
+++ b/sysdeftools/joinsysdef-module.xsl	Mon Apr 19 18:29:46 2010 +0100
@@ -385,7 +385,7 @@
 	<xsl:variable name="prefix" select="name($namespaces[.=$ns])"/>
 	<xsl:attribute name="{name()}">
 	<xsl:choose>
-		<xsl:when test="$prefix = 'id-namespace' or  (not($namespaces[name()='id-prefix']) and $ns=$defaultns)"/> <!-- it's the default namespace, no prefix -->
+		<xsl:when test="$prefix = 'id-namespace' or  (not($namespaces[name()='id-namespace']) and $ns=$defaultns)"/> <!-- it's the default namespace, no prefix -->
 		<xsl:when test="$prefix='' and contains(.,':')">
 			<!-- complex: copy id and copy namespace (namespace should be copied already)-->
 			<xsl:value-of select="."/>
--- a/sysdeftools/joinsysdef.pl	Thu Apr 15 16:45:13 2010 +0100
+++ b/sysdeftools/joinsysdef.pl	Mon Apr 19 18:29:46 2010 +0100
@@ -271,19 +271,15 @@
 				}
 			# if we're here we can just embed the file
 			# no processing logic is done! It's just embedded blindly
-			my  $metadoc = $parser->parsefile ($file);
-			my $item =&firstElement($metadoc->getDocumentElement);
+			my  $metadoc = $parser->parsefile ($link);
+			my $item = $metadoc->getDocumentElement;
 			if(!$item)
 				{
 				print STDERR "Warning: Could not process metadata file: $link\n";
 				next; # do not alter children
 				}
 			$node->removeAttribute('href');
-			foreach my $child (@{$item->getChildNodes})
-				{
-				&blindCopyInto($node,$child);
-				next;
-				}
+			&blindCopyInto($node,$item);
 			}
 		if($node->getAttribute('rel') eq 'link-mapping')
 			{# need to process this now
@@ -745,4 +741,5 @@
 		else {die "cannot process $_";}
 		}
 	close CPP;
+	$? && die "Call to cpp produced an error";
 	}
--- a/sysdeftools/mergesysdef-module.xsl	Thu Apr 15 16:45:13 2010 +0100
+++ b/sysdeftools/mergesysdef-module.xsl	Mon Apr 19 18:29:46 2010 +0100
@@ -18,9 +18,9 @@
 <xsl:template match="/SystemDefinition[starts-with(@schema,'2.') or starts-with(@schema,'1.')]" priority="2" mode="merge-models">
 	<xsl:message terminate="yes">ERROR: Syntax <xsl:value-of select="@schema"/> not supported</xsl:message>
 </xsl:template>
-<xsl:template match="/SystemDefinition[not(systemModel)]" priority="2" mode="merge-models">
+<!--<xsl:template match="/SystemDefinition[not(systemModel)]" priority="2" mode="merge-models">
 	<xsl:message terminate="yes">ERROR: Can only merge stand-alone system models</xsl:message>
-</xsl:template>
+</xsl:template>-->
 
 <!-- stuff for dealing with namespaces -->
 
@@ -130,8 +130,8 @@
  	<xsl:if test="$other[starts-with(@schema,'2.') or starts-with(@schema,'1.')]">
 		<xsl:message terminate="yes">ERROR: Syntax <xsl:value-of select="$other/@schema"/> not supported</xsl:message>
 	</xsl:if>
-	<xsl:if test="not($other/systemModel)">
-		<xsl:message terminate="yes">ERROR: Can only merge stand-alone system models</xsl:message>
+	<xsl:if test="name(*) != name($other/*)">
+		<xsl:message terminate="yes">ERROR: Can only merge system models of the same rank</xsl:message>
 	</xsl:if>
 	 
 	<xsl:copy>
@@ -226,7 +226,7 @@
 			<xsl:copy-of select="$other/@levels"/>
 		</xsl:when>
 		<xsl:when test="contains(concat(' ',normalize-space($other/@levels),' '),' - ')">
-			<!-- if other uses + syntax, then pre/append -->
+			<!-- if other uses - syntax, then pre/append -->
 			<xsl:variable name="lev">
 				<xsl:value-of select="substring-before(concat(' ',normalize-space($other/@levels),' '),' - ')"/>
 				<xsl:value-of select="concat(' ',.,' ')"/>
@@ -316,6 +316,43 @@
 	</xsl:choose>
 </xsl:template>
 
+<xsl:template match="node()" mode="merge-data">
+	<xsl:copy-of select="." />
+</xsl:template>
+
+<xsl:template match="meta" mode="merge-data">
+	<xsl:param name="metas" />
+	<!-- compare this meta against all metas in the  merged doc
+		if they are identical, then ignore this one.
+		identical is computed by translating to a string, normalising some known parts. This might be slow in some cases-->
+	<xsl:variable name="val"><xsl:apply-templates select="." mode="as-xml-text" /></xsl:variable>
+	<xsl:variable name="match">
+		<xsl:for-each select="$metas">
+			<xsl:variable name="cur"><xsl:apply-templates select="." mode="as-xml-text" /></xsl:variable>
+			<xsl:if test="$cur=$val">*</xsl:if>
+		</xsl:for-each>
+	</xsl:variable>
+	<xsl:if test="$match='' ">
+		<xsl:copy-of select="." />
+	</xsl:if>
+</xsl:template>
+
+<xsl:template match="text()[normalize-space(.)='']" mode="as-xml-text"/>
+<xsl:template match="node()" mode="as-xml-text"><xsl:value-of select="."/></xsl:template>
+<xsl:template match="comment()" mode="as-xml-text">&lt;--<xsl:value-of select="."/>--&gt;</xsl:template>
+<xsl:template match="@*" mode="as-xml-text">
+	<xsl:value-of select="concat(' ',name())"/>="<xsl:value-of select="."/>"</xsl:template>
+<xsl:template match="*" mode="as-xml-text">
+	<xsl:value-of select="concat('&lt;',name())"/>
+	<xsl:apply-templates select="@*" mode="as-xml-text"/>
+	<xsl:if test="self::meta and not(@rel)"> rel="Generic"</xsl:if>
+	<xsl:if test="self::meta and not(@type)"> type="auto"</xsl:if>
+	<xsl:text>&gt;</xsl:text>
+	<xsl:apply-templates select="node()" mode="as-xml-text"/>
+	<xsl:value-of select="concat('&lt;/',name(),'&gt;')"/>
+</xsl:template>
+
+
 <xsl:template match="layer | package | collection | component" mode="merge-models">
 	<xsl:param name="other"/>	<!-- the downstream item of the parent's rank that contains a potential items this is merged with -->
 	<xsl:param name="up"/>
@@ -325,6 +362,7 @@
 	<!-- match = this item in the downstream model -->	
 	<xsl:variable name="match" select="$other/*[@id=current()/@id]"/>
 	
+	
 	<!-- prev = the previous item before the current one (no metas, only named items)-->
 	<xsl:variable name="prev" select="preceding-sibling::*[@id][1]"/> 
 
@@ -388,7 +426,10 @@
 			<xsl:otherwise>
 
 				<!--  copy metas and comments in between meta. Do not try to merge metadata between models -->
-				<xsl:copy-of select="meta | $match/meta | comment()[following-sibling::meta]"/>
+				<xsl:apply-templates select="meta | $match/meta | comment()[following-sibling::meta]" mode="merge-data">
+					<xsl:with-param name="metas" select="$match/meta"/>
+				</xsl:apply-templates>
+				<xsl:copy-of select=" $match/meta | $match/comment()[following-sibling::meta]"/>
 				
 				<xsl:apply-templates mode="merge-models">
 					<xsl:with-param name="other" select="$match"/>
--- a/sysdeftools/mergesysdef.xsl	Thu Apr 15 16:45:13 2010 +0100
+++ b/sysdeftools/mergesysdef.xsl	Mon Apr 19 18:29:46 2010 +0100
@@ -22,10 +22,16 @@
 <xsl:variable name="downstream" select="document($Downstream,.)/SystemDefinition"/>
 <xsl:param name="upname">
 	<xsl:choose>
-		<xsl:when test="$downstream[starts-with(@schema,'2.') or starts-with(@schema,'1.')  or not(systemModel)]">
+		<xsl:when test="$downstream[starts-with(@schema,'2.') or starts-with(@schema,'1.')]">
 			<xsl:message terminate="yes">Syntax <xsl:value-of select="@schema"/> not supported</xsl:message>
 		</xsl:when>
-		<xsl:when test="/SystemDefinition/systemModel/@name=$downstream/systemModel/@name">
+		<xsl:when test="name($downstream/*)!=name(/SystemDefinition/*)">
+			<xsl:message terminate="yes">Can only merge fragments of the same rank</xsl:message>
+		</xsl:when>
+<!--		<xsl:when test="$downstream[not(systemModel)]">
+			<xsl:message terminate="yes">Needs to be a standalone system definition</xsl:message>
+		</xsl:when>-->
+		<xsl:when test="/SystemDefinition/systemModel/@name=$downstream/systemModel/@name or not(/SystemDefinition/systemModel/@name)">
 			<xsl:apply-templates mode="origin-term" select="/*">
 				<xsl:with-param name="root">Upstream</xsl:with-param>
 			</xsl:apply-templates>
@@ -36,11 +42,14 @@
 
 <xsl:param name="downname">
 	<xsl:choose>
-		<xsl:when test="/SystemDefinition/systemModel/@name=$downstream/systemModel/@name">
+		<xsl:when test="/SystemDefinition/systemModel/@name=$downstream/systemModel/@name or not($downstream/systemModel/@name)">
 			<xsl:apply-templates mode="origin-term" select="$downstream">	
 				<xsl:with-param name="root">Downstream</xsl:with-param>
 			</xsl:apply-templates>
 			</xsl:when>
+		<xsl:when test="name($downstream/*)!=name(/SystemDefinition/*)">
+			<xsl:message terminate="yes">Can only merge fragments of the same rank</xsl:message>
+		</xsl:when>
 		<xsl:otherwise><xsl:value-of select="$downstream/systemModel/@name"/></xsl:otherwise>
 	</xsl:choose>
 </xsl:param>