Previous Topic

Next Topic

Book Contents

Book Index

Exporting Resources

If a bundle needs to export resources for sharing with other bundles in the OSGi framework, it must describe the exported resources in an XML file with specified syntax.

Overview

There may be more than one resource definition in the same XML file.

The DTD of the resource provider XML is as follows:

  <!DOCTYPE resource-provider [
  <!ELEMENT resource-provider (resource)+>
  <!ELEMENT resource (type, file, range?)>
  <!ELEMENT type (#PCDATA)>
  <!ELEMENT file (#PCDATA)>
  <!ELEMENT range (#PCDATA)>
]>

An example of such an XML description file can describe the exported resources.

    <resource-provider>
      <resource>
        <type>ICQ.oven</type>
        <file>/resources/oven</file>
        <range>1:30</range>
      </resource>

      <resource>
        <type>ICQ.dishwasher</type>
        <file>/resources/dishwasher</file>
        <range>1:5</range>
        <range>20:30</range>
      </resource>
    </resource-provider>  

The location of the XML file must be included in the bundle manifest as a value of the Resource-Config header. For example:

Resource-Config: test/resources/oven.xml;

For example, the .properties file describing the resources for the US English locale may be named settings_EN_US.properties, and may look like this:

2 = First line
3 = Second line

1 = The file with location {0} will be deleted. Are you sure?

If a bundle wishes to provide other bundles or itself with resources located outside its JAR file, i.e. on the local file system, it should get the Resource Provider service and use its setResources(String type, String filename) method. It takes as parameters the name of the resource type and the path to the directory on the file system containing the external resources. The value of the filename parameter must be <local_file_system_path>/<common_resource_name>.

If a bundle no longer wishes to use such external resources, it should use the removeResources(String type) method of the Resource Provider. The method takes as parameter the resource type of the external resource.