java.lang.Object
com.ibm.j9ddr.corereaders.tdump.zebedee.util.Template

public class Template extends Object
This class represents a single template as defined in a template xml file. A template defines the layout of storage in memory (similar to a C struct) and the purpose of templates is to define for each field, the name, offset in bytes, length, type, description etc. The template classes have no dependencies on any of the other Zebedee classes and so may be reused for other purposes. All it requires is that the user supplies an implementation of ImageInputStream so that the template classes can obtain the data for the fields in each structure.

The DTD for the XML description of a template type can be found here (in pretty html format) or here (in raw form). The XML is always verified and the first line must contain the following DTD declaration: <!DOCTYPE type SYSTEM "file://template.dtd"> (the reference to template.dtd is automatically intercepted).

Templates are created using the factory method getTemplate rather than being instantiated directly so only one persistent instance is created for a given name.

  • Method Details

    • getTemplate

      public static Template getTemplate(String templateFileName) throws FileNotFoundException, com.ibm.j9ddr.corereaders.tdump.zebedee.util.InvalidTemplateFile
      Create a new Template from the given template file.
      Parameters:
      templateFileName - the name of the template file. This can be relative or absolute and must include the ".xml" (if any). getResourceAsStream is used to locate the xml file so absolute pathnames are actually relative to this class's classpath.
      Throws:
      FileNotFoundException - if the xml file could not be found
      com.ibm.j9ddr.corereaders.tdump.zebedee.util.InvalidTemplateFile - if the xml is invalid in any way
    • templateName

      public String templateName()
      Returns the name of this template as specified by the top level element
    • getField

      public TemplateField getField(String name) throws NoSuchFieldException
      Returns the TemplateField with the given name.
      Parameters:
      name - the name of the field
      Throws:
      NoSuchFieldException - if there is no field with the given name
    • getFields

      public List getFields()
      Returns a List of the fields in the Template in their original order.
      Returns:
      list the List of fields
    • getOffset

      public int getOffset(String fieldName) throws NoSuchFieldException
      Returns the offset in bytes of the specified field within the template.
      Parameters:
      fieldName - the name of the field
      Returns:
      the offset of the field
      Throws:
      NoSuchFieldException - if there is no field with the given name
    • length

      public int length()
      Returns the length in bytes of this template
    • main

      public static void main(String[] args)
      This method is mainly for regression testing. It prints a text version of the given template files just containing the field name, offset and length. It's much easier to do a diff on this format than the xml which I tend to fiddle with quite a lot!