protectedStartTag, protectedEndTag

Syntax

[#protectedStartTag]startTag[/#protectedStartTag]
body
[#protectedEndTag]endTag[/#protectedEndTag]

where:

Description

The protectedStartTag and protectedEndTag directives are used to specify sections in the generated text where any user manual modification must be preserved. These two directives are specified as expressions that can be dynamic text. Subsequent applications of the template will preserve the text between these delimiters.

These directives are particulary useful when generating some method declaration, where the method implementation may not be part of the model and is expected to be implemented by hand by the developer. These directives ensure the hand written code will be preserved during the next generation process.

A protected start tag result must be unique withing the scope of a generated file (the generation process fails if this constraint is not verified). The onus of ensuring this start tag is unique is on the template writer. The end tag result may not necessarily be unique withing the generated file, as the region is identified by the start tag.

The body between the start tag and end tag directives will be printed when the generated file does not already exist, or when the start tag is not found in the generated file. It can be used to output a default code that the user may (or must) modify by hand.

Examples

This code defines a (simplified) Java declaration for a UML operation:

public void ${operation.name}() {
    [#protectedStartTag]// Start of user code of method ${operation.name}()[/#protectedStartTag]
    TODO insert your manual code here
    [#protectedEndTag]// End of user code[/#protectedEndTag]
}

The above code would produce an output similar to the following:

public void addAccount() {
    // Start of user code of method addAccount()
    TODO insert your manual code here
    // End of user code
}

public void removeAccount() {
    // Start of user code of method removeAccount()
    TODO insert your manual code here
    // End of user code
}

Unfortunatly, this protected section is not very robust: the above protected tags are based on the operation's name, if the operation is renamed then the corresponding hand-written code is lost.

A much robust pattern is to base the protected tags on an identifier that is constant in time:

public void ${operation.name}() {
    [#protectedStartTag]// Start of user code {${operation.eUniqueID()}}[/#protectedStartTag]
    TODO insert your manual code here
    [#protectedEndTag]// End of user code[/#protectedEndTag]
}

The above code would produce an output similar to the following:

public void addAccount() {
    // Start of user code {ID56F239A6}
    TODO insert your manual code here
    // End of user code
}

public void removeAccount() {
    // Start of user code {ID5R47A23}
    TODO insert your manual code here
    // End of user code
}

Now if the operation is renamed, the corresponding Java method will be renamed too but the hand-written code will be preserved.