When creating an analysis module that implements the IReport
interface,
follow the same steps for creating a new class that were outlined in the
Writing an analyzer that implements IAnalyze section.
However, this time you should enter the following information in the New Class wizard:
DWReport
com.ibm.dtfj.analyzer.base.AnalyzerBase
com.ibm.dtfj.analyzer.ext.IReport
The code in Listing 2 demonstrates a class that implements the IReport interface. This simple example outputs the machine type that the dump was created on. No decisions are made by the class as its sole function is to create a report. Enter the contents of Listing 2 into your newly created DWReport class to follow along with the example.
package mypackage; import com.ibm.dtfj.analyzer.base.AnalyzerBase; import com.ibm.dtfj.analyzer.base.AnalyzerContext; import com.ibm.dtfj.analyzer.ext.IAnalysisReport; import com.ibm.dtfj.analyzer.ext.IAnalyzerContext; import com.ibm.dtfj.analyzer.ext.IReport; import com.ibm.dtfj.image.DTFJException; import com.ibm.dtfj.image.Image; /** * This is the basic design required to implement an IReport Interface */ public class DWReport extends AnalyzerBase implements IReport { private static String description = "DWReport example"; public DWReport() {} /* * (non-Javadoc) * @see com.ibm.dtfj.analyzer.base.AnalyzerBase#getShortDescription() */ public String getShortDescription() { return description; } /* * (non-Javadoc) * @see com.ibm.dtfj.analyzer.ext.IReport#produceReport() */ public IAnalysisReport produceReport() { IAnalysisReport ret = allocateReport(); IAnalyzerContext ctx = getContext(); if (ctx instanceof AnalyzerContext) { try { Image p = ((AnalyzerContext)ctx).getCurrentImage(); ret.printLiteral("Image created on " + p.getSystemType()); } catch (DTFJException e) { e.printStackTrace(); } } return ret; } } |
You can see from this example that there are two methods that require an implementation:
getShortDescription()
and produceReport()
.
The aim of the produceReport
method is to extract some useful information from the dump and
return it in report form so that it can be encapsulated in the IAnalysisReport object for later use.
This will be passed to a formatter which will format the report object
for viewing. In the above example a simple report is produced which contains the type of system that the dump was created on.