Code Generation Somusar Style

A Pragmatic Introduction

Francesco Aliverti-Piuri

Copyright © 2003-2012 Somusar

Updated on: October 28, 2004

      
      
      
      
      
      
      
      
      
      
      
      
      
      

Copyright © 2003-2012 so.mus.ar. s.a.s.
Via Sangallo 30 - 20133 Milan - Italy
All rights reserved.

Unix is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Limited.

Linux is a registered trademark of Linus Torvalds in the United States and other countries.

Sun, Sun Microsystems, the Sun logo, Solaris, Java, and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.

Symbian and all Symbian-based marks and logos are trademarks of Symbian Software Limited.

Apple and Mac OS are registered trademarks of Apple Computer, Inc. in the United States and other countries.

Intel is a registered trademark of Intel Corporation in the United States and other countries.

PowerPC and CICS are registered trademarks of International Business Machines Corporation in the United States and other countries.

Microsoft, Windows, Visual Basic are either trademarks or registered trademarks of Microsoft Corp. in the United States and/or other countries.

Oracle is a registered trademark, and PL/SQL is a trademark of Oracle Corporation.

SAP and ABAP/4 are registered trademarks of SAP AG in Germany and several other countries.

PostScript is a registered trademark of Adobe Systems Incorporated in the United States and/or other countries.

So.mus.ar, the Somusar logo, Somusar/Software Production Technique, Somusar/Software Production Machine, Somusar/Sisendel, Somusar/Tefigel, Somusar/SoProTech, Somusar/SoProMach, Somusar/Software Entity, Somusar/Software Mold, Somusar/Software Mold Kit, Somusar/Software Mold Building, Somusar/Code Generator Building, Somusar/Generator Building, and Somusar/File Generation Scheme are trademarks of so.mus.ar. s.a.s. in Italy, in the European Union, in the United States of America and other countries.

Other trademarks or service marks referenced herein are property of their respective owners.


Contents
Chapter 1 - Introduction
Chapter 2 - Reproducing a POC on Your Computer
Chapter 3 - J2EE Generator
3.1 - Proof-of-concept (POC) Information
3.2 - Description
3.3 - SQL Generator: SQL Database Schema Script
3.4 - DAO Generator: Data Access Object Pattern
3.5 - POJO Generator: Plain Old Java Object
Chapter 4 - .NET Generator
4.1 - Proof-of-concept (POC) Information
4.2 - Description
4.3 - C# Generator: Database Access Layer
4.4 - ASPX Generator: Test Pages
4.5 - SQL Generator: Building a MySQL database
Chapter 5 - PHP Generator
5.1 - Proof-of-concept (POC) Information
5.2 - Description
5.3 - PHP Generator: Database Access Layer
5.4 - PHP Generator: Test Pages
5.5 - SQL Generator: Building a MySQL database
Chapter 6 - Java (J2SE) Generator
6.1 - Proof-of-concept (POC) Information
6.2 - Description
6.3 - Java Generator
Chapter 7 - Bare Bones Multitier Generator
7.1 - Proof-of-concept (POC) Information
7.2 - Description
7.3 - SQL Generator
7.4 - Java Generator
7.5 - HTML Generator
Chapter 8 - XML Processor
8.1 - Proof-of-concept (POC) Information
8.2 - Description
8.3 - Tefigel Generator
Chapter 9 - XML Generator
9.1 - Proof-of-concept (POC) Information
9.2 - Description
9.3 - XML Generator
Chapter 10 - API Generator Producing C and HTML
10.1 - Proof-of-concept (POC) Information
10.2 - Description
10.3 - C Generator
10.4 - HTML Generator
Chapter 11 - VisualBasic.NET Generator Draft
11.1 - Proof-of-concept (POC) Information
11.2 - Description
Chapter 12 - VisualBasic.NET Generator
12.1 - Proof-of-concept (POC) Information
12.2 - Description
12.3 - VB.NET Generator
12.3.1 - Have a peek into this generator's internal code!
Chapter 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!
Chapter 14 - PHP/HTML Generator
14.1 - Proof-of-concept (POC) Information
14.2 - Description
14.3 - PHP Generator: Database Access Layer
14.4 - PHP Generator: Test Page
14.5 - HTML Generator: Generating HTML forms
14.6 - HTML Generator: Generating HTML documentation files
Chapter 15 - Java and JSP DAO Struts Generator
15.1 - Proof-of-concept (POC) Information
15.2 - Description
15.3 - DVD Manager Generator
15.4 - CD Manager Generator
15.5 - Book Manager Generator
15.6 - Vhs Manager Generator
Chapter 16 - Further Reading

