O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required