Java Reference
In-Depth Information
How do these uses relationships arise?
The example shows the typical way, which is
when the method signatures of classes in an
exported package expose classes from other
packages. This seems obvious, because the
used types are visible, but it isn't always the
case. You can also expose a type via a base
class that's downcast by the consumer. Because these types of uses relationships are
important, how do you capture them in the bundle metadata?
import
javax.servlet
version= "2.3.0"
HTTP
service
Uses
export
org.osgi.service.http
Figure 2.23 Bundle export uses import
USES DIRECTIVE A directive attached to exported packages whose value is a
comma-delimited list of packages exposed by the associated exported package.
The sidebar “ JAR file manifest syntax” in section 2.5 introduced the concept of a direc-
tive, but this is the first example of using one. Directives are additional metadata to alter
how the framework interprets the metadata to which the directives are attached. The syn-
tax for capturing directives is similar to arbitrary attributes. For example, the following
modified metadata for the HTTP service example shows how to use the uses directive:
Export-Package: org.osgi.service.http;
uses:="javax.servlet"; version="1.0.0"
Import-Package: javax.servlet; version="2.3.0"
Notice that directives use the := assignment syntax, but the ordering of the directives
and the attributes isn't important. This particular example indicates that org.osgi.
service.http uses javax.servlet . How exactly does the framework use this informa-
tion? uses relationships among packages act like grouping constraints for the packages.
In this example, the framework ensures that importers of org.osgi.service.http also
use the same javax.servlet used by the HTTP service implementation.
This captures the previously missing intra-bundle package dependency. In this spe-
cific case, the exported package expresses a uses relationship with an imported pack-
age, but it could use other exported packages. These sorts of uses relationships
constrain which choices the framework can make when resolving dependencies, which
is why they're also referred to as constraints . Abstractly, if package foo uses package bar ,
importers of foo are constrained to the same bar if they use bar at all. Figure 2.24
depicts how this would impact the original incremental dependency resolutions.
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
uses: = "javax.servlet"
export
javax.servlet
version= "2.3.0"
Figure 2.24 Uses constraints detect class-space inconsistencies, so the framework can determine
that it isn't possible to resolve the HTTP client bundle.
Search WWH ::




Custom Search