JeeWiz Home  
The Model-Driven System Builder

JeeWiz Architect's Guide
 
Contents  >   11.  How To
 


11.8 Debug Patterns

Debugging patterns can be hard. Not only are there the normal template issues to get right, but there are also all the interactions between patterns (object A creates object B, which creates object C) and the ordering of pattern phases to consider. The techniques to debug patterns are described here.

 11.8.1  The 'dump' Property
 11.8.2  The 'tracePatterns' Build Property
 11.8.3  Adding to Patterns
 11.8.4  If All Else Fails...

11.8.1  The 'dump' Property
The first step in debugging a pattern is to generate the aggregate XML file, after patterns have been applied, using the 'dump' switch:
ant "-Dpass=-Ddump=aggregate.xml"
This is described in the section on Running JeeWiz.

This creates a dump of the generated system in three parts:
  1. The (aggregate) XML for the fully-resolved specification, after all patterns have fired. This allows you to see all the generated objects and code.
  2. The call structure between patterns and templates.
  3. A summary log of the patterns that fired on objects to create other objects. This is effectively a blow-by-blow account of the more complex patterns at work; simple patterns that do not create other objects are omitted from this log.

11.8.2  The 'tracePatterns' Build Property
To find the source pattern for all objects, you can use the 'tracePatterns' build property. This will give you the initial pattern (e.g. '.../preIncludeSpec.vm') that created the object, noted as the 'sourcePattern' attribute on the object. If this pattern calls other files, this can be seen in the part 2 (the call structure) of the dump.
11.8.3  Adding to Patterns
It is also possible to add debugging code to the patterns (or other parsed files).

You might try to use the technique of, say, adding a comment. The issue with debugging patterns is that comments will be thrown away in reading the XML: this is what the JeeWiz specification read-in does. As the aggregate XML (part 1 of the dump) is generated from the in-memory specification, comments in the patterns will be missing.

There are two standard ways to get extra information out of pattern processing.
  1. The first is via the log methods, which are available on every model object (we normally use '$this', because it is always valid). This takes a string and puts the information out to the console, ending up as a standard log line. The log function returns a 'empty line deleter' string, which is a character that is removed during rendering, but also has the effective of deleting an empty line if that is the only string on the line. The above example would be recast as
    $this.log( $entity.name )
  2. The second is to generate a debug XML element - e.g. <debug firstItem="$firstItem"/>. This has the advantage that the debug element is listed alongside any other objects generated by the pattern.

11.8.4  If All Else Fails...
The final
  • Set tracing on, as described here.
  • Run in verbose mode ("ant -Dpass=-verbose") as described here. As this produces a lot of output, you will want to pipe it to a file, so the complete command would be something like
    ant -Dpass=-verbose >c:\temp\trace.txt
    
This produces a detailed trace that shows how the search for templates proceeded (following the chain of template.properties). It also gives an insight into how patterns are fired and for what objects, e.g.

0000000000000000000000000000000000000000000000000000000000000000000000000
--------  Start pattern   ------
>>>> template preIncludeSpec.vm read from file: C:\JeeWiz\resources\demo\control\application\preIncludeSpec.vm
Velocity template C:\JeeWiz\resources\demo\control\application\preIncludeSpec.vm
!!Parsing automatically generated 'super' file - current component = ComponentManager(application 'SimpleApp')
>>>>>>>> template preIncludeSpec.vm read from file: C:\JeeWiz\bin\file0.txt
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
Processing pattern preIncludeSpec.vm (file=C:\JeeWiz\resources\demo\control\application\preIncludeSpec.vm)
  for component application 'SimpleApp' (Application(SimpleApp))
  using original pattern object directory 'application'
<this>
   <ui-jar name="SimpleApp">
   </ui-jar>
</this>
_________________________________________________________________________
Created new element of class uk.co.nte.jw.components.screen.UiJar using original element tag of ui-jar, 
   parent=SimpleApp, parent class=uk.co.nte.jw.components.j2ee.Application
This notes the start of each pattern, gives the exact file it is being read from, and shows files included by the pattern, with the level of nesting shown by indentation with chevrons ('>>>>'). Following the ooooo's, the pattern file-name is logged again, with the identification of the object in XML specification, and the listing of the generated pattern ('<this>....</this>'). Then following, the '____' line, the objects created from the pattern are listed.
 


Copyright (c) 2001-2008 New Technology/enterprise Ltd.