Services InterfacesHomepage  « Case Study « Services Interfaces

We will need to seamlessly connect local or remote clients to a Manufacturer file a user has chosen and to do this we will need two interfaces that connect locally which we will call Services and remotely which we will call RemoteServices. The interfaces will need to include the stocking, unstocking and search functionality requested by the stakeholder Stocking Goods Limited. In this lesson we create the interfaces and methods required.

Compiling The Services Interfacego to top of page Top

The following Services interface will have to have methods for implementation that will encompass the following processes requested by the stakeholder Stocking Goods Limited:

  1. Stocking - A user of the system should be able to stock goods up to but not exceeding the amount of stock level held.
    • If there is a problem accessing the Manufacturer file we should throw a IOException back to the GUI.
    • If there is a problem updating the Manufacturer file or problems accessing records from the cache map we should throw a ServicesException back to the GUI.
    • A situation may arise where a user tries to stock goods that another user has already stocked and in this scenario we should throw a StockingException back to the GUI.
  2. Unstocking - A user of the system should be able to stock goods up to but not exceeding the amount of stock level held.
    • If there is a problem accessing the Manufacturer file we should throw a IOException back to the GUI.
  3. Searching - A user of the system should be able search for goods by name, by location, by name and location or search all records. We will use the client.ManufacturerTableModel class to pass back search results to the GUI.
    • If there is a problem accessing the Manufacturer file we should throw a IOException back to the GUI.

Cut and paste the following code into your text editor and save it in the   c:\_Case_Study\src\services directory.


package services;

import java.io.IOException;

import model.StockingException;

import client.ManufacturerTableModel;

/**
 * An interface implemented by services that provide access to and interaction 
 * with the Manufacturer file from a GUI.
 * 
 * @author Kevin 
 * @version 1.0
 */
public interface Services {

    /**
     * Attempts to stock the Manufacturer product specified by the GUI user.
     * 
     * @param name The name of the Manufacturer.
     * @param location The location where the Manufacturer is based.
     * @param stockLevel The amount of stock remaining.
     * @param stockOrdered The amount of stock order.
     * 
     * @throws IOException Indicates there was a problem accessing the data.
     * @throws ServicesException Indicates there was a problem updating the data.
     * @throws StockingException Indicates stocking already done by another user.
     */
    public void stockFromManufacturer( String name, String location,
            int stockLevel, int stockOrdered) 
            throws IOException, ServicesException, StockingException;

    /**
     * Attempts to unstock the Manufacturer product specified by the GUI user.
     * 
     * @param name The name of the Manufacturer.
     * @param location The location where the Manufacturer is based.
     * @param stockOrdered The amount of stock order.
     * 
     * @throws IOException Indicates there was a problem updating the data.
     */
    public void unstockBackToManufacturer(String name, String location,
            int stockOrdered) throws IOException;

    /**
     * Search contractor cache map for Manufacturer records matching the
     * criteria specified by the GUI user.
     * 
     * @param name The name of the Manufacturer.
     * @param location The location where the Manufacturer is based.
     * 
     * @return A ManufacturerTableModel holding selected records.
     * 
     * @throws IOException Indicates there was a problem accessing the data.
     */
    public ManufacturerTableModel searchManufacturers(String name, String location)
            throws IOException;
			
}

Compiling Our Source File With the -cp and -d Options

Open your command line editor:

Change to directory  cd c:\_Case_Study\src\services

Compile Services.java using the java compiler with the -cp and -d options
  javac -cp ..\..\classes -d ..\..\classes Services.java

Compiling The RemoteServices Interfacego to top of page Top

The RemoteServices interface is a marker interface that is implemented by services that provide remote access to and interaction with the Manufacturer file from a GUI.

Cut and paste the following code into your text editor and save it in the   c:\_Case_Study\src\remoteservices directory.


package remoteservices;

import java.rmi.Remote;

import services.Services;

/**
 * An interface implemented by services that provide remote access to and interaction 
 * with the Manufacturer file from a GUI. This is a marker interface that has no body.
 * 
 * @author Kevin 
 * @version 1.0
 */
public interface RemoteServices extends Remote, Services {

}

Compiling Our Source File With the -cp and -d Options

Open your command line editor:

Change to directory  cd c:\_Case_Study\src\remoteservices

Compile RemoteServices.java using the java compiler with the -cp and -d options
  javac -cp ..\..\classes -d ..\..\classes RemoteServices.java

Because we have used a package (package remoteservices;) at the top of the code the compiler has created this directory within the classes directory. When we look in the services directory we can see the compiled Services.class file and when we look in the newly created remoteservices directory we can see the compiled RemoteServices.class file.

compile Services Interfaces

Related Java6 Tutorials

Flow Control - Handling Exceptions
Flow Control - Declaring Exceptions
Flow Control - Creating Our Own Exceptions
Swing - RMI - Serialization
OO Concepts - Interfaces


What's Next?

In the next section we finish off coding the model part of the case study.

<<  Controller Part 1                   Model Part 2  >>

go to home page Homepage go to home page Top

All the Controller Part 1 lessons are listed below. Click a link to go to that lesson.


Controller Part 1

Services Exception

Services Interfaces

Services Interface

RemoteServices Interface