2.3. T02 Create a Class

In this tutorial we will create a simple class with MetaFactory.

  • Add the highlighted line to your codeinstruction.xml to use a new pattern.

Listing 2.7 src/patterns/codeinstruction.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?xml version="1.0" encoding="UTF-8"?>
<code_instruction
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="https://metafactory.io/xsd/v1/codeinstruction"
        xsi:schemaLocation="https://metafactory.io/xsd/v1/codeinstruction https://metafactory.io/xsd/v1/codeinstruction.xsd
                            https://metafactory.io/xsd/v1/java-codeinstruction https://metafactory.io/xsd/v1/java-codeinstruction.xsd"
        xmlns:typescript="https://metafactory.io/xsd/v1/typescript-codeinstruction"
        xmlns:java="https://metafactory.io/xsd/v1/java-codeinstruction"
>
  <properties>
    <base>com.metafactory.workshop</base>
    <java.main.directory>src/main/java</java.main.directory>
    <java.generated.directory>src/main/generated</java.generated.directory>
    <conf.main.directory>src/main/resources</conf.main.directory>
    <java.test.directory>src/test/java</java.test.directory>
    <conf.test.directory>src/test/resources</conf.test.directory>
    <!-- Frontend properties -->
    <jhipster.style>4</jhipster.style>
    <jhipster6104_angular1000_frontend.output.path>./metafactory-workshop-frontend</jhipster6104_angular1000_frontend.output.path>
    <app.class.name>MetaFactoryWorkshopApplication</app.class.name>
    <angular.use.angular8.viewchild>true</angular.use.angular8.viewchild>
    <angular.app.name>Workshop</angular.app.name>
    <angular.app.title>MetaFactory Workshop</angular.app.title>
    <webapp.app.directory>/app</webapp.app.directory>
    <webapp.main.directory>${project.property.webapp.main.directory}</webapp.main.directory>
    <angular.library.output.path>./metafactory-workshop-frontend</angular.library.output.path>
    <angular.webapp.main.directory>src/main/webapp</angular.webapp.main.directory>
    <angular.webapp.root>src/main/webapp/app</angular.webapp.root>
    <webapp.components.selector>shc</webapp.components.selector>
    <app.showNotifications>true</app.showNotifications>
    <!-- Backend properties -->
    <jhipster6104_angular1000_backend.output.path>./metafactory-workshop-backend</jhipster6104_angular1000_backend.output.path>

  </properties>

  <!-- Load Freemarker template files -->
  <freemarker>
    <freemarker_library namespace="naming">/library/naming.ftl</freemarker_library>
    <freemarker_library namespace="util">/jhipster/util/util.ftl</freemarker_library>
    <freemarker_library namespace="state_util">/jhipster/util/state-utils.ftl</freemarker_library>
    <freemarker_library namespace="model_util">/library/model_utils.ftl</freemarker_library>
    <freemarker_library namespace="tl">/library/layout/tableLayout.ftl</freemarker_library>
    <freemarker_library namespace="metadata">/library/metadata.ftl</freemarker_library>
  </freemarker>

  <external_libraries>
    <external_library name="libMF">
      <path>./</path>
      <patterns_folder>src/patterns</patterns_folder>
      <snippets_folder>src/snippets</snippets_folder>
      <function_library>src/patterns/package/pattern-functions.xml</function_library>
    </external_library>
  </external_libraries>

  <features>

  </features>

  <!--#############################################################################################################-->
  <!--############################################### Java patterns ###############################################-->
  <!--#############################################################################################################-->

  <!-- The new MetaFactory Runtime Model => A pojo representation of your model.xml which can be used from your snippets-->
  <java:external_java_package id="libMF/package/model/runtime/model-root.xml" />
  <java:external_java_package id="libMF/package/model/runtime/model-pojo.xml" />

  <!-- your patterns here -->
  <java:external_java_package id="libMF/package/feature1/pattern1.xml" />

</code_instruction>
  • Create a new file called pattern1.xml in a new directory metafactory-workshop-metafactory\src\patterns\package\feature1 and place the following content in it:

Listing 2.8 src/patterns/package/feature1/pattern1.xml
1
2
3
4
5
6
7
8
<package xmlns="http://www.firstbase.nl/xsd/personaliom/pattern"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.firstbase.nl/xsd/personaliom/pattern http://www.firstbase.nl/xsd/personaliom/pattern.xsd"
         name="com.company.workshop"
         path="src/main/java">
  <class name="MyClass">
  </class>
</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 the Java class MyClass.

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