To use a resource exported by another bundle or located on the file system, you need to get the Resource Provider service, and use its methods.
Overview
For getting the value of String properties, use some of the variants of the getString method of the Resource Provider service.
For getting the value of file URL properties, use some of the variants of the getURL method.
If you want to use a property with dynamic value, you need to specify the arguments defined in the property value on using the getString/getURL method.
If you want the same language and other locale settings to be used within the entire system, use the setLocale(java.util.Locale locale) method. After that, you can get all necessary resources without having to specify a locale.
This source example illustrates getting the Resource Provider service and using it to take the values of several properties.
package test.resource.usage;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import com.prosyst.util.resprovider.ResourceProvider;
import java.util.Locale;
. . .
private ServiceReference refResourceProvider = null;
private ResourceProvider resProvider = null;
. . .
try {
//Getting the Resource Provider
refResourceProvider = bc.getServiceReference(ResourceProvider.class.getName());
if (refResourceProvider != null) {
resProvider = (ResourceProvider) bc.getService(refResourceProvider);
//Setting the current locale so we don't have to specify it
//each time we are getting a resource
resProvider.setLocale(Locale.GERMAN);
//Getting a String property
String value = resProvider.getString(2);
System.out.println("The value of the property with ID 2 is: " + value);
//Getting a dynamic property
String propWithArg = resProvider.getString("1",
new Object[] {"d:\\my_files\\my_file.del"});
System.out.println("The value of the property with ID 1 is " + propWithArg);
}
} catch (Exception e) {
e.printStackTrace();
}
. . .
There are two ways of specifying the resource types of interest for the importing bundle:
For example, the Resource-Type header may look like this:
Resource-Type: ICQ.oven, system