Java Reference
In-Depth Information
code visible to it from its bundle class path. Be aware that importing a package doesn't
import its subpackages; remember, there's no relationship among nested packages. If
your bundle needs access to org.foo.shape and org.foo.shape.other , it must
import both packages as comma-separated targets, like this:
Import-Package: org.foo.shape,org.foo.shape.other
Your bundles can import any number of packages by listing them on Import-
Package and separating them using commas. It's not uncommon in larger projects
for the Import-Package declaration to grow large (although you should strive to
minimize this).
Sometimes, you'll want to narrow your bundle's package dependencies. Recall how
Export-Package declarations can include attributes to differentiate a bundle's
exported packages. You can use these export attributes as matching attributes when
importing packages. For example, we previously discussed the following export and
associated attribute:
Export-Package: org.foo.shape; org.foo.other; vendor="Manning"
A bundle with this metadata exports the two packages with the associated vendor attri-
bute and value. It's possible to narrow your bundle's imported packages using the
same matching attribute:
Import-Package: org.foo.shape; vendor="Manning"
The bundle with this metadata is declaring a dependency on the package
org.foo.shape with a vendor attribute matching the "Manning" value. The attributes
attached to Export-Package declarations define the attribute's value, whereas attri-
butes attached to Import-Package declarations define the value to match; essentially,
they act like a filter. The details of how imports and exports are matched and filtered
is something we'll defer until section 2.7. For now, it's sufficient to understand that
attributes attached to imported packages are matched against the attributes attached
to exported packages.
For arbitrary attributes, OSG i only supports equality matching. In other words, it
either matches the specified value or it doesn't. You learned about one non-arbitrary
attribute when we discussed Export-Package and the version attribute. Because this
attribute is defined by the OSG i specification, more flexible matching is supported.
This is an area where OSG i excels. In the simple case, it treats a value as an infinite
range starting from the specified version number. For example:
Import-Package: org.osgi.framework; version="1.3.0"
This statement declares an import for package org.osgi.framework for the version
range of 1.3.0 to infinity, inclusive. This simple form of specifying an imported pack-
age version range implies an expectation that future versions of org.osgi.framework
will always be backward compatible with the lower version. In some cases, such as spec-
ification packages, it's reasonable to expect backward compatibility. In situations
where you wish to limit your assumptions about backward compatibility, OSG i allows
Search WWH ::




Custom Search