Figures
Figure 1 - J2EE generator architecture
Figure 2 - XML to Java generator architecture

Tables
Table 1 - SQL Generator: Generated Files
Table 2 - SQL Generator: Input Design Files
Table 3 - DAO Generator: Generated Files
Table 4 - DAO Generator: Input Design Files
Table 5 - POJO Generator: Generated Files
Table 6 - POJO Generator: Input Design Files
Table 7 - Input Design Files
Table 8 - C# Generator: Generated Files
Table 9 - ASPX Generator: Generated Files
Table 10 - SQL Generator: Generated Files
Table 11 - Input Design Files
Table 12 - PHP Generator: Generated Files
Table 13 - PHP Generator: Generated Files
Table 14 - SQL Generator: Generated Files
Table 15 - Java Generator: Generated Files
Table 16 - Java Generator: Input Design Files
Table 17 - Input Design Files
Table 18 - SQL Generator: Generated Files
Table 19 - Java Generator: Generated Files
Table 20 - HTML Generator: Generated Files
Table 21 - Tefigel Generator: Generated Files
Table 22 - Tefigel Generator: Input Design Files
Table 23 - XML Generator: Generated Files
Table 24 - XML Generator: Input Design Files
Table 25 - Input Design Files
Table 26 - C Generator: Generated Files
Table 27 - HTML Generator: Generated Files
Table 28 - Input Design Files
Table 29 - VB.NET Generator: Generated Files
Table 30 - VB.NET Generator: Sample Generator Internal Code
Table 31 - Input Design Files
Table 32 - Java Generator: Generated Files
Table 33 - Java Generator: Sample Generator Internal Code
Table 34 - Input Design Files
Table 35 - PHP Generator: Generated Files
Table 36 - PHP Generator: Generated Files
Table 37 - HTML Generator: Generated Files
Table 38 - HTML Generator: Generated Files
Table 39 - Set of generated files
Table 40 - Input Design Files
Table 41 - DVD Manager Generator: Generated Files
Table 42 - CD Manager Generator: Generated Files
Table 43 - Book Manager Generator: Generated Files
Table 44 - Vhs Manager Generator: Generated Files

Chapter 1 - Introduction

This document describes a set of code generation samples realized by means of Somusar/SoProMach[tm]. The document is structured as an archive of software generation proofs-of-concept (POCs). New paragraphs and chapters may be added from time to time.

Purpose of this document is to provide software developers, who are interested in applying code generation techniques, with working samples on what can be achieved using the SoProMach[tm] generation engine in different contexts.

It is not a purpose of this document to provide off-the-shelf generators ready for massive production deployment, nor is it a purpose of the document to explain in detail the internals of each POC's generation scheme. Such details are described and discussed in the comments contained in the source files that concur to build each generator.

Each POC paragraph briefly explains the purpose of the POC and provides links to both input to, and output from, the relevant generator.

Interested readers are invited to test one or more POC trial packages downloading the free Community Edition, in order to evaluate the fitness of the POCs to the specific context of their projects. It is also possible to request ad-hoc POCs: we will evaluate from case to case the feasibility of such POCs, as described in page "Generator building trial".

Chapter 2 - Reproducing a POC on Your Computer

You can download SoProMach and all POC trial packages for free. The SoProMach and proof-of-concept (POC) trial packages are available in tar/gzip format. Each POC contains the textual input and scripts required to regenerate the POC target code. Compressed POC packages can be uncompressed with all most common uncompress and unzip utilities.

