The ReportRegistry and FileReportRegistry Classes

ReportRegistry is an abstract class that defines a generic interface for maintaining a list of expense reports, shown in Example 5-7.

Example 5-7. The ReportRegistry class
package com.mycompany.expense;

import java.util.Date;
import java.util.List;

public abstract class ReportRegistry {
    public abstract void addReport(Report report) throws RegistryException;

    public abstract void updateReport(Report report) throws RegistryException;

    public abstract void removeReport(Report report) throws RegistryException;

    public abstract Report getReport(int id) throws RegistryException;

    public abstract List getReports(String owner, Date from, Date to,
                                    int[] status) throws RegistryException;
}

It defines methods for adding, updating, removing, and getting a single Report, and one method for getting a set of Report instances that matches a search criteria.

The concrete subclass of the ReportRegistry used in this book is called FileReportRegistry. It’s a simple implementation that uses a file in the user’s home directory for persistence. The constructor initializes the registry from the file, and all methods that modify the registry also save the updated registry to the file. This is okay as a proof-of-concept, but it would be too slow for a registry with many reports. In a real application, I would use a subclass that keeps the registry information in a database instead. Example 5-8 shows the instance variables and the constructor for the FileReportRegistry ...

Get JavaServer Faces now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.