Main BLOGGER
Google
WWW THIS BLOG
Friday, March 31, 2006
 
An approach other than C-- for MCWS

Given the XML schema, Java/C#/C++ provides a schema compiler to generate the correspondent language binding. That is, for a schema instance XML snippet, the schema compiler can generate the code to un-marshal XML into object for the specific language. This is also true for X#.

 

For example, in X# schema, we define a method call as

 

    <xs:complexType name="XSharpMethodInvokeStatement">

        <xs:sequence>

            <xs:element name="object" type="XSharpExpression" />

            <xs:element name="param" minOccurs="0" maxOccurs="unbounded">

                <xs:complexType>

                    <xs:sequence>

                        <xs:element name="value" type="XSharpExpression" />

                    </xs:sequence>

                </xs:complexType>

            </xs:element>

        </xs:sequence>

        <xs:attribute name="methodName" type="xs:string" />

        <xs:attribute name="isExternal" type="xs:boolean" default="false" />

    </xs:complexType>

 

Then from the schema compiler or provided by us, we can have the correspondent C++ class

class XSharpMethodInvokeStatement

{

 private:

        XSharpExpression m_object;

        XSharpExpression m_params[];

        std::string m_methodName;

        bool m_isExternal;

public:

       // getter and muter

        void setObject(const XSharpExpression &object);

        XSharpExpression getObject();

 

        void setParams(const XSharpExpression &params[]);

        XSharpExpression[] getParams();

 

        void setMethodName(const std::string methodName);

        std::string getMethodName();

 

        void setIsExternal(bool isExternal);

        bool getIsExternal();

 };

 

//UnMarshalling, from in-memory object to XML or high level languages such as C++/Java/C#

    CppWriter& operator << (CppWriter &o, const XSharpMethodInvokeStatement &methodInvoke);

    CsWriter& operator << (CsWriter &o, const XSharpMethodInvokeStatement &methodInvoke);

    JavaWriter& operator << (JavaWriter &o, const XSharpMethodInvokeStatement &methodInvoke);

    XmlWriter& operator << (XmlWriter& o, const XSharpMethodInvokeStatement &methodInvoke);

 

 //Marshalling, from XML to in-memory object

XmlReader& operator >> (XmlReader & i, XSharpMethodInvokeStatement &methodInvoke);

 

 

 

 

Such that, user can manipulate the code generation just like normal XML string.

 

For example, if user needs to create a method invocation statement, she or he can do

 

XSharpMethodInvokeStatement mis=new XSharpMethodInvokeStatement();

XSharpExpression obj= new XSharpExpression();

obj.setXXX();

mis.setObject(obj);

…..

 

And then simply call “std::cout << mis;”, user can get the X# code.

 

There is no conflict between this approach and C-- approach.

The comparison between them is listed as following:

  1. In C-- approach, user needs to learn the grammar of C--; in Schema Binding, users need to know the schema.
  2. In C-- approach, user writes mobile code in C--; in Schema Binding, user can choose their favorite language as long as it has the schema binding library in hand.
  3. In C-- approach, user depends on a specific compiler to convert C-- code into X#; in Schema Binding, user needs a schema compiler.
  4. C-- is more readable than the XML generation code as above.
  5. It is much harder to maintain C-- than the X# schema
  6. Schema compiler sounds more comfortable in the Web world than C--

 




<< Home

Powered by Blogger

Google
WWW THIS BLOG