Book a Demo

Author Topic: Code/Transformation Template - Duplication possible?  (Read 7213 times)

sebastian_knox

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Code/Transformation Template - Duplication possible?
« on: January 21, 2016, 02:11:02 am »
Hi!

Is it possible to duplicate a template so I can make some variations for different purposes in a model? In my current project I need to generate Typo3-Extension files (PHP-Model, PHP-TCA-Array and MySQL-Files) which need different filenames and content.
My plan was to make a PIM from which I generate two different PHP-Models (one for Typo3-Model, one for TCA-Model) and a DDL for my MySQL-Output. To reach this goal i would need a modified PHP-Transformation-Model so that I can rename the Classnames for getting proper filenames when rendering the files.
Would be nice if anyone has good idea on this or could tell me this won't work out at all!

Greets

Sebastian

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Code/Transformation Template - Duplication possible?
« Reply #1 on: January 21, 2016, 03:17:33 am »
Too long ago to give a reliable answer, but I remember some way to store any existing template just by using a new name.

q.

P.S. I guess it was simply by adding a new template and copy/paste from where you want to have a copy.
« Last Edit: January 21, 2016, 03:20:54 am by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Code/Transformation Template - Duplication possible?
« Reply #2 on: January 21, 2016, 06:07:05 am »
That seems entirely within the range of what you can do with EA's transformation templates

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Code/Transformation Template - Duplication possible?
« Reply #3 on: January 21, 2016, 08:34:23 pm »
Hi Sebastian,


Here's a way to duplicate a set of code generation templates. It's a little involved, so if you've just got one or two individual templates to duplicate, copy/paste works better.

So let's say you've got a language A which you've written a bunch of templates for, and a language B which you want to duplicate the templates to.

First off, each language you write code generation templates for must have at least one datatype defined, otherwise EA won't recognize it as a language at all. You can do this in Settings -- Code Engineering Datatypes, or by clicking New Language in the code template editor; they both open the same dialog. So the A language already exists, but you must also add a B language.

Next, export your templates to XML (Project -- Model Import/Export -- Export Reference Data).

Open the XML file in a text editor and locate the string
Code: (XML) [Select]
<DataSet name="A_Code_Template"That's the beginning of the XML node that holds all the templates for language A. (There are more attributes, so I've omitted the closing bracket intentionally.)

Make a copy of that entire XML node with all its child nodes (<DataRow> nodes containing four <Column> nodes each). In the copy, change the DataSet name to "B_Code_Template".

Within each <DataRow> in the "B_Code_Template" DataSet, change the value of the Column named TemplateType from "A_Code_Template" to "B_Code_Template", and create a new GUID for each TemplateID Column.

Reimport the XML file to EA.


A very similar approach can be applied to duplicate a set of transformation templates, except there's no need to define a new language for those, and instead of "(language)_Code_Template", the string to look for is "(transform)_Transform_Template".

You should be aware that only templates which have been modified are included in the export, so you can't duplicate EA's built-in templates this way.

HTH,


/Uffe
My theories are always correct, just apply them to the right reality.

sebastian_knox

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Code/Transformation Template - Duplication possible?
« Reply #4 on: January 22, 2016, 01:06:27 am »
Hi together!

Thanks for your responses, especially the one from Uffe! I managed to duplicate the templates properly, but I hoped that this could be done with less effort at all.
My next struggle is the renaming of my classes on transistion, but I hope to figure this out alone - otherwise, I'll start a new topic here!

Cheers

Sebastian