How do I generate Eclipse resources?

The Design Pattern Toolkit lets Eclipse users apply a single pattern template to a single application definition (XML file with application requirements). We've found that it is a good practice to make that single pattern template a "Control Template" that generates no output itself, but rather invokes the generation of a number of output files using other pattern templates. We can elaborate on the bean template example to allow for the generation of multiple beans in a single application. We might change the appdef to look like this.

<beans>
   <bean class="Teacher">
      <package>com/ibm/education</package>
      <property name="first" type="String"/>
      <property name="last" type="String"/>
      <property name="grade" type="int" />
      <property name="room" type="String" />
   </bean>
   <bean class="Student">
      <package>com/ibm/education</package>
      <property name="first" type="String"/>
      <property name="last" type="String"/>
      <property name="teacher" type="Teacher" />
</beans>

For this example we'll assume that the pattern template for a bean is in file "bean.pat". Our high-level pattern template would look like this.

** High-Level Control Template

<iterate nodes="/beans/bean" name="curBean" >
   <start 
      resource="%curBean/package%"/>/%curBean(class)%.java"/>"
      template="bean.pat" />
</iterate>

There is one change we have to make to the original bean.pat file. Since there are several beans and we're generating the code for the current bean in the iteration, all content and attr tags in the bean.pat template need to be changed from node="/bean" to node="curBean".

A very powerful feature of the design pattern toolkit is that multiple templates can be applied to the application definition during a single generation. For example, you can create a pattern template for a JSP that displays one of the beans generated by the bean.pat template. By adding another iterate block to your control.pat high level template, you can also create a number of JSP's. Most complex application have a number of different artifacts (Java, JSP, XML, etc) that use information from the same application definition. By specifying information once and using that information in multiple pattern templates, you can significantly reduce the number of errors in the generated application.


© Copyright IBM Corporation 2000, 2005. All Rights Reserved.