Java Reference
In-Depth Information
Consider the following bundle manifest snippet:
Bundle-ManifestVersion: 2
Bundle-SymbolicName: my.javax.servlet
Bundle-Version: 1.2.0
Export-Package: javax.servlet; javax.servlet.http; version="2.4.0"
This metadata exports the packages javax.servlet and javax.servlet.http with a
version attribute of the specified value. Additionally, the framework implicitly attaches
the bundle's symbolic name and version to all packages exported by a bundle. There-
fore, the previous metadata conceptually looks like this (also shown in figure 5.4):
Bundle-ManifestVersion: 2
Bundle-SymbolicName: my.javax.servlet
Bundle-Version: 1.2.0
Export-Package: javax.servlet; javax.servlet.http; version="2.4.0";
bundle-symbolic-name="my.javax.servlet"; bundle-version="1.2.0"
Although this is conceptually what is
happening, don't try to explicitly
specify the bundle-symbolic-name
and bundle-version attributes on
your exports. These attributes can
only be specified by the framework;
explicitly specifying them results in
an installation exception. With these
implicit attributes, it's possible for
you limit the framework's resolution
of an imported package to specific
bundles. For example, an importing
bundle may contain the following
snippet of metadata:
a)
b)
export
javax.servlet.http
version="2.4.0"
bundle-symbolic-name="my.javax.servlet"
bundle-version="1.2.0"
export
javax.servlet.http
version="2.4.0"
export
javax.servlet.http
version="2.4.0"
bundle-symbolic-name="my.javax.servlet"
bundle-version="1.2.0"
export
javax.servlet.http
version="2.4.0"
Figure 5.4 a) Your metadata declares explicit
attributes that are attached to your bundle's
exported packages, but b) the framework also
implicitly attaches attributes explicitly identifying
from which bundle the exports come.
Import-Package: javax.servlet; bundle-symbolic-name="my.javax.servlet";
bundle-version="[1.2.0,1.2.0]"
In this case, the importer limits its dependency resolution to a specific bundle by spec-
ifying its symbolic name with a precise version range. As you can imagine, this makes the
dependency a lot more brittle, but under certain circumstances this may be desired.
You may be thinking that implicit export attributes aren't completely necessary to
control how import dependencies are resolved. You're correct. You can also use good
old arbitrary attributes to achieve the same effect—just make sure your attribute name
and/or value are sufficiently unique. For example, you can modify your exporting
manifest like this:
Bundle-ManifestVersion: 2
Bundle-SymbolicName: javax.servlet
Bundle-Version: 1.2.0
Export-Package: javax.servlet; javax.servlet.http; version="2.4.0";
my-provider-attribute="my.value.scheme"
Search WWH ::




Custom Search