Each POC can be reproduced through three standard steps after unpacking, and no environment setting is required to run the POC scripts. There is one script associated with each step:

  1. Prepare: remove output from previous generator runs;
    u1_prepare [Linux® and Mac OS® X]
    w1_prepare.bat [Windows®]

  2. Generate: run the POC generator;
    u2_generate [Linux and Mac OS X]
    w2_generate.bat [Windows]

  3. Show results: remove temporary files and list names of generated files;
    u3_results [Linux and Mac OS X]
    w3_results.bat [Windows].

Chapter 3 - J2EE Generator

3.1 - Proof-of-concept (POC) Information

3.2 - Description

This comparatively large POC generates several files that reproduce corresponding files from Sun Microsystems' Java[tm] Adventure Builder Demo (JABD), a new sample application released with the SDK of the Java 2 Enterprise Edition, version 1.4.

The purpose of this POC is twofold:

The architecture of this POC generator is shown below.

Figure 1 - J2EE generator architecture

Figure 1 - J2EE generator architecture

The current version of this POC generates the SQL database schema and two types of Java files from thirteen software entities. All generated files have been successfully tested against the original hand-written counterparts within a working JABD as follows:

The generated SQL schema script "db_schema.sql" faithfully reproduces file "pointbase.sql" from the JABD sample application.

The first type of generated Java file implements the DAO pattern for the Pointbase database. The second type is a plain Java class, often referred to as POJO (Plain Old Java Object).

The DAO code generator produced the complete code of the DAO classes, with the only exception of method PointbaseUserDAO.matchPassword, which was written by hand in file "project/signon/methods/matchPassword".

The POJO code generator produced the complete code of the POJO classes, with the only exception of method AdventurePackage.setHotelItemId, which was written by hand in file "project/catalog/methods/setHotelItemId".

3.3 - SQL Generator: SQL Database Schema Script

Table 1 - SQL Generator: Generated Files

File name Source code
project/DB/db_schema.sql View

Table 2 - SQL Generator: Input Design Files

File name Source code
project/db_schema.ef View
project/catalog/data/activity View
project/catalog/data/adventure_package View
project/catalog/data/lodging View
project/catalog/data/transportation View
project/data/activity_list View
project/data/category View
project/customer/data/account View
project/signon/data/user View

3.4 - DAO Generator: Data Access Object Pattern

Table 3 - DAO Generator: Generated Files

File name Source code
project/catalog/LOGIC/PointbaseCatalogDAO.java View
project/customer/LOGIC/PointbaseAccountDAO.java View
project/signon/LOGIC/PointbaseUserDAO.java View

Table 4 - DAO Generator: Input Design Files

File name Source code
project/catalog/catalog.ef View
project/customer/account.ef View
project/signon/user.ef View
project/signon/methods/matchPassword View

3.5 - POJO Generator: Plain Old Java Object

Table 5 - POJO Generator: Generated Files

File name Source code
project/catalog/LOGIC/Activity.java View
project/catalog/LOGIC/AdventurePackage.java View
project/catalog/LOGIC/Lodging.java View
project/catalog/LOGIC/Transportation.java View
project/customer/LOGIC/Address.java View
project/customer/LOGIC/ContactInformation.java View
project/customer/LOGIC/Account.java View

Table 6 - POJO Generator: Input Design Files

File name Source code
project/catalog/activity.ef View
project/catalog/adventure_package.ef View
project/catalog/methods/setHotelItemId View
project/catalog/lodging.ef View
project/catalog/transportation.ef View
project/customer/address.ef View
project/customer/contact_information.ef View
project/customer/account.ef View

Chapter 4 - .NET Generator

4.1 - Proof-of-concept (POC) Information

4.2 - Description

This compact POC faithfully reproduces the C#/ASPX/SQL code generated by Jack Herrington in his article "Creating Portable Applications with Code Generation", published on DevX.

Purpose of this POC and of the POC in the next paragraph is to demonstrate portability of code generation at two different levels:

  1. Across different target platforms (.NET and a PHP stack, in this case), as already shown in Jack Herrington's article;

  2. Across different code generators, realized with different techniques: the same input model processed by two different generators produces exactly the same code.

Another purpose of this POC is to demonstrate the flexibility and adaptability of the Somusar/Code Generator Building[sm] service: the POC generator reproduces exactly the same coding style (indenting, naming convention for the identifiers) of the original code.

