Java Reference
In-Depth Information
In this case, the importer needs to specify the corresponding attribute name and
value on its Import-Package declaration. There's an advantage to using this approach
if you're in a situation where you must have brittle dependencies: it's not as brittle as
implicit attributes. You're able to refactor your exporting bundle without impacting
importing bundles, because these attribute values aren't tied to the containing bun-
dle. On the downside, arbitrary attributes are easier for other bundles to imitate, even
though there are no guarantees either way.
In short, it's best to avoid brittle dependencies, but at least now you understand
how both implicit and arbitrary export attributes allow importing bundles to have a
say in how their dependencies are resolved. Thinking about the flip side, it may also
occasionally be necessary for exporting bundles to have some control over how
importing bundles are resolved. Mandatory attributes can help you here.
5.1.3
Mandatory export attributes
The OSG i framework promotes arbitrary package sharing among bundles. As we dis-
cussed in the last subsection, in some situations this isn't desired.
Up until now, the importing bundle appears to be completely in control of this sit-
uation, because it declares the matching constraints for dependency resolution. For
example, consider the following metadata snippet for importing a package:
Import-Package: javax.servlet; version="[2.4.0,2.5.0)"
Such an import declaration matches any provider of javax.servlet as long as it's in
the specified version range. Now consider the following metadata snippet for export-
ing a package in another bundle:
Export-Package: javax.servlet; version="2.4.1"; private="true"
Will the imported package match this exported package? Yes, it will, as shown in fig-
ure 5.5. The name of the attribute, private , may have tricked you into thinking other-
wise, but it's just an arbitrary attribute and has no meaning (if it did have meaning to
the framework, it would likely be a directive, not an attribute). When it comes to
matching an import to an export, only the attributes mentioned on the import decla-
ration are compared against the attributes on the export declaration. In this case, the
import mentions the package name and version range, which match the exported
package's name and version. The private
attribute isn't even considered.
In some situations, you may wish to have
a little more control in your exporting bun-
dle. For example, maybe you're exposing a
package containing a nonpublic API , or
you've modified a common open source
library in an incompatible way, and you don't
want unaware bundles to inadvertently
match your exported packages. The OSG i
specification provides this capability using
export
javax.servlet
version="2.4.0"
private="true"
A
B
import
javax.servlet
version="[2.4.0, 2.5.0)"
Figure 5.5 Only attributes mentioned in the
imported package declaration impact
dependency resolution matching. Any
attributes mentioned only in the exported
package declaration are ignored.
Search WWH ::




Custom Search