ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Hangin' with the JAX Pack, Part 3: Registries
Pages: 1, 2

Registering services

Now, let's look at how services are registered with JAXR.

JAXR support for managing registry entries is conceptually a bit more difficult than searching because registry entries have a life cycle. Lifecycle operations normally fall into three categories:

  • A service is born. Add a service to a registry.
  • A service changes. Change the classification of a service.
  • A service dies. Remove the service from the registry.

In order to support these operations, JAXR contains the notion of a business lifecycle manager object, which helps in adding, deleting, changing, and recategorizing services.

Let's look at the steps in adding a Web service to a registry:

  1. Create a connection.
  2. Define the service.
  3. Use the lifecycle management services to save the definition into the registry.

Listing 2 shows how we would go about registering a service into a registry:

Listing 2: JAXRRegister.java

00 //
01 // Developed from the JAXR Spec and API docs
02 // both of which are subject to change
03 //
04 import javax.xml.registry.*;
05 public class JAXRRegister extends RegistryClient {
07  //
08  // The two onException and onResponse methods are defined by the RegistryClient
09  // interface to support asynch. messaging.
10  //
11  void onException() { };
12  void onResponse() { };
14  Connection getConnection(){
16    // . . . Exactly like searching
17  }
19  void Register() {
21    Connection conn = getConnection();
22    Registry Service rs = conn.getRegistryService();
23    BusinessLifeCycleManager lcm = rs.getBusinessLifeCycleManager();
25    Organization org = lcm.createOrganization("Lumber Yards of Nashua");
26    org.setDescription("All the wood you'll ever need!");
28    ClassificationScheme cs = lcm.createClassificationScheme("ntis-gov:naics",
29     "North American Industry CLassification System");
31    // our unique UUID
32    infomodel.Key ckey = lcm.createKey("uuid:C0AABBCC-3333-AB66-000011113333");
33    cs.setKey(cKey);
34    Classification cf = (Classification)lcm.createClassification(cs,"Lumber and Lumber Yards","11111");
36    Collection classifications = new ArrayList();
37    classifications.add(cf);
39    org.addClassifications(classifications);
40    Collection orgs = new ArrayList();
42    orgs.add (org);
43    lcm.saveOrganization(orgs);
44  }
46 }

Let's look at this code in detail.

Line 4 again imports the required JAXR classes.

At line 21 we create a connection to the registry service provider; at line 22 we use the connection to obtain an instance of a registry.

At line 23 we then create our BusinessLifeCycleManager object. We can use this object to perform a variety of lifecycle management operations.

Lines 25 to 34 define the Web service by describing the classification scheme we will use, the description of the service, and its ID. Under normal circumstances, the UUID would be provided by the registry service provided, such as ebXML, to avoid clashes, although JAXR allows for user-defined IDs. An in-depth description of the classification interfaces and objects is defined in the JAXR specification.

Related Reading

Java and XML, 2nd Ed.Java and XML, 2nd Ed.
By Brett McLaughlin
Table of Contents
Sample Chapter
Full Description
Read Online -- Safari

Once we've defined our service, we simple add it to the registry. Line 43 uses our lifecycle manager to add the new Web service.

Once the service has been added, it can be used by any Web service, JAXPack-based or otherwise.


The JAXR APIs are interesting and easy to use. Perhaps all the more so because they completely hide the SOAP-based underpinnings of communcations with various registries. A word of caution, however: numerous differences were found between the JAXR specification, the Java docs for JAXR, and the provided interfaces. JAXR is clearly an evolving specification.

In the final article in the series, we'll look at JAX-RPC.

Al Saganich is BEA Systems' senior developer and engineer for enterprise Java technologies, focused on Java integration and application with XML and Web services.

Previously in this series:

Hangin' with the JAX Pack, Part 1 -- In this three-part series, BEA Systems' Al Saginach takes a look at the JAX Pack, JAVA APIs for providing XML-based Web services handling XML. This week Al looks at JAXP (for XML processing) and JAXB (for XML binding). Next week: XML messaging with JAXM.

Hangin' with the JAX Pack, Part 2: JAXM -- Al Saganich examines JAXM, the Java API for XML Messaging, and shows how it provides support for accessing various messaging formats.

Return to ONJava.com.