The generator of this POC produces SQL code that builds a simple database, a C# database access layer for that database, and ASPX test pages. The input model for the generator is provided by the same XML file used as input model in the aforementioned article.

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

Table 7 - Input Design Files

File name Source code
input.xml View

4.3 - C# Generator: Database Access Layer

Table 8 - C# Generator: Generated Files

File name Source code
bin/Author.cs View
bin/Book.cs View
bin/Publisher.cs View
bin/make.bat View

4.4 - ASPX Generator: Test Pages

Table 9 - ASPX Generator: Generated Files

File name Source code
asp/Author.aspx View
asp/Book.aspx View
asp/Publisher.aspx View
asp/index.aspx View

4.5 - SQL Generator: Building a MySQL database

Table 10 - SQL Generator: Generated Files

File name Source code
mysql/data.sql View
mysql/schema.sql View

Chapter 5 - PHP Generator

5.1 - Proof-of-concept (POC) Information

5.2 - Description

This compact POC faithfully reproduces the PHP/SQL code generated by Jack Herrington in his article "Creating Portable Applications with Code Generation", published on DevX.

Purpose of this POC and of the POC in the previous paragraph is to demonstrate portability of code generation at two different levels:

  1. Across different target platforms (.NET and a PHP stack, in this case), as already shown in Jack Herrington's article;

  2. Across different code generators, realized with different techniques: the same input model processed by two different generators produces exactly the same code.

Another purpose of this POC is to demonstrate the flexibility and adaptability of the Somusar/Code Generator Building[sm] service: the POC generator reproduces exactly the same coding style (indenting, naming convention for the identifiers) of the original code.

The generator of this POC produces SQL code that builds a simple database, a PHP database access layer for that database, and PHP test pages. The input model for the generator is provided by the same XML file used as input model in the aforementioned article.

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

Table 11 - Input Design Files

File name Source code
input.xml View

5.3 - PHP Generator: Database Access Layer

Table 12 - PHP Generator: Generated Files

File name Source code
phplib/Author.php View
phplib/Book.php View
phplib/Publisher.php View
phplib/ssdb.php View

5.4 - PHP Generator: Test Pages

Table 13 - PHP Generator: Generated Files

File name Source code
php/Author.php View
php/Book.php View
php/Publisher.php View
php/index.php View

5.5 - SQL Generator: Building a MySQL database

Table 14 - SQL Generator: Generated Files

File name Source code
mysql/data.sql View
mysql/schema.sql View

Chapter 6 - Java (J2SE) Generator

6.1 - Proof-of-concept (POC) Information

6.2 - Description

This POC provides examples of use of tjpp[tm] (Tefigel Java preprocessor) that produces Java files from corresponding input files with extension ".tj".

Purpose of the POC is to demonstrate how compact directives can produce repetitive fragments of code by exploiting the lightweight macro definition capabilities of Tefigel on micropatterns of Java code.

6.3 - Java Generator

Table 15 - Java Generator: Generated Files

File name Source code
FiveProperties.java View
Hello.java View
Hello2.java View
Results.java View
SampleException1.java View
SampleException2.java View
SimpleClass.java View
subpackage/ComplexClass.java View

Table 16 - Java Generator: Input Design Files

File name Source code
FiveProperties.tj View
Hello.tj View
Hello2.tj View
Results.tj View
SampleException1.tj View
SampleException2.tj View
SimpleClass.tj View
subpackage/ComplexClass.tj View

Chapter 7 - Bare Bones Multitier Generator

7.1 - Proof-of-concept (POC) Information

7.2 - Description

This POC provides a concise example of use of Sisendel on a simple model containing three software entities. The model is derived from an example contained in book "Code Generation in Action", written by Jack Herrington. The generator produces three files for each entity: one SQL script, one Java class, and one HTML form.

Purpose of the POC is to allow trial users to examine the structure of some simple software molds and verify the effect produced by simple changes applied to either the software entities or the software molds.

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

Table 17 - Input Design Files

File name Source code
project/author.ef View
project/book.ef View
project/publisher.ef View

7.3 - SQL Generator

