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:
1<?xml version="1.0" encoding="UTF-8"?>
2<personal-iom-project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://www.firstbase.nl/xsd/personaliom/project
4 http://www.firstbase.nl/xsd/personaliom/project.xsd"
5 xmlns="http://www.firstbase.nl/xsd/personaliom/project"
6 allowDeprecated="true">
7 ...
8</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:
Go to ‘XML’
‘XML Catalog’
‘User Specified Entries’
‘Add’
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
At ‘key type’ select “Namespace Name” (already selected by default)
‘Ok’
‘Add’
Navigate to the same XSD.
Now select ‘key type’ “Schema Location”
The key (i.e. schema location) is: http://www.firstbase.nl/xsd/personaliom/project.xsd (don’t forget the .xsd suffix after the namespace)
‘Ok’
The above steps need to be repeated for both the namespace model and pattern:
<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">
<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"
>
Under construction - replace (image with) deprecated namespaces
pattern.xml old
namespace = http://www.firstbase.nl/xsd/personaliom/pattern
schemalocation = http://www.firstbase.nl/xsd/personaliom/pattern.xsd
When the namespace and schemalocation of all 3 XSDs are bound, then the Eclipse XML catalog looks as follows:
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:
Select the Snippets view
Press the right mouse button and choose ‘customize’
Choose import
Selecteer the file freemarker-snippets-metafactory.xml inside the Support/Eclipse folder of the MetaFactory installation
Choose ‘Open’
‘Apply’
After these steps your Snippets will look like this: