| home / programming / java / webservices / chap3 / 4 | [previous] [next] |
|
|
A standard Java class that implements a service is sometimes known as the service implementation class. The Standard Java Provider invokes this class when the Apache SOAP runtime receives a request for the service from a SOAP client.
Let's look at the service implementation class for the Job Resumé Repository Service. It
contains functionality for storing and retrieving resumés using the submit() and
retrieve() methods, respectively. The service is implemented by the
com.wrox.jobresume.service JobResumeRepositoryService class. It's located in
JobResumeRepositoryService.java, which is listed below:
package com.wrox.jobresume.service;
import java.util.Hashtable;
import com.wrox.jobresume.Resume;
public class JobResumeRepositoryService extends Object {
private Hashtable resumeList = null;
private int resumeUID;
public JobResumeRepositoryService() {
// Initiate the resumeList
resumeList = new Hashtable();
// Initiate the resumeCounter to 1000
resumeUID = 1000;
// Create a default resume
Resume resume = createDefaultResume();
submit(resume);
}
public String submit(Resume resume) throws IllegalArgumentException {
if (resume == null) {
throw new IllegalArgumentException("The resume argument must not be null");
}
try {
// Generate a uid for the resume
String uid = new Integer(resumeUID).toString();
System.out.println("UID=" + uid);
resumeUID+=1;
// Store the uid with the resume object
resume.setUid(uid);
// Store the resume object in the hashtable
resumeList.put(resume.getUid(),resume);
return uid ; // return the generated uid
} catch (NullPointerException e) {
// completed unsuccesfully - the resumé was not stored
return null;
}
}
public Resume retrieve(String uid) throws IllegalArgumentException {
if (uid == null) {
throw new IllegalArgumentException("The uid argument must not be null");
}
return (Resume)resumeList.get(uid);
}
public Resume createDefaultResume() {
String fName = "Mack";
String mName = "Levin";
String lName = "Hendricks";
String address = "600 Denali";
String city = "Southfield";
String state = "MI";
String zip = "48342";
String pNumber = "248-555-1212";
String education = "1998-2000 Oakland University\n" +
"Masters of Science in Computer Science\n" +
"Rochester Hills, MI 48309\n\n" +
"1992-1998 Oakland University\n" +
"Bachelor of Science, Computer Science\n" +
"Rochester Hills, MI 48309";
String wHistory = "Work history goes here!";
String references = "Available upon Request";
Resume resume = new Resume(fName, mName, lName, address,city, state,
zip, pNumber, education, wHistory, references);
return resume;
}
}
The submit() method takes a Resume object as a parameter. The Resume
object contains attributes that represent a physical resumé. We will discuss the details of the
Resume object in a later section. The submit() method also generates a unique
ID (uid) to uniquely identify the Resume object, stores the uid as
part of the Resume object, and stores the Resume object in a Hashtable
with the uid as the key. Also, if the Resume object was stored successfully then
the uid is returned to the calling application, which in our case is a SOAP client. The
retrieve() method retrieves a Resume object from the Hashtable using
the uid. Notice that a default resume is created and stored in the HashTable with a
uid value of 1000.
| home / programming / java / webservices / chap3 / 4 | [previous] [next] |
Created: June 5, 2002
Revised: June 5, 2002
URL: http://webreference.com/programming/java/webservices/chap3/4/2.html