Table 18 - SQL Generator: Generated Files

File name Source code
project/DB/author.sql View
project/DB/book.sql View
project/DB/publisher.sql View

7.4 - Java Generator

Table 19 - Java Generator: Generated Files

File name Source code
project/LOGIC/Author.java View
project/LOGIC/Book.java View
project/LOGIC/Publisher.java View

7.5 - HTML Generator

Table 20 - HTML Generator: Generated Files

File name Source code
project/UI/author.html View
project/UI/book.html View
project/UI/publisher.html View

Chapter 8 - XML Processor

8.1 - Proof-of-concept (POC) Information

8.2 - Description

This POC processes an XML file containing a fragment of Shakespeare's "The Two Gentlemen of Verona" and generates a Tefigel script. The POC in the next paragraph applies the same process in the opposite order: it generates exactly the same XML file (input in this POC) starting from exactly the same Tefigel script that is output in this POC.

The purpose of these two dual POCs is manifold:

Specific purpose of this POC is moreover to allow trial users to evaluate the XML processing capabilities of Tefigel.

8.3 - Tefigel Generator

Note:

Fragment from "The Two Gentlemen of Verona".
Text placed in the public domain by Moby Lexical Tools, 1992.
SGML markup by Jon Bosak, 1992-1994.
XML version by Jon Bosak, 1996-1998.

   
   

Table 21 - Tefigel Generator: Generated Files

File name Source code
two_gent-frag.tefigel View

Table 22 - Tefigel Generator: Input Design Files

File name Source code
two_gent-frag.xml View

Chapter 9 - XML Generator

9.1 - Proof-of-concept (POC) Information

9.2 - Description

This POC generates an XML file containing a fragment of Shakespeare's "The Two Gentlemen of Verona" starting from a Tefigel script. The POC in the previous paragraph applies the same process in the opposite order: it generates exactly the same Tefigel script (input in this POC) starting from exactly the same XML file that is output in this POC.

The purpose of these two dual POCs is manifold:

Specific purpose of this POC is moreover to allow trial users to evaluate the XML generation capabilities of Tefigel.

9.3 - XML Generator

Note:

Fragment from "The Two Gentlemen of Verona".
Text placed in the public domain by Moby Lexical Tools, 1992.
SGML markup by Jon Bosak, 1992-1994.
XML version by Jon Bosak, 1996-1998.

   
   

Table 23 - XML Generator: Generated Files

File name Source code
two_gent-frag.xml View

Table 24 - XML Generator: Input Design Files

File name Source code
two_gent-frag.tefigel View

Chapter 10 - API Generator Producing C and HTML

10.1 - Proof-of-concept (POC) Information

10.2 - Description

This POC provides an example of a code and documentation generator driven by a simple textual model. The model describes a set of APIs, specifying their interface and describing their function, and allows to describe the relevant steps of each API. These descriptions are then copied as comments into the generated C code. The generator produces one skeleton C source file for each function and an HTML documentation file describing all the interfaces.

Purpose of the POC is to provide an example of a concise textual model for simple custom generation tasks.

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

Table 25 - Input Design Files

File name Source code
APIdescr.txt View

10.3 - C Generator

Table 26 - C Generator: Generated Files

File name Source code
code_dir/open.c View
code_dir/close.c View
code_dir/read.c View
code_dir/write.c View

10.4 - HTML Generator

Table 27 - HTML Generator: Generated Files

File name Source code
APIdescr.html View

Chapter 11 - VisualBasic.NET Generator Draft

11.1 - Proof-of-concept (POC) Information

11.2 - Description

Note:

This version of the generator has been superseded by a refactored version described in the next paragraph .

   
   

Chapter 12 - VisualBasic.NET Generator

12.1 - Proof-of-concept (POC) Information

12.2 - Description

Note:

This generator can be used from within Visual Basic Express 2005 Beta. See related article.

   
   

This POC reproduces the VisualBasic.NET (VB.NET) code produced by Kathleen Dollard's generator in her article "Generate .NET Code With XSLT", published on VisualStudio Magazine.

