O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

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

Simplify your Business Delegates with the Service Locator

Unless your Business Delegates use a Service Locator, they will have duplicate code for dealing with the lookup service.

To implement a Service Locator, we’ll take all of the logic for doing the JNDI lookup and move it out of the multiple Business Delegates and into a single Service Locator.

Typically in J2EE applications, there will be a number of components that all use the same JNDI service. While a complex application might use several different registries such as JNDI and UDDI (for web service endpoints), an individual component will typically need access to only one registry. In general, a single Service Locator will support a single, specific registry.

By making the Business Delegate an object that handles only the business methods rather than also handling the registry lookup code, you increase the cohesion for the Business Delegates.

A Service Locator’s pseudo-code

// obtain an InitialContext object
// perform remote lookup
// handle remote issues
// optionally, cache references
image with no caption

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