Java Reference
In-Depth Information
in the last section, isn't sufficient. Why not? Let's consider the simple
API
in the follow-
ing code snippet:
package org.osgi.service.http;
import javax.servlet.Servlet;
public interface HttpService {
void registerServlet(Sting alias, Servlet servlet, HttpContext ctx);
}
This is a snippet from an
API
you'll meet in chapter 15. The details of what it does are
unimportant at the moment; for now, you just need to know its method signature.
Let's assume the implementation of this
API
is packaged as a bundle containing the
org.osgi.service.http
package but not
javax.servlet
. This means it has some
metadata in its manifest like this:
Export-Package: org.osgi.service.http; version="1.0.0"
Import-Package: javax.servlet; version="2.3.0"
Let's assume the framework has the
HTTP
service bundle and a servlet library bundle
installed, as shown in figure 2.20. Given these two bundles, the framework makes the
only choice available, which is to select the version of
javax.servlet
provided by the
Servlet
API
bundle.
import
javax.servlet
version="2.3.0"
HTTP
service
Servlet
API
Figure 2.20
HTTP
service-dependency
resolution
export
org.osgi.service.http
export
javax.servlet
version="2.3.0"
Now, assume you install two more bundles into the framework: the Tomcat bundle
exporting version 2.4.0 of
javax.servlet
and a bundle containing a client for the
HTTP
service importing version 2.4.0 of
javax.servlet
. When the framework resolves
these two new bundles, it does so as shown in figure 2.21.
The
HTTP
client bundle imports
org.osgi.service.http
and version 2.4.0 of
javax.servlet
, which the framework resolves to the
HTTP
service bundle and the
To m c a t b u n d l e , r e s p e c t i v e l y. I t s e e m s t h a t e v e r y t h i n g i s f i n e : a l l b u n d l e s h a v e t h e i r
dependencies resolved, right? Not quite. There's an issue with these choices for
dependency resolution—can you see what it is?
import
javax.servlet
version="2.4.0"
import
javax.servlet
version="2.3.0"
import
org.osgi.service.http
Tomcat
HTTP
client
HTTP
service
Servlet
API
export
javax.servlet
version="2.4.0"
export
org.osgi.service.http
export
javax.servlet
version="2.3.0"
Figure 2.21
Subsequent HTTP client-dependency resolution