The generator of this POC produces VB.NET classes that provide strongly typed access based on a database's XML Schema Definition. A thorough description of the generator's input and of the generated code is provided in "Generate .NET Code With XSLT".

Kathleen's generator is based on Extensible Stylesheet Transformations (XSLT), while this POC generator exploits Tefigel's XML processing and file generation capabilities.

In particular, this refactored version of the generator also exploits new Tefigel constructs, that allowed to significantly simplify the generator structure in comparison with the generator of the previous paragraph .

Purpose of this POC is to demonstrate portability of code generation across different code generators, realized with different techniques: the same input model processed by different generators produces the same code. Another purpose of this POC is to demonstrate the adaptability of the Somusar/Code Generator Building[sm] service: the POC generator reproduces the same coding style (indenting, naming convention for the identifiers) of Kathleen's code.

The XML input file used in the POC is the same as the "Simplified XML document describing schema" from Kathleen's article and is linked to from the following table.

Table 28 - Input Design Files

File name Source code
Northwind.xml View

12.3 - VB.NET Generator

Table 29 - VB.NET Generator: Generated Files

File name Source code
Northwind.vb View

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

Table 30 - VB.NET Generator: Sample Generator Internal Code

Description File name Source code
Main VB.NET template vb_gen/templates/vb_body View
DataTable Class template called by "vb_body" vb_gen/templates/datatable_class View
XML processor to read database table metadata vb_gen/xml_table/tag_node.in View
Main generator script main.tefigel View

Chapter 13 - XML to Java Generator

13.1 - Proof-of-concept (POC) Information

13.2 - Description

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

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!

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

Chapter 14 - PHP/HTML Generator

14.1 - Proof-of-concept (POC) Information

14.2 - Description

This POC generator is an update of a prototype generator thoroughly described in article "PHP and HTML Generation using SoProMach", published on Code Generation Network (CGN).

The generator reproduces the PHP code described by Eric Rollins in his article "PHP Web Site Generation using Ruby", also published on CGN. Additionally, the generator of this POC produces HTML forms and documentation for the software entities of the sample target application, featuring classes for authors, books, publishers, reviewers, and book stores.

Purpose of this POC is to demonstrate the advantages of the multitier consistency offered by Somusar/Software Entities[tm], that also provide a common language to designers of different application tiers, thus reducing the cross-tier communication and inconsistency problems.

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

Table 34 - Input Design Files

File name Source code
project/author.ef View
project/book.ef View
project/publisher.ef View
project/reviewer.ef View
project/store.ef View
project/store_book.ef View
project/db_load.ef View

14.3 - PHP Generator: Database Access Layer

Table 35 - PHP Generator: Generated Files

File name Source code
project/DB/AuthorSS.php View
project/DB/AuthorValue.php View
project/DB/BookSS.php View
project/DB/BookValue.php View
project/DB/BookWithNamesValue.php View
project/DB/PublisherSS.php View
project/DB/PublisherValue.php View
project/DB/ReviewerSS.php View
project/DB/ReviewerValue.php View
project/DB/StoreBookSS.php View
project/DB/StoreBookValue.php View
project/DB/StoreBookWithNamesValue.php View
project/DB/StoreSS.php View
project/DB/StoreValue.php View

14.4 - PHP Generator: Test Page

Table 36 - PHP Generator: Generated Files

File name Source code
project/DB/DbLoadTest.php View

14.5 - HTML Generator: Generating HTML forms

Table 37 - HTML Generator: Generated Files

File name Source code
project/UI/author.html View
project/UI/book.html View
project/UI/publisher.html View
project/UI/reviewer.html View
project/UI/store.html View
project/UI/store_book.html View

14.6 - HTML Generator: Generating HTML documentation files

Table 38 - HTML Generator: Generated Files

File name Source code
project/DOC/author.html View
project/DOC/book.html View
project/DOC/db_load.html View
project/DOC/publisher.html View
project/DOC/reviewer.html View
project/DOC/store.html View
project/DOC/store_book.html View

Chapter 15 - Java and JSP DAO Struts Generator

15.1 - Proof-of-concept (POC) Information

15.2 - Description

Note:

This generator can be used from within Eclipse 3. See related article.

   
   

