Service Registry 3 2005Q4 Developer's Guide

Saving Objects in the Registry

After you have created an object and set its attributes, you publish it to the Registry by calling either the LifeCycleManager.saveObjects method or an object-specific save method like BusinessLifeCycleManager.saveOrganizations or BusinessLifeCycleManager.saveServices. You always publish a collection of objects, not a single object. The save methods return a BulkResponse object that contains the keys (that is, the unique identifiers) for the saved objects. The following code fragment saves an organization and retrieves its key:

// Add organization and submit to registry
// Retrieve key if successful
Collection orgs = new ArrayList();
orgs.add(org);
BulkResponse response = blcm.saveOrganizations(orgs);
Collection exceptions = response.getExceptions();
if (exceptions == null) {
    System.out.println("Organization saved");

    Collection keys = response.getCollection();
    Iterator keyIter = keys.iterator();
    if (keyIter.hasNext()) {
        javax.xml.registry.infomodel.Key orgKey =
             (javax.xml.registry.infomodel.Key) keyIter.next();
        String id = orgKey.getId();
        System.out.println("Organization key is " + id);
    }
}

If one of the objects exists but some of the data have changed, the save methods update and replace the data. This normally results in the creation of a new version of the object (see Changing the State of Objects in the Registry).