Browse Prior Art Database

XML-Based Templates for Generating Artifacts from Java-Based Models

IP.com Disclosure Number: IPCOM000123471D
Original Publication Date: 1998-Dec-01
Included in the Prior Art Database: 2005-Apr-04
Document File: 5 page(s) / 173K

Publishing Venue

IBM

Related People

Starkey, M: AUTHOR

Abstract

This disclosure describes a mechanism for generating code using a template-based approach for code generation. It fixes a number of problems inherent with template-driven code generation. Some of these problems are protection of proprietary information in text-based templates and performance of code generation.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 52% of the total text.

XML-Based Templates for Generating Artifacts from Java-Based Models

   This disclosure describes a mechanism for generating code
using a template-based approach for code generation.  It fixes a
number of problems inherent with template-driven code generation.
Some of these problems are protection of proprietary information in
text-based templates and performance of code generation.

   This solution works by translating a template into Java
source, compiling that source to produce a routine that generates
code.  This routine is then used to generate code in the product.
The templates are used solely during the build of the product and the
generated code is shipped with the product.  End-users may customize
their templates if they have the template translation utility and the
source templates.  Other end-users cannot see the proprietary
information in the templates.  Thus the date model from which code is
being generated can be made visible when it is stable and the set of
people who see the data model is controlled.

   Figure 1 shows the process for creating a compiled template
that can be used to generate code from the data model.  First the
programmer must create their data model since the templates are a
direct reflection of the data model.  The templates are written as
text files with commands that navigate through the data model and
control the code that is generated.  Once the templates have been
written they are translated into Java source code through a single
pass translator.  The translator produces a Java program.  This Java
program can then be compiled and when run against an instance of the
data model will generate code in the form described by the templates.

   The template language that is used is fairly simple to
ensure that it is easy to write.  The template language is XML and
uses a specific document type definition as illustrated in Table 2.
The template defines the output file name and defines each line of
output for the generated file.  It is highly dependent on the data
model from which it is generating code.  There are language elements
in the template language that define the navigation of the data
model.  There are also commands for conditional generation based on
values in the data model and there are language elements for
extracting these values from the data model.  Table 1 shows the
commands available in the template language.  There are two major
types of commands: control flow commands describe the navigation of
the model, and data acquisition commands extract data from the model,
as shown below.
  o ...