This multi-output generator produces a large number of files, derived from the source code written by Keld H. Hansen in his JavaBoutique tutorial "Using DAOs in Apache Struts".

Purpose of this generator is to record and reproduce Keld's skills in delivering high-quality code for several DAOs using various types of back-end implementations.

In order to demonstrate that, the generator reproduces Keld's example code to manage a DVD library, and extends his example producing similar code to manage three additional libraries:

Beyond the DAO classes, the generated code for each library manager includes unit tests, user interface code, JSP pages, Struts configuration files in XML, and application property files, as listed in the next table. Overall, for each input entity file, twenty-three files are generated.

Table 39 - Set of generated files

Quantity Type of generated file Corresponding generator template(s)
1 struts-config.xml struts-config.xml
1 POJO .java Class.java
1 ManagerIF.java ClassManagerIF.java
2 Manager.java SimpleManager.java,
DatabaseManager.java
2 ManagerFactoryIF.java ClassManagerFactoryIF.java,
DatabaseManagerFactoryIF.java
4 ManagerFactory.java SimpleManagerFactory.java,
JdbcManagerFactory.java,
StrutsManagerFactory.java,
TomcatManagerFactory.java
1 Test.java UnitTest.java
1 Form.java DetailForm.java
7 Action.java CommonAction.java,
CreateAction.java,
DeleteAction.java,
DetailAction.java,
ListAction.java,
ProcessAction.java,
UpdateAction.java,
MiscAction.java
1 detail.jsp detail.jsp
1 list.jsp list.jsp
1 app.properties application.properties

Each set of library manager files (for DVDs, CDs, books, and VHSes) is generated from a corresponding textual model file written in Sisendel, and listed in the following table.

Table 40 - Input Design Files

File name Source code
project/dvd.ef View
project/cd.ef View
project/book.ef View
project/vhs.ef View

All generated files are accessible through the tables of the following paragraphs, one paragraph for each library manager.

15.3 - DVD Manager Generator

Table 41 - DVD Manager Generator: Generated Files

File name Source code
project/CORE/dvd_struts-config.xml View
project/LOGIC/DVD.java View
project/LOGIC/DVDManagerIF.java View
project/DB/SimpleDVDManager.java View
project/DB/DatabaseDVDManager.java View
project/LOGIC/DVDManagerFactoryIF.java View
project/DB/DatabaseDVDManagerFactoryIF.java View
project/DB/SimpleDVDManagerFactory.java View
project/DB/JdbcDVDManagerFactory.java View
project/DB/StrutsDVDManagerFactory.java View
project/DB/TomcatDVDManagerFactory.java View
project/CORE/DVDTest.java View
project/UI/DetailDVDForm.java View
project/UI/CommonDVDAction.java View
project/UI/CreateDVDAction.java View
project/UI/DeleteDVDAction.java View
project/UI/DetailDVDAction.java View
project/UI/ListDVDAction.java View
project/UI/ProcessDVDAction.java View
project/UI/UpdateDVDAction.java View
project/UI/dvd_detail.jsp View
project/UI/dvd_list.jsp View
project/CORE/dvd_app.properties View

15.4 - CD Manager Generator

Table 42 - CD Manager Generator: Generated Files

File name Source code
project/CORE/cd_struts-config.xml View
project/LOGIC/CD.java View
project/LOGIC/CDManagerIF.java View
project/DB/SimpleCDManager.java View
project/DB/DatabaseCDManager.java View
project/LOGIC/CDManagerFactoryIF.java View
project/DB/DatabaseCDManagerFactoryIF.java View
project/DB/SimpleCDManagerFactory.java View
project/DB/JdbcCDManagerFactory.java View
project/DB/StrutsCDManagerFactory.java View
project/DB/TomcatCDManagerFactory.java View
project/CORE/CDTest.java View
project/UI/DetailCDForm.java View
project/UI/CommonCDAction.java View
project/UI/CreateCDAction.java View
project/UI/DeleteCDAction.java View
project/UI/DetailCDAction.java View
project/UI/ListCDAction.java View
project/UI/ProcessCDAction.java View
project/UI/UpdateCDAction.java View
project/UI/cd_detail.jsp View
project/UI/cd_list.jsp View
project/CORE/cd_app.properties View

