3.2.1. Configuring Eclipse

3.2.1.1. Plugins

MetaFactory is designed to work with both Freemarker and Velocity. In order to customize Freemarker templates it is recommended to install the FreemarkerIDE plugin. FreemarkerIDE is part of JBoss Tools. Please visit JBoss-downloads and follow the instructions. You can also use Eclipse Marketplace to install Freemarker IDE or JBoss Tools.

In order to customize Velocity templates it is recommended to install the VeloEdit plugin (currently version 1.0.7). For installation use Eclipse Marketplace for the installation and search for Velocity.

3.2.1.2. XML Catalog

MetaFactory works with various types of xml files, each one using its own namespace. It would be nice if we can use the Xml editor of Eclipse to bind the namespace to the matching XSD. Let’s start with a MetaFactory project file (metafactory.xml), which looks as follows:

Listing 3.1 metafactory.xml
1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?>
<personal-iom-project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                          xsi:schemaLocation="http://www.firstbase.nl/xsd/personaliom/project
                                                        http://www.firstbase.nl/xsd/personaliom/project.xsd"
                                          xmlns="http://www.firstbase.nl/xsd/personaliom/project"
                                          allowDeprecated="true">
        ...
</personal-iom-project>

Before the XML editor of Eclipse can use XSD based autocomplete, the XSD must be bound to the namespace. To do this, open Eclipse Preferences and perform the following steps:

  1. Go to ‘XML’

  2. ‘XML Catalog’

  3. ‘User Specified Entries’

  4. ‘Add’

  5. Navigate to the XSD that belongs to the namespace of the project, which you will find in the ‘support’ folder of the MetaFactory installation. The filename is personal-iom-project.xsd

  6. At ‘key type’ select “Namespace Name” (already selected by default)

  7. ‘Ok’

  8. ‘Add’

  9. Navigate to the same XSD.

  10. Now select ‘key type’ “Schema Location”

  11. The key (i.e. schema location) is: http://www.firstbase.nl/xsd/personaliom/project.xsd (don’t forget the .xsd suffix after the namespace)

  12. ‘Ok’

The above steps need to be repeated for both the namespace model and pattern:

Listing 3.2 namespace Model
<model xmlns="https://metafactory.io/xsd/v1/model"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="https://metafactory.io/xsd/v1/model
                           https://metafactory.io/xsd/v1/model.xsd">
Listing 3.3 namespace Code instruction (replaces pattern.xml)
<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"
>

Hammer M Under construction - replace (image with) deprecated namespaces

pattern.xml old

When the namespace and schemalocation of all 3 XSDs are bound, then the Eclipse XML catalog looks as follows:

../_images/EclipseXmlCatalog-768x541.png

3.2.1.3. Code fragments for Freemarker

In the process of making new MetaFactory templates you will find that some lines of code are repeated frequently. Both the Freemarker and Velocity editor provide functionality to automize these patterns. First we need to install the patterns in the Velocity editor, using the following steps.

The Freemarker code fragments use the Eclipse Snippets View. Open this view (Menu Window -> Show View -> Other -> General -> Snippets). Now install the code fragments by executing the following steps:

  1. Select the Snippets view

  2. Press the right mouse button and choose ‘customize’

  3. Choose import

  4. Selecteer the file freemarker-snippets-metafactory.xml inside the Support/Eclipse folder of the MetaFactory installation

  5. Choose ‘Open’

  6. ‘Apply’

After these steps your Snippets will look like this:

../_images/EclipseFreemarkerSnippets.png