Service Registry 3 2005Q4 Developer's Guide

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 that you store in the repository, you must first create an ExtrinsicObject. When you save the ExtrinsicObject to the Registry, the associated repository item is also saved.

Creating an Extrinsic Object

To create an ExtrinsicObject, you first need to create a javax.activation.DataHandler object for the repository item. The LifeCycleManager.createExtrinsicObject method takes a DataHandler argument.


Note –

You can also use an implementation-specific form of the createExtrinsicObject method that takes no arguments. If you use this form, you can create the DataHandler object later and use the ExtrinsicObject.setRepositoryItem method to specify the repository item. You can also create extrinsic objects that have no associated repository items.


To store a file in the repository, for example, first create a java.io.File object. From the File object, create a javax.activation.FileDataSource object, which you use to instantiate the DataHandler object.

String filename = "./MyFile.xml";
File repositoryItemFile = new File(filename);
DataHandler repositoryItem =
     new DataHandler(new FileDataSource(repositoryItemFile));

Next, call createExtrinsicObject with the DataHandler as argument:

ExtrinsicObject eo =
     blcm.createExtrinsicObject(repositoryItem);
eo.setName("My Graphics File");

Set the MIME type of the object to make the object accessible. The default MIME type is application/octet-stream. If the file is an XML file, set the MIME type as follows:

eo.setMimeType("text/xml");

Finally, call the implementation-specific ExtrinsicObjectImpl.setObjectType method to store the ExtrinsicObject in an appropriate area of the Registry. This method has the following signature:

public void setObjectType(Concept objectType)
    throws JAXRException

The easiest way to find the appropriate concept for a particular type of file is to use the Explore feature of the Web Console. Look under the ObjectType classification scheme for the various types of ExtrinsicObject concepts. Specify the ID for the concept as the argument to getRegistryObject, then specify the concept as the argument to setObjectType.

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 ExtrinsicObject to the Registry.

Collection extobjs = new ArrayList();
extobjs.add(eo);
BulkResponse response = blcm.saveObjects(extobjs);

The ExtrinsicObject contains 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 that 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 JAXRPublishExtrinsicObject.java in the directory <INSTALL>/registry/samples/publish-extrinsic/src. This example publishes an XML file to the Registry (its own build.xml file).

ProcedureTo Run the JAXRPublishExtrinsicObject Example

Steps
  1. Go to the directory <INSTALL>/registry/samples/publish-extrinsic.

  2. Type the following command:


    asant run
    

Using an Extrinsic Object in a Specification Link

You can publish an ExtrinsicObject by itself, but it is also a common practice to create an ExtrinsicObject to use as the specificationObject attribute of a SpecificationLink for a ServiceBinding object (see Creating Services and Service Bindings). The ExtrinsicObject typically refers to a WSDL file.

  1. Create a SpecificationLink object.

  2. Store the WSDL document in the repository and create an ExtrinsicObject that refers to it. Set the extrinsic object’s type to WSDL and its MIME type to text/xml.

  3. Specify the extrinsic object as the specificationObject attribute of the SpecificationLink object.

  4. Add the SpecificationLink object to the ServiceBinding object.

  5. Add the ServiceBinding object to the Service object.

  6. Save the Service object.

After you create a Service and ServiceBinding, create a SpecificationLink:


SpecificationLink specLink = blcm.createSpecificationLink();
specLink.setName("Spec Link Name");
specLink.setDescription("Spec Link Description");

Create an ExtrinsicObject as described in Creating an Extrinsic Object. Use the ID for the WSDL concept and the text/xml MIME 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 ExtrinsicObject as the specification object for the SpecificationLink:


specLink.setSpecificationObject(eo);

Add the SpecificationLink to the ServiceBinding, then add the objects to their collections and save the services.


binding.addSpecificationLink(specLink);
serviceBindings.add(binding);
...

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 for Use in a Specification Link: Example

For an example of creating an extrinsic object to use in a specification link, see JAXRPublishService.java in the directory <INSTALL>/registry/samples/publish-service/src. This example publishes a WSDL file to the Registry.

ProcedureTo Run the JAXRPublishService Example

Steps
  1. Go to the directory <INSTALL>/registry/samples/publish-service.

  2. Type the following command:


    asant run