15.5 - Book Manager Generator

Table 43 - Book Manager Generator: Generated Files

File name Source code
project/CORE/book_struts-config.xml View
project/LOGIC/Book.java View
project/LOGIC/BookManagerIF.java View
project/DB/SimpleBookManager.java View
project/DB/DatabaseBookManager.java View
project/LOGIC/BookManagerFactoryIF.java View
project/DB/DatabaseBookManagerFactoryIF.java View
project/DB/SimpleBookManagerFactory.java View
project/DB/JdbcBookManagerFactory.java View
project/DB/StrutsBookManagerFactory.java View
project/DB/TomcatBookManagerFactory.java View
project/CORE/BookTest.java View
project/UI/DetailBookForm.java View
project/UI/CommonBookAction.java View
project/UI/CreateBookAction.java View
project/UI/DeleteBookAction.java View
project/UI/DetailBookAction.java View
project/UI/ListBookAction.java View
project/UI/ProcessBookAction.java View
project/UI/UpdateBookAction.java View
project/UI/book_detail.jsp View
project/UI/book_list.jsp View
project/CORE/book_app.properties View

15.6 - Vhs Manager Generator

Table 44 - Vhs Manager Generator: Generated Files

File name Source code
project/CORE/vhs_struts-config.xml View
project/LOGIC/Vhs.java View
project/LOGIC/VhsManagerIF.java View
project/DB/SimpleVhsManager.java View
project/DB/DatabaseVhsManager.java View
project/LOGIC/VhsManagerFactoryIF.java View
project/DB/DatabaseVhsManagerFactoryIF.java View
project/DB/SimpleVhsManagerFactory.java View
project/DB/JdbcVhsManagerFactory.java View
project/DB/StrutsVhsManagerFactory.java View
project/DB/TomcatVhsManagerFactory.java View
project/CORE/VhsTest.java View
project/UI/DetailVhsForm.java View
project/UI/CommonVhsAction.java View
project/UI/CreateVhsAction.java View
project/UI/DeleteVhsAction.java View
project/UI/DetailVhsAction.java View
project/UI/ListVhsAction.java View
project/UI/ProcessVhsAction.java View
project/UI/UpdateVhsAction.java View
project/UI/vhs_detail.jsp View
project/UI/vhs_list.jsp View
project/CORE/vhs_app.properties View

Chapter 16 - Further Reading

Additional information on the different aspects of the Somusar/Software Production Technique[tm] can be found in the other volumes of the Somusar/SoProTech[tm] Booklet Series, listed below.

Vol. I - somusar/SoProTech: An Introduction

An introduction to the Somusar/Software Production Technique[tm], a new, fast, and efficient technology to make high-quality multifacet software.

Vol. II - somusar/SoProTech: A Sample Project

Description of a sample project, serving as a proof-of-concept for the Somusar/Software Production Technique[tm], and the Somusar/Sisendel[tm] and Somusar/Tefigel[tm] languages. A few code examples are provided and demonstrate the practical applicability of the technique.

Vol. III - somusar/Sisendel: A Tutorial Introduction

A tutorial introduction to Somusar/Sisendel[tm], describing all features of the simple software entity design language. Several code examples practically demonstrate the conciseness and flexibility of the language.

Vol. IV - somusar/Tefigel: A Tutorial Introduction

An introduction to the syntax, semantics, and usage of Somusar/Tefigel[tm], including a vast set of code examples, illustrating the powerful features of the text file generation language.

Vol. V - somusar/Sisendel: Reference Guide

Sisendel reference guide: official definition of syntax and semantics of the Somusar/Sisendel[tm] language.

Vol. VI - somusar/Tefigel: Reference Guide

Tefigel reference guide: official definition of syntax and semantics of the Somusar/Tefigel[tm] language.

Vol. VII - somusar/SoProMach: User's Guide

The Somusar/Software Production Machine[tm] User's Guide. How to install and operate SoProMach.

Vol. VIII - somusar/tjpp: User's Guide

The Somusar/tjpp[tm] User's Guide. How to install and operate the Java[tm] preprocessor.