spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / java / webservices / chap3 / 4 To page 1current pageTo page 3To page 4To page 5To page 6
[previous] [next]

Professional Java Web Services

Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


Service Implementation Class

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 To page 1current pageTo page 3To page 4To page 5To page 6
[previous] [next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

Created: June 5, 2002
Revised: June 5, 2002

URL: http://webreference.com/programming/java/webservices/chap3/4/2.html