Home | Business News | Browse by Publication | X | XML Journal

Model-driven programming using XSLT: an approach to rapid development of domain-specific program generators. (XML Labs).

Publication: XML Journal
Publication Date: 01-AUG-02
Format: Online
Delivery: Immediate Online Access

Article Excerpt
Model-driven programming is a software development paradigm that strives to bring out the abstract model manipulation that we're trying to achieve through a body of programming language code. This approach focuses first on what is being achieved in a computing system and then on how it's being achieved. It's the responsibility of a software subsystem to translate the what to how.

Typically, the purpose of the software subsystem is to generate a concrete implementation from declarative models. This could be viewed as an extension of MVC (Model-View-Controller) architecture by incorporating a generator component (i.e., MVCG).

Adopting a generative approach in software development is a goal cherished by many application developers. Why write repetitive code when a single source of specification can generate the needed variations? Generic programming partially addresses this by allowing us to write template-based code in which the variability is expressed in the template parameter. For example, in C++ Standard Template Library (STL), the concepts of collections, iterators, and algorithms operating over iterators are all implemented in terms of parametric types [T.sub.i]. When we use STL with a concrete type such as a C++ class, the code is generated by a C++ compiler/linker. In software development projects it's desirable to replace repetitive coding with some form of automation, and many times we see a need to achieve this. Custom program generators could replace the volume of manually written code by generating code from domain-specific models. Less manually written code is a good thing.

Plenty of software products around us apply the concept of model-driven development. Consider, for example, a professional HTML editor. The user interface assists the user in developing the Web site through a look-and-feel visual approach. The editor will generate HTML, JavaScript, JSP/ASP, JDBC programs, and other software artifacts based on the model of the Web site that the user has built through the highly intuitive visual interface. However, these products are built to perform specific tasks that may not be of use in general software development. My point is that there's a dearth of tools to facilitate the rapid translation of domain-specific models into desired programming language constructs.

Compiler-compilers (CC) are tools that help in the building of program generators. The input specification to CC is typically language grammar. Based on the input syntax, the CC generates a parsing/lexing framework, which then builds a custom program generator. You can build a C compiler by using a CC. In a CC-based code generation approach, the focus on code generation logic is lost due to the distraction of building various infrastructures, such as an abstract syntax tree (AST), syntax and semantic validation, and so on. A rapid approach to program generator development needs tools supporting scripting capabilities with reference to parsing and syntax tree building/visiting. We don't want to spend time and resources in program generator acquisition. Since code generation invariably involves tree walking, the entire focus should be on visiting the syntax tree of the model and generating the output syntax tree.

One view of XML is that it's a metalanguage used to define other domain-specific languages. XML tags, attributes, and namespaces could be used to capture models of application domain concepts. XML model syntactic validity can be checked by tools that enforce XML schema. In-memory representation of XML documents is standardized with the DOM (Document Object Model).

With XSLT you have scripted access to the XML DOM. The XSLT processor parses the XML document to construct the DOM, and XSLT scripts manipulate the DOM input to construct the DOM output. It's possible to construct plaintext source code files from the DOM output. The plaintext output forms one to many source code files.

These facts make the source code generation task extremely easy since the tasks of parsing, validating, and generating code can all be performed with freely available tools in the manner of rapid scripting-based development. Development of a visual modeling interface may require significant effort, but it's not a must-have. Plaintext editors can be used to capture domain-specific models in XML.

In a source code generation scheme a central concern is how to integrate generated code with manually written code. Typically, a framework is generated that is then customized manually. Regeneration caused by model change shouldn't wipe out past customizations. In other words, there should be a clear physical separation of custom code and generated code.

I've found that the inheritance and encapsulation mechanisms of object-oriented languages are a neat way to address this separation concern. More specifically, manually written code could inherit or use generated base classes or interfaces. In the other direction, generated code could also inherit or use handwritten classes. A generated code module/package is kept separate from manually developed modules/packages. In procedural languages the same effect could be achieved by effectively mimicking OO languages. It isn't good practice to mix generated text with handwritten text physically since this approach is brittle from an automation standpoint. Code generation examples in this article are in Java.

Though we're focusing on source code generation in this article, many kinds of documents can be generated out of XML models. For example, from the XML object relational model of domain entities you can generate a PDF file capturing the model in pictorial form. The notable point is that plaintext that can be used for various purposes is generated, source...

View this article FREE - Now for a Limited Time, try Goliath Business News
Free for 3 Days!



More articles from XML Journal
Show report. (web services Edge conference & expo).(SYS-CON's Web Serv..., August 01, 2002
New release of GoXML Transform 3.0. (XML News).(Product Announcement)(..., August 01, 2002
Updated Blaze Advisor from HNC. (XML News).(Blaze Advisor from HNC 4.2..., August 01, 2002
Tamino XML Server integrated with Stellent CM system.(Brief Article), August 01, 2002
Content@ Web from XyEnterprise. (XML News).(Brief Article)(Product Ann..., August 01, 2002

Looking for additional articles?
Search our database of over 3 million articles.

Looking for more in-depth information on this industry?
Search our complete database of Industry & Market reports by text, subject, publication name or publication date.

About Goliath
Whether you're looking for sales prospects, competitive information, company analysis or best practices in managing your organization, Goliath can help you meet your business needs.

Our extensive business information databases empower business professionals with both the breadth and depth of credible, authoritative information they need to support their business goals. Whether it be strategic planning, sales prospecting, company research or defining management best practices - Goliath is your leading source for accurate information.