Scenario Tree describes how to drive automatic generation processes.
Indeed, a scenario transforms an input (XML files, Pojos) into a GENERATED XML file which describes the body of a part (Editor, Query, Detail UI…).
The default generation process which is driven by Scenario Tree provided by Scenario.xml file (see Scenario architecture), may contain defects.
For instance, in our case, we want to make 3 improvements:
Making changes to Scenario Tree file means update the generation processes. The belowing example shows differents possiblities:
These changes can be manually made by the developper inside the Scenario.xml file.
A other way is to assemble changes inside a new Scenario tree stored in a specific xml file, inject these changes inside the current Scenario.xml file and launch needed generation processes.
In the example below, previously described needed change are incorparated.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <scenarioTree xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adichatz.org/xsd/v0.9.1/generator/scenarioTree.xsd"> <pathElements> <pathElement type="PROJECT" location="myscenario"/> </pathElements> <params> <param id="devl.default.integer.pattern" value="#####"/> </params> <generators> <generator treeClassName="org.adichatz.generator.wrapper.TableWrapper" generatorClassName="org.mycompany.myscenario.generator.MyTableGenerator"/> <generator treeClassName="#CONTROLGENERATOR()" generatorClassName="org.mycompany.myscenario.generator.MyControlGenerator"/> </generators> <generationScenario scenarioClassName="org.adichatz.scenario.impl.PluginEntityScenario"> <modelPart> <pojoRewriters> <pojoRewriter rewriterClassName="org.adichatz.scenario.generation.SuperPojoRewriter" propertyRegex="lastUpdate"> <params> <param id="superClassURI" value="bundleclass://./#PACKAGENAME().model.ASuperLastUpdate"/> <param id="sourceURI" value="platform:/plugin/org.adichatz.template/template/src/ASuperLastUpdate.java"/> </params> </pojoRewriter> </pojoRewriters> </modelPart> <propertyField id="lastUpdate"> <controlField xsi:type="dateTextType" enabled="false" style="SWT.BORDER | SWT.TIME"/> <columnField xsi:type="tableColumnType" property="lastUpdate" sorted="true" style="SWT.CENTER"/> </propertyField> <pluginEntity entityURI="adi://././FilmMM"> <messages> <message key="invalid.year.value" value="Invalid year '{0}'! Value must be between 1900 and 2155"/> </messages> <propertyField id="releaseYear" pojoType="short"> <controlField xsi:type="formattedTextType" editPattern="####" format="Integer"> <validators> <validator key="invalidYear" errorMessage="#MSG(film, invalid.year.value, #FV())"> <errorWhen>return #FV() < 1900 || #FV() > 2155;</errorWhen> </validator> </validators> </controlField> </propertyField> <propertyField id="specialFeatures"> <controlField xsi:type="multiChoiceType" multiChoiceType="String" values="Trailers,Commentaries,Deleted Scenes,Behind the Scenes" popupToolbar="true"/> </propertyField> </pluginEntity> <generationUnit scenarioClassName="org.adichatz.scenario.impl.GroupListNavigatorScenario" adiResourceURI="adi://groupNavigator/GroupNavigatorContent" type="NAVIGATOR"/> </generationScenario> <customPostAction injectInsideScenarioFile="true" generatePojo="true" generateEJB="true" generatePersistenceXml="true" deployEJB="true"> <customGenerationUnit type="ENTITY" propertyRegex="lastUpdate"/> <customGenerationUnit type="DETAIL" propertyRegex="lastUpdate"/> <customGenerationUnit type="TABLE" entityRegex="Film"/> <customGenerationUnit type="MESSAGE_BUNDLE" entityRegex="Film"/> </customPostAction> </scenarioTree>
Remarks:
Line 4: | A new project containing resources (classes) is added to the path for generation processes. |
---|---|
Lines 10-11: | 2 new Generators are used instead of standard generators. |
Lines 16-21: | 2 new pojo rewriters are executed after Pojos are generated. |
Lines 25-26: | The controller for lastUpdate property will be a DateTextController for any entity of the project. |
Line 30: | An item is added to the message bundle file linked to the Film entity (filmGENERATED.properties file). |
Lines 33-39: | Assumes that the value of the releaseYear property must be between 1900 and 2155 (Client side). |
Line 42 : | The value of the specialFeatures property is an array of predetermined values and uses a MultiChoiceController controller. |
Line 45: | A new navigator will be generated which provide List/Detail query editor. |
Line 48: | Regenerate Entity MetaModel (e.g. ActorMM) for all entity having a lastUpdate property. |
Line 49: | Regenerate Detail Include (e.g. ActorDI) for all entity having a lastUpdate property. |
Line 50: | Regenerate Table Include (e.g. FilmTI) for Film entity. |
Line 51: | Regenerate Message Bundle (e.g. film.properties) for Film entity. |
When defining a datasource, a Customization file can be specified linked to this data source.
Each time this data source is chosen, the customization file is suggested to bring changes to the scenario tree before launching the generation process.
|
|
|
Initial and final Scenario.xml can be respectively seen here and here.: