Introduction to TC's Packages

Contents

  1. Package connection
  2. Package tc.calendar
  3. Package tc.ui
  4. Package tc.database
  5. Package tc.application
  6. Other packages

In the following, we have decribed the use of the packages in TC and Connection frameworks, and also listed the main extension possiblities and how to utilize them. The TC framework takes care of three major tasks: calendar logic (together with its user interface), database access, and message passing between clients and the server.

connection

To accomplish the message passing between clients and the server TC utilizes a separate mini framework — Connection — that provides services for message sending and receiving and also defines an interface and a basic mechanism for message handling. Figure 5 shows the architecture of the connection package. Classes that are referenced from the package but are not in it are depicted as darker rectangles (the same applies for all subsequent class diagrams).

The upper half of the figure represents the core of the framework. Its main component is ConnectionManager that controls message sending, receiving, and handling. ConnectionManager delegates these functions to its subcomponents: MessageWriter, MessageReader, and MessageHandler. MessageWriter is used for writing messages to a stream and MessageReader for reading them. Reading and writing is implemented with Java streams and serialization.

Figure 5: The connection package

MessageHandler is a super class for all message handlers needed in an application. Besides the handle operation that ConnectionManager calls after receiving a message, MessageHandler also offers mechanism for chaining message handlers and delegating incoming messages onwards in the chain until they get handled. The mechanism conforms to the Chain of Responsibility design pattern [GHJ95]. An application creates a ConnectionManager for managing its messages by giving it (1) an input and output stream as the source and sink of messages and (2) the root of the linked message handlers that handle incoming messages. An application may also register ExceptionObserver objects for ConnectionManager. These objects are notified upon a possible exception during message reading or writing. Normally, exceptions only arise when the entity on the other end of the stream terminates. The core components of connection package all handle Message objects. Application developer must subclass this abstract class to define her own messages.

The lower half of figure 5 shows the Connection framework's subcomponent that implements a general client/server architecture based on ConnectionManager and sockets. Client and Server are started as separate processes. Server includes a ServerSocket for listening connections from Client objects. Client creates its own socket in order to connect to Server. Server in turn creates a new thread (object of ServerThread class) to communicate with each client.

tc.calendar

The calendar package of TC (see figure 6) defines the basic calendar concepts: TimeGrid, TimeSlice, and Marker. TimeGrid is an adapter that represents a vector of TimeSlice objects as a grid. The grid can be used as a model for the CalendarPanel user interface component. A TimeSlice object represents a time period (from start to end ) dedicated to some marker. Marker represents any data that can be associated with a time slice. Each marker must have a unique identifier to differentiate it from other markers and a color that is used when painting the marked time slice. TimeGrid can be adjusted in a black-box manner by setting its granularity (vertical and horizontal time units) and various other parameters including its actual size and the size and the location of the window view that is shown to the user. The main parameters and logical components of TimeGrid are represented in figure 7.

Figure 6: The TC's calendar package

The grid consists of cells that represent a fraction of time. In the grid time flows from top to bottom and left to right. Grid start date and Grid end date denote the size of the grid. Window is the part of the grid that is currently shown to the user. Granularity (i.e. column unit and row unit) denotes the size of a cell as time units. Grid increment denotes the amount of new columns fetched from the data repository when the end-user chooses to view time cells that are outside the current grid.

Although the TimeGrid class includes many overridable methods related to time calculations, it is intended to be used as a black-box component. Also the Marker and TimeSlice classes are black-box components. The Marker class might be subclassed to give specialized (type safe) getters and setters for the data related to the marker. TimeSlice's main black-box setting is the date format to be used when printing the time slice as text.

Figure 7: The main parameters and logical components of TimeGrid

tc.ui

The architecture of the ui (user interface) package is illustrated in figure 8. The main component of any TC application's user interface is CalendarPanel. It visualizes the information of the TimeGrid class and offers means for the end-user to manipulate it. CalendarPanel uses JBCL class library's GridControl to visualize TimeGrid. TimeGrid's data can be modified directly and by calling CalendarPanel's refresh method, CalendarPanel updates its view according to changes. CalendarPanel includes a PopupMenu for invoking its commands and a StatusBar for informing its actions to the end-user. Several dialogs are used to display more detailed information about the time slices and to manipulate them. New commands can be added to CalendarPanel's popup menu by using the addPopupMenuItem method and by overriding the handlePopupMenuEvent method.

Figure 8: The ui (user interface) package

tc.database

TC's database package provides an extendible way to access a relational database. It also provides basic database queries needed in the TC framework including queries related to markers, time slices, and user account. The architecture of the database package is represented in figure 9.

Figure 9: The database package

DatabaseManager is the main component of the database package. Its connection descriptor property includes information, e.g., about the database that is going to be used and the driver that is used when connecting to the database. DatabaseManager handles the communication with the database. A new DatabaseManager object is intended to be created for every database connection, i.e. for every concurrent database user. DatabaseManager stores the user name and id and marker ids of the user for whom the database is opened. These attributes are obtained during database opening and marker fetching and they are later used to ensure that only data associated with the particular user is tampered via the manager.

DatabaseManager implements the interface ExceptionObserver (namely the operation exceptionOccured) so that it gets informed when an exception occurs in communication. DatabaseManager provides basic operations for opening and closing the database. Its runQuery operation can be used to pose arbitrary queries against the database. These queries are defined as subclasses for the abstract DatabaseQuery class. The class defines the methods which a database query must implement so that DatabaseManager can execute it. DatabaseManager's runQuery method calls the methods of DatabaseQuery like defined in the Template Method pattern [GHJ95].

DatabaseManager always calls doValidationCheck before the actual calculation. In this method a database query can perform an additional check which ensures that the query can be performed. If the check fails, the method must throw a subclass of ValidationException.

The getSQLClause method must return the SQL clause that is used to create a QueryDataSet for this query. The created data set is passed as a parameter for the calculate method. The isWriteQuery method determines if this query is a write query (intends to modify the data in the database). The calculate method is the most crucial in DatabaseQuery. It finalizes the query by possibly gathering information from the given data set or modifying the data set. If the query is a read query this method should create the result object that is returned in getResult. Otherwise, if this query is a write query this method should modify or remove the proper rows in the data set. The data set includes suitable methods for iterating and examining it.

tc.application

Figure 10 shows the two frameworks (the local and the remote version of TC) derived from the core TC components. These classes are stored in the application package, which reflects the fact that these systems can also be seen as applications.

The two systems both use the classes CalendarFrame and Calendar. CalendarFrame encapsulates DatabaseCalendarPanel and puts it visible on the screen. DatabaseCalendarPanel extends CalendarPanel by adding user interface commands needed for database interaction. CalendarFrame also introduces a new dialog that is not related to the time grid visualization but again rather to the database handling. This dialog — the class PasswordDialog — is used for asking user name and password. The passwords are encrypted with the MessageDigest class of the java.security package. Calendar is the common interface for the calendar logic implementations. It defines the interface for accessing the DatabaseManager. CalendarFrame calls these methods according to the user interaction.

The first system visualizes the time grid and handles the database. It does not utilize the connection package. The main class of this local system is LocalCalendar. It has TimeGrid and DatabaseManager as its direct components and it uses CalendarFrame to show DatabaseCalendarPanel (to visualize TimeGrid) and implements the Calendar interface so that it delegates the methods directly to the DatabaseManager.

Figure 10: Two systems derived from the core TC components and the connection package

The second system uses the connection package to build a client/server architecture where the server handles the database and accepts connections from several clients who visualize and manipulate their own calendars. The main class on the client side is CalendarClient. It extends Client (and thus inherits socket connection functionality) and implements Calendar so that it sends corresponding messages (e.g., GetTimeSlicesMessage) to the server side. As in LocalCalendar, CalendarClient creates a CalendarFrame to hold CalendarPanel and a TimeGrid to capture time information. CalendarClient implements Client's abstract method createMessageHandlers so that it creates the handlers needed to react to the messages received from the server. The handlers include, e.g., TimeSlicesMessageHandler that handles incoming time slices and updates them to the TimeGrid.

The main class on the server side is DatabaseServer. It extends Server to inherit socket connection functionality needed on the server side. It implements the abstract createMessageHandlers method of Server so that it creates the handlers needed to respond to messages received from the client. This method also creates a new DatabaseManager that is passed as a parameter for handlers that need to access it. The createMessageHandlers method is invoked by every new ThreadServer created by Server. In this way, every new client will have its own set of handlers and a DatabaseManager to serve it.

Other packages

Other TC packages include tc.message, tc.messagehandler.client, tc.message.handler.server, and tc.util. These include the messages used in TC and the client and server side handlers for the messages. The tc.util package includes some convenience classes.


Back to the Main Page of Time Calendar