XML Update

Updating of source JAVA file consist in :

  • adding method (generated) into JAVA file source.
  • adding field (generated) into JAVA file source.

    There is sample into Components/CodeUpdater/Java directory of usecases-catalog catalog.

To do that, you must :

  • define model type of java into component. Whith this définition, you set JAVA file source to update. This model definition will force then user who open the component, to select JAVA file to update :
      <models>
            <model key="javaClass" type="java" />
      </models>
  • define whith file element, the method/field content to insert into JAVA source file.
    • The template to use to generate this method/field content.

    Here sample which add field content into existing JAVA file :

      <output>
        <file key="javaClass" >
                    <insert path="field" >
                    <template uri="/ftl/CodeUpdater/Java/AddJavaField.ftl" />
            </insert>          
        </file>
      </output>

    To set source JAVA file to update (which is defined into model), key attribute of the file element must refer key attribute of model element.

  • write template which generate method/field content :
    private String ${fieldName}; 

model

Model definition type of java and with javaClass is done like this :

...
<models>
  <model type="java" key="javaClass"  />
  ...
</models>
...

file

file element is inside output element. It is able to describe the updating to do on JAVA source file which is defined into model. Updating source JAVA file with key javaClass :

...
<output>
    <file key="javaClass" >
        ...
    </file>
  </output>
...

insert

insert element is inside file element. It is able to insert method/field content with path attribute :

  • set path="method" to insert method.
  • set path="field" to insert field.
...
  <file key="javaClass" >
    <insert path="method|field" >
      <template uri="..." />
    </insert>
  </file>
...

template

Method/field content to insert is generated. This generation can be done with template (Freemarker, velocity, XSL,...).

To generate method/field content with template path_of_myTemplate, insert must contain :

...
<insert path="method|field" >
  <template uri="path_of_myTemplate" />
</insert>
...