#### Illustrative examples

After you installed JReport Designer, you can find the following illustrative sample programs for using the Engine Bean in `<install_root>\help\designer\samples`.

- TestEngineBean.java

  A sample program. Here is an explanation of how TestEngineBean.java works, and how it uses the methods provided by JReport Engine Bean.

  First, the example file TestEngineBean.java contains hard-coded paths. These must be modified before they can be compiled and run. For example, assume that JReport Designer has been installed to `C:\JReport\Designer`, the Test B section can be modified as follows:

      bean.setUID("test");
      bean.setKey("ffffffffffffffffffffffffffffffffffffffff");
      bean.setReportHome("C:\\JReport\\Designer");
      bean.setReportName("C:\\JReport\\Designer\\Demo\\Reports\\SampleReports\\CustomerAnalysis.cls");
      bean.setCatName("C:\\JReport\\Designer\\Demo\\Reports\\SampleReports\\SampleReports.cat");
      bean.setTimeZone("CST");
      bean.setParamValues("p_StartDate=01/01/2006,p_EndDate=12/31/2007");
      bean.setResultFile("C:\\JReport\\Designer\\temp\\CustomerAnalysis.rst");

  The result file will be saved in the `C:\JReport\Designer\temp` directory and the result file name will be SalesAnalysisbyRetailStore.rst.

  In addition, TestEngineBean.java will also show how to use JReport Engine Bean to export the result file (.rst extension) to the different file formats (HTML, PDF, TEXT, etc.).

  Assume that SalesAnalysisbyRetailStore.rst has already been generated by JReport Engine Bean, you can then export it to the different file formats:

      bean.exportToPdf("C:\\JReport\\Designer\\temp\\CustomerAnalysis.pdf");
      bean.exportToText("C:\\JReport\\Designer\\temp\\CustomerAnalysis.txt", true);
      bean.exportToHtml("C:\\JReport\\Designer\\temp\\CustomerAnalysis.html");

  `C:\\JReport\\Designer\\temp\\...` is the location where users specify the new generated files. Finally, TestEngineBean.java will call the methods to add, delete, save and get the WHERE portion in the report catalog:

      bean.saveWherePortion("WherePortionCustomerID","@\"Customer ID\" < 20");
      bean.setNamedWherePortion("WherePortionCustomerID1");
      bean.setWherePortion("((@\"Customer ID\" > 10) and (@\"Customer ID\" < 20))");
      bean.deleteWherePortion("WherePortionCustomerID1");
      bean.getAvailableQueryFields();
      bean.getAvailableWherePortions();

  To run TestEngineBean.java, you need to use the following command to compile it first:

      C:\JReport\Designer\help\designer\samples>
      javac -classpath C:\JReport\Designer\lib\jrengine.jar;C:\JReport\Designer\lib\sac.jar;
      C:\JReport\Designer\lib\log4j-1.2.8.jar; TestEngineBean.java

  Here, it is assumed that `C:\JReport\Designer` is the location where JReport Engine Bean has been installed to, and it is the current directory when users execute these commands. The sample program can then be run with the following command:

      C:\JReport\Designer\help\designer\samples>
      java -classpath C:\JReport\Designer\lib\jrengine.jar;C:\JReport\Designer\lib\sac.jar;
      C:\JReport\Designer\lib\log4j-1.2.8.jar; TestEngineBean
      java -Dreporthome="C:\JReport\Designer"
      -classpath C:\JReport\Designer\lib\jrengine.jar;C:\JReport\Designer\lib\sac.jar;
      C:\JReport\Designer\lib\log4j-1.2.8.jar;C:\JReport\Designer\lib\hsqldb.jar; TestEngineBean

  When the sample program is complete, you will notice a temporary file `<reportname>.rst`. For this particular sample program, it will either be customerlist.rst or phaseorder.rst depending on which report has been executed. These result files can be read and displayed by either JReport Viewer (the thin client viewer) or JReport Result Viewer Bean.

- TestWherePortion.java and LocalWherePortion.java

  Sample programs purely for the method operated on a WHERE portion. You can add, save and delete a new WHERE portion just as you would with TestEngineBean.java. The difference is that the user can do all of these things in his own report home, catalog and report file. These result files can be read and displayed by either JReport Viewer (the thin client viewer) or JReport Result Viewer Bean.

  To compile and run these sample programs, you can use the same way as compiling and running TestEngineBean.java.