Managing Objects in the Registry
- Once you have published objects to the Registry, you can perform operations on them. This chapter describes these operations.Creating Relationships Between Objects: Associations
Creating Relationships Between Objects: Associations
You can create an
Associationobject and use it to specify a relationship between any two objects. The ebXML specification specifies anAssociationTypeclassification scheme that contains a number of canonical concepts you can use when you create anAssociation. You can also create your own concepts within theAssociationTypeclassification scheme, if none of the canonical ones are suitable.The canonical association types are as follows:
AccessControlPolicyForAffiliatedWith(which has the subconceptsEmployeeOfandMemberOf)ContainsContentManagementServiceForEquivalentToExtendsExternallyLinksHasFederationMemberHasMemberImplementsInstanceOfInvocationControlFileFor(which has the subconceptsCatalogingControlFileForandValidationControlFileFor)OffersServiceOwnerOfRelatedToReplacesResponsibleForSubmitterOfSupersedesUsesThe Registry uses some of these association types automatically. For example, when you add a
Serviceto anOrganization, the Registry creates anOffersServiceassociation with theOrganizationas the source and theServiceas the target.Associations are directional: each
Associationhas a source object and a target object. Establishing an association between two objects is a three-step process:
- Find the
AssociationTypeconcept you wish to use (or create one).- Use the
LifeCycleManager.createAssociationmethod to create the association. This method takes two arguments, the target object and the concept that identifies the relationship.- Use the
RegistryObject.addAssociationmethod to add the association to the source object.For example, suppose you have two objects,
obj1andobj2, and you want to establish aRelatedTorelationship between them. (In this relationship, which object is the source and which is the target is arbitrary.) First, locate the concept namedRelatedTo:// Find RelatedTo concept for Association Collection namePatterns = new ArrayList(); namePatterns.add("RelatedTo"); BulkResponse br = bqm.findObjects("Concept", null, namePatterns, null, null, null, null); Collection concepts = br.getCollection();Iterate through the concepts (there should only be one) to find the right one.
Create the association, specifying
obj2as the target:Add the association to the source object,
obj1:Finally, save the association:
Collection associations = new ArrayList(); associations.add(relAssoc1); BulkResponse response = blcm.saveObjects(associations);Associations can be of two types, intramural and extramural. You create an intramural association when both the source and target object are owned by you. You create an extramural association when at least one of these objects is not owned by you. The owner of an object can use an access control policy to restrict the right to create an extramural association with that object as a source or target.
Creating Associations: Example
For an example of creating an association, see
<INSTALL>/registry/samples/publish-association/src/JAXRPublishAssociation.java. This example creates aRelatedToassociation between any two objects whose unique identifiers you specify. For example, you could specify the identifiers of the two child organizations created in Creating and Retrieving an Organization Hierarchy: Example. To run the example, follow these steps:Whether the association is intramural or extramural depends upon who owns the two objects.
Storing Items in the Repository
As About Registries and Repositories explains, the Registry includes a repository in which you can store electronic content. For every item you store in the repository, you must first create a type of
RegistryObjectcalled anExtrinsicObject. When you save theExtrinsicObjectto the Registry, the associated repository item is also saved.Creating an Extrinsic Object
To create an
ExtrinsicObject, you first need to create ajavax.activation.DataHandlerobject for the repository item. TheLifeCycleManager.createExtrinsicObjectmethod takes aDataHandlerargument.To store a file in the repository, for example, first create a
java.io.Fileobject. From theFileobject, create ajavax.activation.FileDataSourceobject, which you use to instantiate theDataHandlerobject.String filename = "./MyFile.xml"; File repositoryItemFile = new File(filename); DataHandler repositoryItem = new DataHandler(new FileDataSource(repositoryItemFile));Next, call
createExtrinsicObjectwith theDataHandleras argument:Set the MIME type of the object to make it accessible. The default MIME type is
application/octet-stream. If the file is an XML file, set it as follows:Finally, call the implementation-specific
ExtrinsicObjectImpl.setObjectTypemethod to store theExtrinsicObjectin an appropriate area of the Registry. This method has the following signature:The easiest way to find the appropriate concept for a file is to use the Explore feature of the Web Console. Look under the
ObjectTypeclassification scheme for the various types ofExtrinsicObjectconcepts. Specify the ID for the concept as the argument togetRegistryObject, then specify the concept as the argument tosetObjectType.String conceptId = "urn:oasis:names:tc:ebxml- regrep:ObjectType:RegistryObject:ExtrinsicObject:XML"; Concept objectTypeConcept = (Concept) bqm.getRegistryObject(conceptId); ((ExtrinsicObjectImpl)eo).setObjectType(objectTypeConcept);Finally, you save the
ExtrinsicObjectto the Registry.Collection extobjs = new ArrayList(); extobjs.add(eo); BulkResponse response = blcm.saveObjects(extobjs);The
ExtrinsicObjectcontains the metadata, and a copy of the file is stored in the repository.If the Registry does not have a concept for the kind of file you want to store there, you can create and save the concept yourself.
Creating an Extrinsic Object: Example
For an example of creating an extrinsic object, see
<INSTALL>/registry/samples/publish-extrinsic/src/JAXRPublishExtrinsicObject.java. This example publishes an XML file to the Registry. To run the example, follow these steps:Using an Extrinsic Object as a Specification Link
You can publish an
ExtrinsicObjectby itself, but it is also very common to create anExtrinsicObjectto use as theSpecificationLinkobject for aServiceBindingobject (see Creating Services and Service Bindings). TheExtrinsicObjecttypically refers to a WSDL file.
- Create a
SpecificationLinkobject.- Store the WSDL document in the repository and create an
ExtrinsicObjectthat refers to it. Set the extrinsic object's type toWSDLand its mime type totext/xml.- Specify the extrinsic object as the
specificationObjectattribute of theSpecificationLinkobject.- Add the
SpecificationLinkobject to theServiceBindingobject.- Add the
ServiceBindingobject to theServiceobject.- Save the
Serviceobject.After you create a
ServiceandServiceBinding, create aSpecificationLink:SpecificationLink specLink = blcm.createSpecificationLink(); specLink.setName("Spec Link Name"); specLink.setDescription("Spec Link Description");Create an
ExtrinsicObjectas described in Creating an Extrinsic Object. Use the ID for the WSDL concept and thetext/xmlMIME type.String conceptId = "urn:oasis:names:tc:ebxml- regrep:ObjectType:RegistryObject:ExtrinsicObject:WSDL"; Concept objectTypeConcept = (Concept) bqm.getRegistryObject(conceptId); ((ExtrinsicObjectImpl)eo).setObjectType(objectTypeConcept); eo.setMimeType("text/xml");Set the
ExtrinsicObjectas the specification object for theSpecificationLink:Add the
SpecificationLinkto theServiceBinding, then add the objects to their collections and save the services.When you remove a service from the Registry, the service bindings and specification links are also removed. However, the extrinsic objects associated with the specification links are not removed.
Creating an Extrinsic Object as a Specification Link: Example
For an example of creating an extrinsic object as a specification link, see
<INSTALL>/registry/samples/publish-service/src/JAXRPublishService.java. This example publishes a WSDL file to the Registry. To run the example, follow these steps:Organizing Objects Within Registry Packages
Registry packages allow you to group a number of logically related registry objects, even if the individual member objects belong to different owners. For example, you could create a
RegistryPackageobject and add to it all objects in the Registry whose names shared a particular unique string or that all contained aSlotwith the same name and value.To create a
RegistryPackageobject, call theLifeCycleManager.createRegistryPackagemethod, which takes aStringorInternationalStringargument. Then call theRegistryPackage.addRegistryObjectorRegistryPackage.addRegistryObjectsmethod to add objects to the package.For example, you could create a
RegistryPackageobject named "SunPackage":Then, after finding all objects with the string
"Sun"in their names, you could iterate through the results and add each object to the package:A common use of packages is to organize a set of extrinsic objects. A registry administrator can load a file system into the Registry, storing the directories as registry packages and the files as the package contents. See the Administration Guide for more information.
Organizing Objects Within Registry Packages: Examples
For examples of using registry packages, see the two examples in
<INSTALL>/registry/samples/packages/src:JAXRPublishPackage.javaandJAXRQueryPackage.java. The first example publishes aRegistryPackageobject that includes all objects in the Registry whose names contain the string"free". The second example searches for this package and displays its contents. To run the examples, follow these steps:Changing the State of Objects in the Registry
You add an
AuditableEventobject to the audit trail of an object when you publish it to the Registry or when you modify it in any way. See Retrieving the Audit Trail of an Object for details on these events and on how to obtain information about them. Table 8-5 on page 33 describes the events and how they are created.Many events are created as a side effect of some other action:
- Saving an object to the Registry creates an
EVENT_TYPE_CREATEDevent.- The following actions create an
EVENT_TYPE_VERSIONEDevent:
- Changing an object's name or description
- Adding, modifying, or removing a
Classification,ExternalIdentifier,ExternalLink, orSlot- For an
OrganizationorUser, adding, modifying, or removing aPostalAddressorTelephoneNumberYou can retrieve version information for an object. See Retrieving the Version of an Object for details.
Note: At this release, versioning of objects is disabled. All objects have a version of 1.1.
You can also change the state of objects explicitly. This feature may be useful in a production environment where different versions of objects exist and you wish to use some form of version control. For example, you can approve a version of an object for general use and deprecate an obsolete version before you remove it. If you change your mind after deprecating an object, you can undeprecate it. You can perform these actions only on objects you own.
The
LifeCycleManagerImpl.approveObjectsmethod has the following signature:It is possible to restrict access to these actions to specific users, such as registry administrators.
No
AuditableEventis created for actions that do not alter the state of aRegistryObject. For example, queries do not generate anAuditableEvent, and noAuditableEventis generated for aRegistryObjectwhen it is added to aRegistryPackageor when you create anAssociationwith the object as the source or target.Changing the State of Objects in the Registry: Examples
For examples of approving, deprecating, undeprecating objects, see the examples in
<INSTALL>/registry/samples/auditable-events/src:JAXRApproveObject.java,JAXRDeprecateObject.java, andJAXRUndeprecateObject.java. Each example performs an action on an object whose unique identifier you specify, then displays the object's audit trail so that you can see the effect of the example. To run the examples, follow these steps:The object you specify should be one that you created.
Removing Objects From the Registry and Repository
A registry allows you to remove from it any objects that you have submitted to it. You use the object's ID as an argument to the
LifeCycleManager.deleteObjectsmethod.The following code fragment deletes the object that corresponds to a specified key string and then displays the key again so that the user can confirm that it has deleted the correct one.
String id = key.getId(); Collection keys = new ArrayList(); keys.add(key); BulkResponse response = blcm.deleteObjects(keys); Collection exceptions = response.getException(); if (exceptions == null) { System.out.println("Objects deleted"); Collection retKeys = response.getCollection(); Iterator keyIter = retKeys.iterator(); javax.xml.registry.infomodel.Key orgKey = null; if (keyIter.hasNext()) { orgKey = (javax.xml.registry.infomodel.Key) keyIter.next(); id = orgKey.getId(); System.out.println("Object key was " + id); } }Deleting an
Organizationdoes not delete theServiceandUserobjects that belong to theOrganization. You must delete them separately.Deleting a
Serviceobject deletes theServiceBindingobjects that belong to it, and also theSpecificationLinkobjects that belong to theServiceBindingobjects. Deleting theSpecificationLinkobjects, however, does not delete the associatedExtrinsicObjectinstances and their associated repository items. You must delete the extrinsic objects separately.
AuditableEventandAssociationobjects are not always deleted when the objects associated with them are deleted. You may find that as you use the Registry, a large number of these objects accumulates.Removing Objects from the Registry: Example
For an example of deleting an object from the Registry, see
<INSTALL>/registry/samples/delete-object/src/JAXRDelete.java. This example deletes the object whose unique identifier you specify. To run the example, follow these steps: