2
Vote

odatagen fix for ComplexType substring-after(@Type,'.') xsl parser

description

When using odatagen I noticed it uses the "substring-after" function for parsing a ComplexType property generates an invalid class name for ComplexTypes. This has issues if your namespace has more than one period,'.' for your ComplexType. For example, Net.MyCompany.MyComplexType would result in a Objective-C generated type of MyCompany.MyComplexType and will of course not compile.
 
Example that will crash due to odatagen:
 
  • (id) CreateMyComplexTypeid:(NSString )Id creditcard:(Model.MyComplexType )MyComplexType
     
     
     
    Suggested solution:
     
    In these files objc_headers.h and objc_implementations.h
     
    Search for this code: <xsl:value-of select=\"substring-after(@Type,'.')\"/>
    Replace with: <xsl:call-template name=\"substring-after-last\"> <xsl:with-param name=\"input\" select=\"@Type\" /> <xsl:with-param name=\"marker\" select=\"'.'\" /> </xsl:call-template>
     
    Add this code to the char[] of each file:
     
    "<xsl:template name=\"substring-after-last\">\n"\
    "<xsl:param name=\"input\" />\n"\
    "<xsl:param name=\"marker\" />\n"\
    "<xsl:choose>\n"\
    " <xsl:when test=\"contains($input,$marker)\">\n"\
    " <xsl:call-template name=\"substring-after-last\">\n"\
    " <xsl:with-param name=\"input\"\n"\
    " select=\"substring-after($input,$marker)\" />\n"\
    " <xsl:with-param name=\"marker\" select=\"$marker\" />\n"\
    " </xsl:call-template>\n"\
    " </xsl:when>\n"\
    " <xsl:otherwise>\n"\
    " <xsl:value-of select=\"$input\" />\n"\
    " </xsl:otherwise>\n"\
    " </xsl:choose>\n"\
    "</xsl:template>\n"\

comments

slessard wrote Jan 19, 2011 at 4:22 AM

Where exactly within that char[] should that code be added?

CTapang wrote Mar 12, 2011 at 12:20 AM

The xslt files are now separate files, instead of large strings in header files. Version 1.2 fixes this.
The way we fixed this is to allow the user to specify a namespace, which is then used as part of the fully-qualified name of the class. This solution is better than using the service namespace (which is a universally unique namespace, strictly speaking), which is a different universe of namespaces altogether. Collisions are still avoided by allowing the user to specify the namespace of the resulting class.