Home Page   We Generate Your Software.
Products Services Company Technology Demo Contact Site Map Search
The Somusar/SoProTech[tm] Booklet Series
Volume IX

"Code Generation Somusar Style"

Printer friendly


Contents
1. Introduction
2. Reproducing a POC on Your Computer
3. J2EE Generator
4. .NET Generator
5. PHP Generator
6. Java (J2SE) Generator
7. Bare Bones Multitier Generator
8. XML Processor
9. XML Generator
10. API Generator Producing C and HTML
11. VisualBasic.NET Generator Draft
12. VisualBasic.NET Generator
13. XML to Java Generator
13.1 Proof-of-concept (POC) Information
13.2 Description
13.3 Java Generator: Plain Java objects with hand-written sections
13.3.1 Have a peek into this generator's internal code!
14. PHP/HTML Generator
15. Java and JSP DAO Struts Generator
16. Further Reading

Chapter 13 - XML to Java Generator

13.1 - Proof-of-concept (POC) Information        top

13.2 - Description        top

This POC is based on the Java generator described by Giuseppe Naccarato in his articles "Writing a Code Generator in Java" and "Implement an IOM-Based Code Generator ", published on Java Pro.

Purpose of this POC is to introduce a simple Java generator that translates an XML model into Java classes, that can then be edited by hand and later reused across subsequent generator runs. The generator preserves the contents of editable sections and the previous version of each Java class derived from the XML model. It is thus possible to change the input model, the templates, and the editable sections independently of one another.

For a discussion on editable section, refer to thread "Preserving hand-edits across generation cycles: editable sections" on cgn-talk (you will have to register to access the thread).

The input model for the generator is provided by the same XML file used as input model in the aforementioned articles, augmented with an additional method getDiscount for class Order.

The architecture of this POC generator is shown below.

Figure 2 - XML to Java generator architecture Figure 2 - XML to Java generator architecture

All output files are generated from the input model file listed in the following table.

Table 31 - Input Design Files

File name Source code
model.xml View

13.3 - Java Generator: Plain Java objects with hand-written sections        top

Table 32 - Java Generator: Generated Files

File name Source code
Order.java View
Customer.java View

13.3.1 - Have a peek into this generator's internal code!        top

Table 33 - Java Generator: Sample Generator Internal Code

Description File name Source code
Class generation template xml_jgen/gen_class View
Property declaration template xml_jgen/declare View
Property implementation template xml_jgen/implement View
Mapping of XML types to Java types xml_jgen/java_type View
XML model parser xml_jgen/xml_parse/tag_node.in View
Main generator script main.tefigel View

[Previous chapter]    [Next chapter]    [Back to top]

http:// www.somusar.com  / doc  / booklets  / cg_somusar  - Powered by SoProMach
Copyright © 2003-2012 Somusar - Trademarks - Legal - Privacy - Webmaster