Before adding a Java Object table, you need to define your own classes to create a Java Object.  Inside the classes, there must be a class method to return a collection object (for example, Vector). Each element of the return collection is treated as a row for the table you want to add.  Furthermore, each of the elements contains the fields for the row. Each field can be a primitive data type (for example, int), an object (instance of a class), or a collection object (for example, Vector). The following sample code shows you how to create a Java Object:

 

package com.peernet.javaobject;

import java.util.Vector;

 

// This is a sample program to illustrate how to create 

// a Java Object to be added as a table.

 

public class Student {

 

  private int ID;

  private String firstName;

  ...

 

  public Student(int id, String fname ...) {

    ID = id;

    firstName = fname;

    ...

  }

 

  public int getID() {

    return this.ID;

  }

 

  public String getFirstName() {

    return this.firstName;

  }

 

  ... 

 

  static public Vector createStudents() {

    Vector v = new Vector();

 

    Vector row1 = new Vector();

    Vector row2 = new Vector();

    ...

 

    // create 1st student

    row1.add( new Student(100001, "Suzan", 'F', 3.65, "English", "Ottawa") );

    row1.add( "Language" ); // department

    row1.add( "Oxford" );  // university

 

    // create 2nd student

    row2.add( new Student(100002, "John", 'M', 3.75, "Civil", "Chicago") );

    row2.add( "Engineering" );

    row2.add( "Princeton" );

 

    ...

 

    // add rows to v (the table)

    v.add( row1 );

    v.add( row2 );

    ...

 

    return v;

  }

}

 

Note that you can locate this sample code in the file Student.java, which can be found in the \userguide\samples folder under the PEERNET Reports installation directory.

 

Compile your Java code to generate classes. You can create a JAR file to contain these classes. Then, in your current project, you must add a class path for the classes or the JAR file. Note, however, that you can also copy JAR, CLASS, and ZIP files for use in your project to the \lib folder under the PEERNET Reports installation directory. Files copied to this location will be automatically referenced, and do not have to be added as class paths to be used in your project. For more information about class paths, see Chapter 22: Working with Class Paths.

 

The class path can be either the full path containing the classes or JAR file name, or just the path (full folder name); for example, c:\classes\xyz.jar or c:\classes\. Under the classes folder you could have sub-folders that reflect the class hierarchies and/or a collection of JAR files required by the project.