Java class model component

This tutorial learn to you create XML component with Java class model. It is able to generate a XML Hibernate mapping file with Java UserBean class. Template used has pojo parameter type of class.

You can find next sample into usecases-catalog/Components/Model/XMLToJavaClass.akgncpt.xml catalog.

Template

Here Freemarker template used to generate XML Hibernate mapping :

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
    
<hibernate-mapping>

<class 
    name="net.sourceforge.akrogen.bean.UserBean" 
    table="T_USER"
>
<#list pojo.fields as f>
    <property
        name="${f.elementName}"
        type="${f.typeSignature?substring(1)}"
        column="${f.elementName}"
    />
</#list>
</class>
</hibernate-mapping>

pojo is interface type of org.eclipse.jdt.core.IType where you can get method org.eclipse.jdt.core.IMethod, and fields org.eclipse.jdt.core.IField de la classe Java UserBean.

XML component

Here XML component which we must use :

<?xml version="1.0" encoding="UTF-8"?>
<component>
  <models>
    <!-- This component requires selection of Java class which is used into 
         Template context (Output) -->
    <model type="class" key="pojo" useIntoOutput="true" omitDocumentType="true" />
  </models>
  <input>
    <page title="Java class to XML" >
      <description>Transform Java Class persistent bean to a XML mapping hibernate.</description>
      <box flex="1" id="" orient="vertical"
              xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">                                                    
        <hbox>
          <label value="Output Base dir :" />
          <textbox id="outputBaseDir" flex="1" />
          <button type="folder" target="outputBaseDir" label="Browse..." />
        </hbox>
        <hbox>
          <label value="Output File name :" />
          <textbox id="outputFileName" flex="1" />
        </hbox> 
        <hbox>
          <button type="preview" label="Preview..." />
        </hbox>                 
      </box>                    
    </page>
  </input>
  <output>
    <file>
      <template uri="/ftl/JavaClass/JavaClassToXML.ftl" />
    </file>
  </output>
</component>

Create JavaClassToXML.akgncpt.xml XML component file into Components/Model/ directory of the MyAkrogenCatalog catalog.

Here explanation about this XML component :

model element

Model element define model to use into template (useIntoOutput="true"). You can use this model to generate XUL Dynamic Wizard page (with useIntoInput="true").

Here model is file type of JAVA class type="class" which is putted with key key="pojo".

XML component use

Refresh catalog View. JavaClassToXML must be appear into catalog.

Double click on JavaClassToXML component to open Wizard page. This Wizard page is displayed before displaying XML component, because it required class JAVA selection :

Select UserBean JAVA class (by keywording UserBean).

Click on Next button to display XML component Wizard page