DomainTemplatesOptionConfiguration
Domain Templates Option Configuration
What is a Domain Template?
The term template is a very overloaded term. So first, let's start with what a template is, in the context of this feature. In this case, a template file contains static and dynamic content (and typically script code) with the purpose of generating content like program language source code, HTML, XML or just plain, human readable text.
In UML, there are various types of elements (Class, Interface, Actor, etc.) and these elements can be stereotyped which identifies the element as serving a particular purpose or possessing certain behaviors. A domain object is an object that is specific to a certain domain. For example, in an online gaming application domain, some domain objects might be Player, Weapon, Level, and Opponent. These domain objects could be represented in a UML class diagram as Class elements with the stereotype of player, weapon, level, and opponent, respectively.
In order to generate the code for these domain objects, it would be necessary to create custom code template files. Once the template files are created, we need a way to map the elements/stereotypes to the appropriate template files during the code generation process. This is what a domain template is: the mapping of a model element type and stereotype to a particular code generation template file. The three domain templates that ship with UML tools in NetBeans 6.0 are designed for the basic Java types: Basic Class, Basic Interface and Basic Enumeration. The Basic Class domain template is defined as any Class element that has no stereotype defined for it. Similarly, for the other two basic domain templates.
Keep in mind that the sole purpose of creating domain templates is to generate text from a UML model. The text that is generated is unlimited in terms of its format and purpose. The most common output (and the default) is Java code, but it could also be C++, Ruby, JavaScript, JSP, HTML, XML, or just plain text, to point out several examples. The output format is completely defined by the template files that are defined for a particular domain template.
Templates Options Panel
Categories
Categories are defined by the modeler and are used only as a grouping mechanism for organizing the domain templates. A modeler may choose to create and group all domain templates under a single category, or create as many categories with as few or as many domain templates as desired. Everything is completely free-form from the name of the categories and domain templates to the number of either of these. The only thing that is predetermined is that template families contain templates and template families cannot be nested to create "sub-family" nodes.
Domain Templates
Domain templates are defined by the modeler and are used to create relationships between elements in the model with output file templates. The relationship between a domain template and a template file(s) is defined by a model element type and stereotype. For example, a modeler can create a domain template named MyFooObject and define it as any model element with an element type of Class and a stereotype of foo. This domain template can then be defined to use one or more of the available template files (see "NetBeans Templates" below) for code generation.
Code Generation
Code generation is a misnomer because, as described above in "What is a Domain Template" section, the output is not limited to programming language source code. When a UML project is instructed to generate code via the Generate Code action, it merely identifies model element types and stereotypes as domain templates which have a defined set of template files it will use to generate "code" (output). Creating and defining the domain templates (and the template files) is the keystone of customized code generation.
Accessing the UML Templates Options
The domain templates are accessed via the UML Options panel. Select the Tools|Options menu action, select the UML category, and then select the Templates tab. A tree of domain templates grouped into categories are displayed in the Domain Templates tree structure. Each domain template has a set of properties (model element type, stereotype, description, and a list of template files) that can be customized.
Note: Modification for the Templates panel are not permanently saved until the OK button for the options dialog is clicked.
Creating and Removing Categories
Select the Categories node (root node of tree) and click the Add button. A new node with a default name will be created. Select the node and press F2 (windows) or triple click to enter edit mode on the node name.
To remove a category, select the desired category node and click the Remove button. There is no warning dialog for this action, but canceling out of the option dialog will restore everything as it was when the options dialog was opened.
Creating and Removing Domain Templates
Select the target category and click the Add button. A new node with a default name will be created. Select the node and press F2 (windows) or triple click to enter edit mode on the node name.
To remove a domain template, select the desired domain template node and click the Remove button. There is no warning dialog for this action, but canceling out of the option dialog will restore everything as it was when the options dialog was opened.
Modifying Domain Template Properties
With a domain template node selected, the domain template properties can be modified.
Element Type
This is the model element type (Class, Interface, Enumeration, Actor, Node, Package, etc) of the domain template. Exactly one element type must be selected.
Stereotype
This is the stereotype of the domain template. Stereotypes are custom defined by the modeler. Here are examples of some contrived stereotypes: foo, my-foo, ejb-stateless, persistence.
Description
This is a brief description of the domain template and maybe what its template file(s) will output.
Output Parameters
This is a list of the template files and other output parameters used for the code generation process when an element is identified as being of this type of domain template. The desired output can be customized to use a custom filename based on the element name with a predefined prefix and/or suffix, a custom extension, and a custom output subfolder.
Filename Format
The default resulting filename will be the same as the model element name. The filename can be customized with a prefix or suffix (or both) with the use of the {name} token. For example, {name}Bean, My{name}, or My{name}Bean. For a model element named Foo, the three examples would result in FooBean, MyFoo and MyFooBean, respectively. Leaving this field blank or entering {name} will result in a file named Foo.
Extension
The extension of the resulting generated file can be predefined by the template file being used, or it can be customized using this field.
Folder Path
The Generate Code action dialog requires a default output path. This is the base folder for all output. The package of a model element further defines the subfolder path under the base folder. This field can specify a custom subfolder path under the package subfolder path. This field is most commonly left blank.
Template File
The template file is the actual filename of the template file that will be used to generate the output. The template file is selected from a list of available template files that have been defined as UML code generation templates. The UML code generation templates can be accessed and customized via the Tools|Templates menu action. Only template files found under the UML/Code Generation folder (and subfolders) are made available for selection. You can create new template files from scratch or make duplicates of current template files and modify them to fit your needs.
Template Table Buttons
Add Template...
The Add Template... button will display a dialog with the four input fields for a template file. Click OK in this dialog and a new row will be added to the templates table.
Edit
Select a row in the templates table and click Edit. A dialog with the four input fields and the current data for the selected row will be available for modification. Clicking OK will close the dialog and refresh the row in the templates table.
Remove
When a row is selected in the templates table, clicking the Remove button will remove it from the table.

