Created
April 25, 2013 08:55
-
-
Save SlyNet/5458430 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<xsl:stylesheet version="2.0" | |
xmlns:string="http://symphony-cms.com/functions" | |
xmlns:func="http://exslt.org/functions" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
extension-element-prefixes="func"> | |
<xsl:output method="text"/> | |
<xsl:variable name="accessDict"> | |
<accesses> | |
<access key="property" value="Accessor.Property"/> | |
</accesses> | |
</xsl:variable> | |
<xsl:key name="accessByName" match="access" use="string(@key)"/> | |
<xsl:variable name="cascadeDict"> | |
<cascades> | |
<cascade key="all-delete-orphan" value="Cascade.DeleteOrphans" /> | |
<cascade key="all" value="Cascade.All" /> | |
</cascades> | |
</xsl:variable> | |
<xsl:template match="map"> | |
<xsl:for-each select="class"> | |
<xsl:apply-templates select="."/> | |
</xsl:for-each> | |
</xsl:template> | |
<xsl:template match="class"> | |
<xsl:variable name="fullClassName" select="tokenize(@name, ',')[1]"/> | |
<xsl:variable name="className" select="tokenize($fullClassName, '\.')[last()]"/> | |
public class <xsl:value-of select="$className"/>Map : ClassMapping<<xsl:value-of select="$className"/>> | |
{ | |
public <xsl:value-of select="$className"/>Map() | |
{ | |
<xsl:for-each select="child::*"> | |
<xsl:apply-templates select="."/> | |
</xsl:for-each> | |
} | |
} | |
</xsl:template> | |
<xsl:template match="property"> | |
<xsl:param name="prefix"></xsl:param> | |
<xsl:value-of select="$prefix"/>Property(x => x.<xsl:value-of select="@name"/>, pm => { | |
pm.Column("<xsl:value-of select="column/@name"/>"); | |
<xsl:if test="column/@not-null"> | |
pm.NotNullable(<xsl:value-of select="column/@not-null"/>); | |
</xsl:if> | |
}); | |
</xsl:template> | |
<xsl:template match="component"> | |
Component(c => c.<xsl:value-of select="@name"/>, cm => { | |
<xsl:for-each select="child::*"> | |
<xsl:apply-templates select="."> | |
<xsl:with-param name="prefix">cm.</xsl:with-param> | |
</xsl:apply-templates> | |
</xsl:for-each> | |
}); | |
</xsl:template> | |
<xsl:template match="many-to-one"> | |
ManyToOne(x => x.<xsl:value-of select="@name"/>, mto => { | |
mto.Column("<xsl:value-of select="@column"/>"); | |
<xsl:if test="@not-null"> | |
mto.NotNullable(<xsl:value-of select="@not-null"/>); | |
</xsl:if> | |
}); | |
</xsl:template> | |
<xsl:template match="bag"> | |
Bag(x => x.<xsl:value-of select="@name"/>, bm => { | |
bm.Table("<xsl:value-of select="@table"/>"); | |
<xsl:if test="@lazy"> | |
bm.Lazy(CollectionLazy.Lazy); | |
</xsl:if> | |
<xsl:if test="key/@column"> | |
bm.Key(km => km.Column("<xsl:value-of select="key/@column"/>")); | |
</xsl:if> | |
<xsl:if test="@inverse"> | |
bm.Inverse(<xsl:value-of select="@inverse"/>); | |
</xsl:if> | |
bm.Access(<xsl:value-of select="key('accessByName', ./@access ,$accessDict)/@value"/>); <!-- todo: implement--> | |
}, colMap => { | |
<xsl:choose> | |
<xsl:when test="count(./many-to-many) > 0"> | |
colMap.ManyToMany(mtm => { | |
mtm.Column("<xsl:value-of select="many-to-many/@column"/>"); | |
} | |
</xsl:when> | |
<xsl:when test="count(./one-to-many) > 0"> | |
colMap.OneToMany(); | |
</xsl:when> | |
</xsl:choose> | |
})); | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment