2.6. T05 Foreach Object

In this tutorial we will create a class for each object in the model.

  • Open in directory metafactory-workshop-metafactory\src\model the file called model.xml and add the highlighted content:

Eye S You can open model.xml directly from the MetaFactory Project window by double clicking it.

Listing 2.11 src/model/model.xml
 1<?xml version="1.0" encoding="UTF-8"?>
 2<model xmlns="https://metafactory.io/xsd/v1/model"
 3       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 4       xsi:schemaLocation="https://metafactory.io/xsd/v1/model https://metafactory.io/xsd/v1/model.xsd">
 5  <metadata>
 6    <angular.webapp>
 7      <main.directory>src/main/webapp</main.directory>
 8      <root>src/main/webapp/app</root>
 9    </angular.webapp>
10    <application>
11      <backend.api.url>
12        <dev>http://workshop.local:8080</dev>
13        <prod>https://localhost:8080</prod>
14      </backend.api.url>
15      <frontend.host.dev>localhost</frontend.host.dev>
16    </application>
17    <backend.app.class.name>MetaFactoryworkshopApplication</backend.app.class.name>
18    <main.stylesheet.filename>global.scss</main.stylesheet.filename>
19  </metadata>
20  <package name="domain">
21    <metadata>
22      <base>com.metafactory.workshop</base>
23      <content.folder.name>content</content.folder.name>
24      <dto>
25        <demo.keyword>Demo</demo.keyword>
26        <rest.controller.package>com.metafactory.workshop.rest.dto</rest.controller.package>
27      </dto>
28      <jhipster>
29        <login.screen>modal</login.screen>
30        <style>6</style>
31      </jhipster>
32      <jhl.base>com.metafactory.workshop</jhl.base>
33      <main.stylesheet.filename>global.scss</main.stylesheet.filename>
34      <markup.version>material_v1</markup.version>
35      <maven.artifact>
36        <id>metafactory-workshop</id>
37        <name>MetaFactory workshop</name>
38        <version>1.0.0-SNAPSHOT</version>
39      </maven.artifact>
40      <model>
41        <implementation.package>com.metafactory.workshop.domain</implementation.package>
42        <runtime.package>org.metafactory.model.runtime.domain</runtime.package>
43      </model>
44      <project.support.intelligentfiltering>true</project.support.intelligentfiltering>
45      <repository.jpa>
46        <class.package>com.metafactory.workshop.repository.jpa.impl</class.package>
47        <dialect>
48          <packagename>com.metafactory.workshop.repository.dialect</packagename>
49          <version>82</version>
50        </dialect>
51      </repository.jpa>
52      <repository>
53        <jpa>
54          <interface.package>com.metafactory.workshop.repository.jpa</interface.package>
55        </jpa>
56        <style>JPA2</style>
57        <util.package>com.metafactory.workshop.repository.util</util.package>
58      </repository>
59      <sequencename>hibernate_sequence</sequencename>
60      <theme>hoursangular</theme>
61    </metadata>
62    <object name="YourFirstObject">
63      <attribute name="firstAttribute" type="String"></attribute>
64    </object>
65    <object name="YourSecondObject">
66      <attribute name="secondAttribute" type="String"></attribute>
67    </object>
68  </package>
69</model>
  • Open in directory metafactory-workshop-metafactory\src\patterns\package\feature1 the file called pattern1.xml and adapt line 7 so it has the highlighted content:

Listing 2.12 src/patterns/feature1/pattern1.xml
 1<package xmlns="http://www.firstbase.nl/xsd/personaliom/pattern"
 2         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3         xsi:schemaLocation="http://www.firstbase.nl/xsd/personaliom/pattern http://www.firstbase.nl/xsd/personaliom/pattern.xsd"
 4         name="com.company.workshop"
 5         path="src/main/java"
 6         package="domain">
 7  <class name="${object.name}" foreach="object">
 8    <operation name="constructor">
 9      <body>${fmsnippet.feature1.constructor}</body>
10    </operation>
11  </class>
12</package>

Now:

  • Click on metafactory-workshop-metafactory in the MetaFactory Project window.

  • Click on the Play button to run the MetaFactory tool.

Once finished the MetaFactory Tool will have generated a class for each object in the model

  • Open the directory metafactory-workshop-backend\src\main\java\com\company\workshop to see the result.