WebSphere consultant Chris Gerken answers questions on model-driven development (MDD) and how to author and use executable patterns, Java™ Emitter Templates (JET), and Design Pattern Toolkit (DPTK) to generate application source. MDD transformations are now being used as executable patterns. They automate the consistent application of conventions, best practices, and guidelines. Significant new function in Eclipse and RSA now lets you easily author these patterns to generate application source (Java, COBOL, JSP, XML, properties files, and so on).
Question: Given a united modeling language (UML) activity model, how do I create a plug-in that will execute a model-to-model transformation (UML2 to DSL Ecore) and use the information in the model to generate code using Java Emitter Templates (JET), but doing it seamlessly and programmatically?
Answer: In general, you should use a meet-in-the-middle approach. Start by building out your JET transform (if you're still using Rational Software Architect (RSA) V6.x, then use the Design Pattern Toolkit (DPTK) from alphaWorks®). The input model is optimized to make model access in the templates very simple.
Once the model-to-text transform is written, you can write an RSA transformation that navigates your UML model and builds an internal model that looks like the input model required by the JET transform. The final rule in the RSA transformation converts the built-up internal model to a format easily consumed by the JET transform (XML string or EMF in-memory model) and to programmatically invoke JET (or DPTK).
Question: What is an exemplar and how does it help me build model-to-text transformations?
Answer: An exemplar is a representative example of what you want your model-to-text transform to generate. It is consumed by the exemplar authoring tools in RSA, and is used to quickly extract the input model schema and model-to-text templates.The assumption during exemplar authoring is that the exemplar is written to all applicable best practices, guidelines, conventions, and so on. It demonstrates all points of variability to be supported by the transformation. It may not seem like it at first, but you save a great deal of time by building and validating an exemplar, and then using it as an input to the transform authoring process.
Question: When should I use DPTK as opposed to JET to write my m-2-t transforms?
Answer: If you plan to run your transformations on Eclipse 3.2, Rational Application Developer (RAD) V7, or Rational Software Architect V7, then use JET. For earlier versions of RSA, RAD, or Eclipse, use DPTK.
Question: I want to use a deployment descriptor (web.xml) as an input model for JET transform, but I also need a few bits of additional data that cannot go into the deployment descriptor. How do I make this work?
Answer: You can put the additional information in a second XML file. Your transform will take one of the two files as its primary input, and will use the content tag to read, parse, and load into memory the second file. Once both models are loaded from the two files, you can perform whatever template processing is necessary to generate your files.
Question: What do patterns have to do with model-to-text transformations?
Answer: Grady Booch once defined a pattern as a solution to a recurring problem within a given context. This definition implies that best practices, guidelines, and naming conventions are all forms of patterns. Since model-to-text transformations can automate the application of best practices, guidelines, and naming conventions, model-to-text transformations (and model-to-model transformations) can, therefore, automate the application of patterns. I often interchange the terms "transformation" and "pattern".
Question: One thing I am struggling with is how to scope my exemplar and my pattern. I want to be sure the scope is big enough to get the power of model-to-text transformations, but not so big we get overwhelmed with our first transform.
Answer: There are several ways you can scope your exemplar:
- Start with: "A pattern is a solution to a recurring problem in a given context." Solutions can take the form of best practices, conventions, guidelines, design docs, and so on. Look for groups of files that solve a particular problem, like how to persist an object (including doc and j-unit test files). Of course, the more times this problem is solved across your application suites, the better.
- I say two files are "MDD_related" (my terminology) if the two collections of model data needed to generate the respective files overlap. Examples include a class or file name for one file being called out in the source for the other file, the same property names (or variants thereof like getter and setter names) appear in the source for the two files, and so on. We can also say that the MDD-relation is strong (an interface and an implementing class) or weak (a jar name for a Java project and a referencing admin script). You want to look for groups of strongly MDD-related files (think mathematical closure).
Both of these approaches end up identifying the same groups of files. For a good introductory exemplar, I'd look for a group of files that has about 20 files in it. I've observed that roughly 80% of the templates in a pattern are trivial, 15% are straightforward and easy to complete, and 5% are rather gnarly.
If you're a more experienced pattern author, you can look at the files, ask a few questions, and get a good feel for both the number and complexity of the templates, and the size and shape of the model. I'd add in risk factors for additional unseen complexity, such as the subject matter expert and pattern subject matter expert are unfamiliar with the other subject matter expert's domain.
To over simplify, I'd build 5 to 10 templates for your first transformation. Any more, you simply delay gratification. Any less, and you won't see the power of model-to-text transformations.
Question: I have some Java classes that would be really good candidates for generation with JET, but there's also a lot of business logic in each class that's going to be very difficult to generate. I suppose I could generate the class source once and let the developers add their business logic, but how can I keep that logic from being written over if I have to regenerate?
Answer: You need to use the userRegion tag in JET. This tag identifies a section of generated text that a user can modify. If the transform is run again, the changes made by the developers are saved across that re-generation. In short, create your templates to generate the source, identify the portions of the generated source that developers may want to modify, and surround those sections with userRegion tags.
Question: What kinds of applications have already been generated with model-to-text transformations?
Answer: Since RSA V7 only just came out recently, most of the model-to-text transformations have been written using DPTK. The generated applications and components include custom portlets, J2EE applications, Eclipse components (wizards, dialog boxes, help, rich clients), optimized data base access, and other customer-specific applications.
Question: I've written a number of DPTK patterns for RSA V6. What's the easiest way to migrate them to JET and RSA V7?
Answer: RSA V7 and RAD V7 both ship with a JET tag library called the DPTK compatibility layer. This tag library contains tags that look and behave like the original DPTK tags. These tags, however, are implemented on top of JET.
Once your pattern has been loaded into a V7 workspace, you can apply the DPTK pattern "Add JET Behavior" to your DPTK pattern to add the right natures, settings, and folders required to tune the transform as a JET transform. .
Question: What's so great about the new JET tags? I could do the same thing with embedded Java already.
Answer: The JET tags provide the same level of template flow control (iteration, conditional processing, model access, and so on) that you could provide yourself with embedded Java, but they do so in a way that is language neutral. This makes it possible for COBOL C programmers, and system administrators to author transformations without having to learn Java.
Some of the tags also hide a great deal of complexity that make it impractical to imbed with Java. For example, the file tag (applies a template to the model and stores the resulting content in a new Eclipse resource) also interacts with configuration managements plug-ins and other editors to ensure that the generated file is created into Eclipse correctly.
Question: You have multiple transformations: UML2Java, JET, and DPTK? What is the clear strategy from RSA?
Answer: The model-to-text technology to use depends on the version of Rational tooling you use. The first choice is EMFT JET (available in Eclipse 3.2.0 and Rational V7 and later). If you are not running one of those platforms, then you should use DTPK.
Question: What is Pattern Repository and how does the Pattern Repository relate to the Asset Repository (RAS)? Again, an area of confusion from RSA.
Answer: A pattern repository is a server (although it can be on your local machine) that holds patterns deployed as Reusable Asset Specification (RAS) files. A RAS file is nothing more that a zip file with some additional metadata about the nature and use of the assets in the RAS file as well as metadata that describes any installation steps that should be taken when the RAS asset is imported into your workspace. Special actions can include the installation of Eclipse plug-ins or the importing of files into the workspace. These actions are run automatically. Of course, RAS files can contain other kinds of assets too.
-
IBM WebSphere Developer Technical Journal: Get started with model-driven development using the Design Pattern Toolkit
-
IBM WebSphere Developer Technical Journal: Get started with model-driven development using the Design Pattern Toolkit, Part 2
-
Design Pattern Toolkit
-
JET Enhancement Proposal (JET2)

Chris Gerken is a Senior Programmer with the IBM Software Services for WebSphere Enablement team. He has been developing MDD methodologies and tooling for the past 6 years. He has developed a way to automate the application of best and only practices using a simple, tag-based templating syntax.
Comments (Undergoing maintenance)





