Java Reference
In-Depth Information
to use different versions of the same XML parser. If you specify uses constraints too
broadly, this isn't possible. Accurate uses constraints are important, but luckily tools
exist for generating them for exported packages.
OK ! You made it through the most difficult part and survived. Don't worry if you
didn't understand every detail, because some of it may make more sense after you
have more experience creating and using bundles. Let's turn our attention back to
the paint program to review why you did all this in the first place.
2.8
Reviewing the benefits of the modular paint program
Even though the amount of work required to create the modular version of the paint
program wasn't great, it was still more effort than if you left the paint program as it
was. Why did you create this modular version? Table 2.3 lists some of the benefits.
Table 2.3
Benefits of modularization in the paint program
Benefit
Description
Logical boundary
enforcement
Yo u c a n ke e p t h e i m p l e m e n t a t i o n d e t a i l s p r i v a t e , b e c a u s e y o u 'r e o n l y e x p o s i n g w h a t
you want to expose in the org.foo.shape public API package.
Reuse
improvement
The code is more reusable because you explicitly declare what each bundle
depends on via Import-Package statements. This means you know what you
need when using the code in different projects.
Configuration
verification
Yo u n o l o n g e r h av e t o g u e s s i f y o u 'v e d e p l oy e d t h e a p p l i c a t i o n p r o p e r l y, b e c a u s e O S G i
verifies whether all needed pieces are present when launching the application.
Version
verification
Similar to configuration verification, OSGi also verifies whether you have the correct
versions of all the application pieces when launching the application.
Configuration
flexibility
Yo u c a n m o r e e a s i l y t a i l o r t h e a p p l i c a t i o n t o d i f f e r e n t s c e n a r i o s by c r e a t i n g n ew c o n -
figurations. Think of this as paint program a la carte.
Some of these benefits are more obvious than others. Some you can demonstrate eas-
ily. For example, assume you forgot to deploy the shape API bundle in the launcher,
which you can simulate by deleting bundles/shape-2.0.jar before launching the paint
program. If you do this, you'll see an exception like this:
org.osgi.framework.BundleException: Unresolved constraint in bundle 1:
package; (&(package=org.foo.shape)(version>=2.0.0)(!(version>=3.0.0)))
The exact syntax of this message will become familiar to you when you read chapter 4;
but ignoring the syntax, it tells you the application is missing the org.foo.shape pack-
age, which is provided by the API bundle. Due to the on-demand nature of Java class
loading, such errors are typically only discovered during application execution when
the missing classes are used. With OSG i, you can immediately discover such issues with
missing bundles or incorrect versions. In addition to detecting errors, let's look at how
OSG i modularity helps you create different configurations of the application.
 
Search WWH ::




Custom Search