Java Reference
In-Depth Information
Table 15.1
Default behavior of HttpContext implementations
Method
Behavior
handleSecurity()
Implementation-specific authentication, although all known open
source implementations return true
getResource()
Maps requested resources to the content of the registering bundle
getMimeType()
Always returns null
OSGi R4.2 bundle tracker
The BundleTracker class provided by the OSGi R4.2 Compendium simplifies the
task of tracking bundles much as ServiceTracker simplifies tracking services. As
with ServiceTracker , which we introduced in chapter 4, BundleTracker supports
a filter pattern based on bundle states and a customizer object to fine-tune which
bundles are tracked and/or to create a customized object to track with the bundle.
Compared to the simple BundleTracker you created in chapter 3, the OSGi Bundle-
Tracker performs the same task, but does so in a more sophisticated way. In par-
ticular, it handles concurrency issues better and allows you to track bundles based
on desired states, instead of just the ACTIVE state as the simple implementation did.
Listing 15.2 Tracking HTTP resources in ResourceTracker
@Override
public Object addingBundle(Bundle bundle, BundleEvent event) {
ArrayList<String> aliases = new ArrayList<String>();
Checks whether bundle
specifies resources
String[] resources = findResources(bundle);
B
if (resources != null) {
HttpContext ctx = new ProxyHttpContext(bundle);
for (String p : resources) {
String[] split = p.split("\\s*=\\s*");
String alias = split[0];
String file = split.length == 1 ? split[0] : split[1];
try {
http.registerResources(alias, file, ctx);
aliases.add(alias);
} catch (NamespaceException e) {
e.printStackTrace();
}
}
}
return aliases.isEmpty()
? null : aliases.toArray(new String[aliases.size()]);
}
 
Search WWH ::




Custom Search