felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r865657 [22/27] - in /websites/staging/felix/trunk/content: ./ documentation/ documentation/community/ documentation/development/ documentation/faqs/ documentation/subprojects/ documentation/subprojects/apache-felix-commons/ documentation/s...
Date Fri, 14 Jun 2013 14:11:48 GMT
Modified: websites/staging/felix/trunk/content/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-6.html
==============================================================================
--- websites/staging/felix/trunk/content/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-6.html (original)
+++ websites/staging/felix/trunk/content/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-6.html Fri Jun 14 14:11:44 2013
@@ -49,8 +49,7 @@
 <a href="http://www.apache.org/">asf</a>  <br />
 <a href="http://www.apache.org/security/">security</a>  <br />
 <a href="http://www.apache.org/foundation/sponsorship.html">sponsorship</a>  <br />
-<a href="http://www.apache.org/foundation/thanks.html">sponsors</a>  <br />
-</p>
+<a href="http://www.apache.org/foundation/thanks.html">sponsors</a>    </p>
 <iframe
     src="http://www.apache.org/ads/button.html"
     style="border-width:0; float: left"
@@ -77,281 +76,281 @@
       <h1 id="example-6-spell-checker-service-bundle">Example 6 - Spell Checker Service Bundle</h1>
 <p><em>(This example should be rewritten to use the Service Tracker.)</em></p>
 <p>In this example, we complicate things further by defining a new service that uses an arbitrary number of dictionary services to perform its function. More precisely, we define a spell checker service will aggregate all dictionary services and provide another service that allows us to spell check passages using our underlying dictionary services to verify the spelling of words. Our bundle will only provide the spell checker service if there is at least one dictionary service available. First, we will start by defining the spell checker service interface in a file called <code>SpellChecker.java</code>:</p>
-<div class="codehilite"><pre><span class="o">/*</span>
- <span class="o">*</span> <span class="n">Apache</span> <span class="n">Felix</span> <span class="n">OSGi</span> <span class="n">tutorial</span><span class="o">.</span>
-<span class="o">**/</span>
-
-<span class="nb">package</span> <span class="n">tutorial</span><span class="o">.</span><span class="n">example6</span><span class="o">.</span><span class="n">service</span><span class="p">;</span>
-
-<span class="o">/**</span>
- <span class="o">*</span> <span class="n">A</span> <span class="n">simple</span> <span class="n">service</span> <span class="n">interface</span> <span class="n">that</span> <span class="n">defines</span> <span class="n">a</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span><span class="o">.</span>
- <span class="o">*</span> <span class="n">A</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span> <span class="n">checks</span> <span class="n">the</span> <span class="n">spelling</span> <span class="n">of</span> <span class="n">all</span> <span class="n">words</span> <span class="n">in</span> <span class="n">a</span>
- <span class="o">*</span> <span class="n">given</span> <span class="n">passage</span><span class="o">.</span> <span class="n">A</span> <span class="n">passage</span> <span class="n">is</span> <span class="n">any</span> <span class="n">number</span> <span class="n">of</span> <span class="n">words</span> <span class="n">separated</span> <span class="n">by</span>
- <span class="o">*</span> <span class="n">a</span> <span class="n">space</span> <span class="n">character</span> <span class="ow">and</span> <span class="n">the</span> <span class="n">following</span> <span class="n">punctuation</span> <span class="n">marks:</span> <span class="n">comma</span><span class="p">,</span>
- <span class="o">*</span> <span class="n">period</span><span class="p">,</span> <span class="n">exclamation</span> <span class="n">mark</span><span class="p">,</span> <span class="n">question</span> <span class="n">mark</span><span class="p">,</span> <span class="n">semi</span><span class="o">-</span><span class="n">colon</span><span class="p">,</span> <span class="ow">and</span> <span class="n">colon</span><span class="o">.</span>
-<span class="o">**/</span>
-<span class="n">public</span> <span class="n">interface</span> <span class="n">SpellChecker</span>
+<div class="codehilite"><pre><span class="cm">/*</span>
+<span class="cm"> * Apache Felix OSGi tutorial.</span>
+<span class="cm">**/</span>
+
+<span class="kn">package</span> <span class="n">tutorial</span><span class="p">.</span><span class="n">example6</span><span class="p">.</span><span class="n">service</span><span class="p">;</span>
+
+<span class="cm">/**</span>
+<span class="cm"> * A simple service interface that defines a spell checker service.</span>
+<span class="cm"> * A spell checker service checks the spelling of all words in a</span>
+<span class="cm"> * given passage. A passage is any number of words separated by</span>
+<span class="cm"> * a space character and the following punctuation marks: comma,</span>
+<span class="cm"> * period, exclamation mark, question mark, semi-colon, and colon.</span>
+<span class="cm">**/</span>
+<span class="n">public</span> <span class="k">interface</span> <span class="n">SpellChecker</span>
 <span class="p">{</span>
-    <span class="o">/**</span>
-     <span class="o">*</span> <span class="n">Checks</span> <span class="n">a</span> <span class="n">given</span> <span class="n">passage</span> <span class="k">for</span> <span class="n">spelling</span> <span class="n">errors</span><span class="o">.</span> <span class="n">A</span> <span class="n">passage</span> <span class="n">is</span> <span class="n">any</span>
-     <span class="o">*</span> <span class="n">number</span> <span class="n">of</span> <span class="n">words</span> <span class="n">separated</span> <span class="n">by</span> <span class="n">a</span> <span class="n">space</span> <span class="ow">and</span> <span class="n">any</span> <span class="n">of</span> <span class="n">the</span> <span class="n">following</span>
-     <span class="o">*</span> <span class="n">punctuation</span> <span class="n">marks:</span> <span class="n">comma</span> <span class="p">(,),</span> <span class="n">period</span> <span class="p">(</span><span class="o">.</span><span class="p">),</span> <span class="n">exclamation</span> <span class="n">mark</span> <span class="p">(</span><span class="o">!</span><span class="p">),</span>
-     <span class="o">*</span> <span class="n">question</span> <span class="n">mark</span> <span class="p">(?),</span> <span class="n">semi</span><span class="o">-</span><span class="n">colon</span> <span class="p">(;),</span> <span class="ow">and</span> <span class="n">colon</span><span class="p">(:)</span><span class="o">.</span>
-     <span class="o">*</span> <span class="nv">@param</span> <span class="n">passage</span> <span class="n">the</span> <span class="n">passage</span> <span class="n">to</span> <span class="n">spell</span> <span class="n">check</span><span class="o">.</span>
-     <span class="o">*</span> <span class="nv">@return</span> <span class="n">An</span> <span class="n">array</span> <span class="n">of</span> <span class="n">misspelled</span> <span class="n">words</span> <span class="ow">or</span> <span class="n">null</span> <span class="k">if</span> <span class="nb">no</span>
-     <span class="o">*</span>         <span class="n">words</span> <span class="n">are</span> <span class="n">misspelled</span><span class="o">.</span>
-    <span class="o">**/</span>
-    <span class="n">public</span> <span class="n">String</span><span class="o">[]</span> <span class="n">check</span><span class="p">(</span><span class="n">String</span> <span class="n">passage</span><span class="p">);</span>
+    <span class="cm">/**</span>
+<span class="cm">     * Checks a given passage for spelling errors. A passage is any</span>
+<span class="cm">     * number of words separated by a space and any of the following</span>
+<span class="cm">     * punctuation marks: comma (,), period (.), exclamation mark (!),</span>
+<span class="cm">     * question mark (?), semi-colon (;), and colon(:).</span>
+<span class="cm">     * @param passage the passage to spell check.</span>
+<span class="cm">     * @return An array of misspelled words or null if no</span>
+<span class="cm">     *         words are misspelled.</span>
+<span class="cm">    **/</span>
+    <span class="n">public</span> <span class="n">String</span><span class="p">[]</span> <span class="n">check</span><span class="p">(</span><span class="n">String</span> <span class="n">passage</span><span class="p">);</span>
 <span class="p">}</span>
 </pre></div>
 
 
 <p>The service interface is quite simple, with only one method that needs to be implemented. Notice that we put the service interface in the package <code>tutorial.example6.service</code>, instead of just putting it in <code>tutorial.example6</code>. We did this because we need to share the interface definition with other bundles, therefore it is better to separate service interfaces that need to be shared from code that does not need to be shared. Such an approach ensures a strong separation between interface and implementation.</p>
 <p>In the following bundle source code, the bundle needs to create a complete list of all dictionary services; this is somewhat tricky and must be done carefully. First, the bundle uses its bundle context to register itself as a service event listener, then it queries for all currently available dictionary services. After creating the list of dictionary services, the bundle then registers its spell checker service if and only if there is at least one dictionary service available. These actions must be performed in a synchronized block to avoid interference from service events. Additionally, since the bundle is monitoring the dynamic availability of the dictionary services, when the number of dictionary services falls to zero or increases from zero, the bundle must unregister and register its spell checker service, respectively. We implement our bundle in a file called <code>Activator.java</code>:</p>
-<div class="codehilite"><pre><span class="o">/*</span>
- <span class="o">*</span> <span class="n">Apache</span> <span class="n">Felix</span> <span class="n">OSGi</span> <span class="n">tutorial</span><span class="o">.</span>
-<span class="o">**/</span>
-
-<span class="nb">package</span> <span class="n">tutorial</span><span class="o">.</span><span class="n">example6</span><span class="p">;</span>
-
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">BufferedReader</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">InputStreamReader</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">IOException</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="n">ArrayList</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="n">HashMap</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="n">StringTokenizer</span><span class="p">;</span>
-
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">osgi</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">BundleActivator</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">osgi</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">BundleContext</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">osgi</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">ServiceRegistration</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">osgi</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">ServiceReference</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">osgi</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">ServiceListener</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">osgi</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">ServiceEvent</span><span class="p">;</span>
-
-<span class="nb">import</span> <span class="n">tutorial</span><span class="o">.</span><span class="n">example2</span><span class="o">.</span><span class="n">service</span><span class="o">.</span><span class="n">DictionaryService</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">tutorial</span><span class="o">.</span><span class="n">example6</span><span class="o">.</span><span class="n">service</span><span class="o">.</span><span class="n">SpellChecker</span><span class="p">;</span>
-
-<span class="o">/**</span>
- <span class="o">*</span> <span class="n">This</span> <span class="n">class</span> <span class="n">implements</span> <span class="n">a</span> <span class="n">bundle</span> <span class="n">that</span> <span class="n">implements</span> <span class="n">a</span> <span class="n">spell</span>
- <span class="o">*</span> <span class="n">checker</span> <span class="n">service</span><span class="o">.</span> <span class="n">The</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span> <span class="n">uses</span> <span class="n">all</span> <span class="n">available</span>
- <span class="o">*</span> <span class="n">dictionary</span> <span class="n">services</span> <span class="n">to</span> <span class="n">check</span> <span class="k">for</span> <span class="n">the</span> <span class="n">existence</span> <span class="n">of</span> <span class="n">words</span> <span class="n">in</span>
- <span class="o">*</span> <span class="n">a</span> <span class="n">given</span> <span class="n">sentence</span><span class="o">.</span> <span class="n">This</span> <span class="n">bundle</span> <span class="ow">not</span> <span class="n">only</span> <span class="n">monitors</span> <span class="n">the</span> <span class="n">dynamic</span>
- <span class="o">*</span> <span class="n">availability</span> <span class="n">of</span> <span class="n">dictionary</span> <span class="n">services</span><span class="p">,</span> <span class="n">but</span> <span class="n">it</span> <span class="n">manages</span> <span class="n">the</span>
- <span class="o">*</span> <span class="n">aggregation</span> <span class="n">of</span> <span class="n">all</span> <span class="n">available</span> <span class="n">dictionary</span> <span class="n">services</span> <span class="n">as</span> <span class="n">they</span>
- <span class="o">*</span> <span class="n">arrive</span> <span class="ow">and</span> <span class="n">depart</span><span class="o">.</span> <span class="n">The</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span> <span class="n">is</span> <span class="n">only</span> <span class="n">registered</span>
- <span class="o">*</span> <span class="k">if</span> <span class="n">there</span> <span class="n">are</span> <span class="n">dictionary</span> <span class="n">services</span> <span class="n">available</span><span class="p">,</span> <span class="n">thus</span> <span class="n">the</span> <span class="n">spell</span>
- <span class="o">*</span> <span class="n">checker</span> <span class="n">service</span> <span class="n">will</span> <span class="n">appear</span> <span class="ow">and</span> <span class="n">disappear</span> <span class="n">as</span> <span class="n">dictionary</span>
- <span class="o">*</span> <span class="n">services</span> <span class="n">appear</span> <span class="ow">and</span> <span class="n">disappear</span><span class="p">,</span> <span class="n">respectively</span><span class="o">.</span>
-<span class="o">**/</span>
-<span class="n">public</span> <span class="n">class</span> <span class="n">Activator</span> <span class="n">implements</span> <span class="n">BundleActivator</span><span class="p">,</span> <span class="n">ServiceListener</span>
+<div class="codehilite"><pre><span class="cm">/*</span>
+<span class="cm"> * Apache Felix OSGi tutorial.</span>
+<span class="cm">**/</span>
+
+<span class="kn">package</span> <span class="n">tutorial</span><span class="p">.</span><span class="n">example6</span><span class="p">;</span>
+
+<span class="kn">import</span> <span class="nn">java</span><span class="p">.</span><span class="n">io</span><span class="p">.</span><span class="n">BufferedReader</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">java</span><span class="p">.</span><span class="n">io</span><span class="p">.</span><span class="n">InputStreamReader</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">java</span><span class="p">.</span><span class="n">io</span><span class="p">.</span><span class="n">IOException</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">java</span><span class="p">.</span><span class="n">util</span><span class="p">.</span><span class="n">ArrayList</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">java</span><span class="p">.</span><span class="n">util</span><span class="p">.</span><span class="n">HashMap</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">java</span><span class="p">.</span><span class="n">util</span><span class="p">.</span><span class="n">StringTokenizer</span><span class="p">;</span>
+
+<span class="kn">import</span> <span class="nn">org</span><span class="p">.</span><span class="n">osgi</span><span class="p">.</span><span class="n">framework</span><span class="p">.</span><span class="n">BundleActivator</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">org</span><span class="p">.</span><span class="n">osgi</span><span class="p">.</span><span class="n">framework</span><span class="p">.</span><span class="n">BundleContext</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">org</span><span class="p">.</span><span class="n">osgi</span><span class="p">.</span><span class="n">framework</span><span class="p">.</span><span class="n">ServiceRegistration</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">org</span><span class="p">.</span><span class="n">osgi</span><span class="p">.</span><span class="n">framework</span><span class="p">.</span><span class="n">ServiceReference</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">org</span><span class="p">.</span><span class="n">osgi</span><span class="p">.</span><span class="n">framework</span><span class="p">.</span><span class="n">ServiceListener</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">org</span><span class="p">.</span><span class="n">osgi</span><span class="p">.</span><span class="n">framework</span><span class="p">.</span><span class="n">ServiceEvent</span><span class="p">;</span>
+
+<span class="kn">import</span> <span class="nn">tutorial</span><span class="p">.</span><span class="n">example2</span><span class="p">.</span><span class="n">service</span><span class="p">.</span><span class="n">DictionaryService</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">tutorial</span><span class="p">.</span><span class="n">example6</span><span class="p">.</span><span class="n">service</span><span class="p">.</span><span class="n">SpellChecker</span><span class="p">;</span>
+
+<span class="cm">/**</span>
+<span class="cm"> * This class implements a bundle that implements a spell</span>
+<span class="cm"> * checker service. The spell checker service uses all available</span>
+<span class="cm"> * dictionary services to check for the existence of words in</span>
+<span class="cm"> * a given sentence. This bundle not only monitors the dynamic</span>
+<span class="cm"> * availability of dictionary services, but it manages the</span>
+<span class="cm"> * aggregation of all available dictionary services as they</span>
+<span class="cm"> * arrive and depart. The spell checker service is only registered</span>
+<span class="cm"> * if there are dictionary services available, thus the spell</span>
+<span class="cm"> * checker service will appear and disappear as dictionary</span>
+<span class="cm"> * services appear and disappear, respectively.</span>
+<span class="cm">**/</span>
+<span class="n">public</span> <span class="k">class</span> <span class="n">Activator</span> <span class="n">implements</span> <span class="n">BundleActivator</span><span class="p">,</span> <span class="n">ServiceListener</span>
 <span class="p">{</span>
-    <span class="sr">//</span> <span class="n">Bundle</span><span class="err">&#39;</span><span class="n">s</span> <span class="n">context</span><span class="o">.</span>
-    <span class="n">private</span> <span class="n">BundleContext</span> <span class="n">m_context</span> <span class="o">=</span> <span class="n">null</span><span class="p">;</span>
-    <span class="sr">//</span> <span class="n">List</span> <span class="n">of</span> <span class="n">available</span> <span class="n">dictionary</span> <span class="n">service</span> <span class="n">references</span><span class="o">.</span>
+    <span class="c1">// Bundle&#39;s context.</span>
+    <span class="n">private</span> <span class="n">BundleContext</span> <span class="n">m_context</span> <span class="o">=</span> <span class="k">null</span><span class="p">;</span>
+    <span class="c1">// List of available dictionary service references.</span>
     <span class="n">private</span> <span class="n">ArrayList</span> <span class="n">m_refList</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ArrayList</span><span class="p">();</span>
-    <span class="sr">//</span> <span class="n">Maps</span> <span class="n">service</span> <span class="n">references</span> <span class="n">to</span> <span class="n">service</span> <span class="n">objects</span><span class="o">.</span>
+    <span class="c1">// Maps service references to service objects.</span>
     <span class="n">private</span> <span class="n">HashMap</span> <span class="n">m_refToObjMap</span> <span class="o">=</span> <span class="k">new</span> <span class="n">HashMap</span><span class="p">();</span>
-    <span class="sr">//</span> <span class="n">The</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span> <span class="n">registration</span><span class="o">.</span>
-    <span class="n">private</span> <span class="n">ServiceRegistration</span> <span class="n">m_reg</span> <span class="o">=</span> <span class="n">null</span><span class="p">;</span>
+    <span class="c1">// The spell checker service registration.</span>
+    <span class="n">private</span> <span class="n">ServiceRegistration</span> <span class="n">m_reg</span> <span class="o">=</span> <span class="k">null</span><span class="p">;</span>
 
-    <span class="o">/**</span>
-     <span class="o">*</span> <span class="n">Implements</span> <span class="n">BundleActivator</span><span class="o">.</span><span class="n">start</span><span class="p">()</span><span class="o">.</span> <span class="n">Adds</span> <span class="n">itself</span>
-     <span class="o">*</span> <span class="n">as</span> <span class="n">a</span> <span class="n">service</span> <span class="n">listener</span> <span class="ow">and</span> <span class="n">queries</span> <span class="k">for</span> <span class="n">all</span> <span class="n">currently</span>
-     <span class="o">*</span> <span class="n">available</span> <span class="n">dictionary</span> <span class="n">services</span><span class="o">.</span> <span class="n">Any</span> <span class="n">available</span> <span class="n">dictionary</span>
-     <span class="o">*</span> <span class="n">services</span> <span class="n">are</span> <span class="n">added</span> <span class="n">to</span> <span class="n">the</span> <span class="n">service</span> <span class="n">reference</span> <span class="n">list</span><span class="o">.</span> <span class="n">If</span>
-     <span class="o">*</span> <span class="n">dictionary</span> <span class="n">services</span> <span class="n">are</span> <span class="n">found</span><span class="p">,</span> <span class="k">then</span> <span class="n">the</span> <span class="n">spell</span> <span class="n">checker</span>
-     <span class="o">*</span> <span class="n">service</span> <span class="n">is</span> <span class="n">registered</span><span class="o">.</span>
-     <span class="o">*</span> <span class="nv">@param</span> <span class="n">context</span> <span class="n">the</span> <span class="n">framework</span> <span class="n">context</span> <span class="k">for</span> <span class="n">the</span> <span class="n">bundle</span><span class="o">.</span>
-    <span class="o">**/</span>
-    <span class="n">public</span> <span class="n">void</span> <span class="n">start</span><span class="p">(</span><span class="n">BundleContext</span> <span class="n">context</span><span class="p">)</span> <span class="n">throws</span> <span class="n">Exception</span>
+    <span class="cm">/**</span>
+<span class="cm">     * Implements BundleActivator.start(). Adds itself</span>
+<span class="cm">     * as a service listener and queries for all currently</span>
+<span class="cm">     * available dictionary services. Any available dictionary</span>
+<span class="cm">     * services are added to the service reference list. If</span>
+<span class="cm">     * dictionary services are found, then the spell checker</span>
+<span class="cm">     * service is registered.</span>
+<span class="cm">     * @param context the framework context for the bundle.</span>
+<span class="cm">    **/</span>
+    <span class="n">public</span> <span class="k">void</span> <span class="n">start</span><span class="p">(</span><span class="n">BundleContext</span> <span class="k">context</span><span class="p">)</span> <span class="n">throws</span> <span class="n">Exception</span>
     <span class="p">{</span>
-        <span class="n">m_context</span> <span class="o">=</span> <span class="n">context</span><span class="p">;</span>
+        <span class="n">m_context</span> <span class="o">=</span> <span class="k">context</span><span class="p">;</span>
 
         <span class="n">synchronized</span> <span class="p">(</span><span class="n">m_refList</span><span class="p">)</span>
         <span class="p">{</span>
-            <span class="sr">//</span> <span class="n">Listen</span> <span class="k">for</span> <span class="n">events</span> <span class="n">pertaining</span> <span class="n">to</span> <span class="n">dictionary</span> <span class="n">services</span><span class="o">.</span>
-            <span class="n">m_context</span><span class="o">.</span><span class="n">addServiceListener</span><span class="p">(</span><span class="n">this</span><span class="p">,</span>
-                <span class="s">&quot;(&amp;(objectClass=&quot;</span> <span class="o">+</span> <span class="n">DictionaryService</span><span class="o">.</span><span class="n">class</span><span class="o">.</span><span class="n">getName</span><span class="p">()</span> <span class="o">+</span> <span class="s">&quot;)&quot;</span> <span class="o">+</span>
+            <span class="c1">// Listen for events pertaining to dictionary services.</span>
+            <span class="n">m_context</span><span class="p">.</span><span class="n">addServiceListener</span><span class="p">(</span><span class="k">this</span><span class="p">,</span>
+                <span class="s">&quot;(&amp;(objectClass=&quot;</span> <span class="o">+</span> <span class="n">DictionaryService</span><span class="p">.</span><span class="k">class</span><span class="p">.</span><span class="n">getName</span><span class="p">()</span> <span class="o">+</span> <span class="s">&quot;)&quot;</span> <span class="o">+</span>
                 <span class="s">&quot;(Language=*))&quot;</span><span class="p">);</span>
 
-            <span class="sr">//</span> <span class="n">Query</span> <span class="k">for</span> <span class="n">all</span> <span class="n">dictionary</span> <span class="n">services</span><span class="o">.</span>
-            <span class="n">ServiceReference</span><span class="o">[]</span> <span class="n">refs</span> <span class="o">=</span> <span class="n">m_context</span><span class="o">.</span><span class="n">getServiceReferences</span><span class="p">(</span>
-                <span class="n">DictionaryService</span><span class="o">.</span><span class="n">class</span><span class="o">.</span><span class="n">getName</span><span class="p">(),</span> <span class="s">&quot;(Language=*)&quot;</span><span class="p">);</span>
+            <span class="c1">// Query for all dictionary services.</span>
+            <span class="n">ServiceReference</span><span class="p">[]</span> <span class="n">refs</span> <span class="o">=</span> <span class="n">m_context</span><span class="p">.</span><span class="n">getServiceReferences</span><span class="p">(</span>
+                <span class="n">DictionaryService</span><span class="p">.</span><span class="k">class</span><span class="p">.</span><span class="n">getName</span><span class="p">(),</span> <span class="s">&quot;(Language=*)&quot;</span><span class="p">);</span>
 
-            <span class="sr">//</span> <span class="n">Add</span> <span class="n">any</span> <span class="n">dictionaries</span> <span class="n">to</span> <span class="n">the</span> <span class="n">service</span> <span class="n">reference</span> <span class="n">list</span><span class="o">.</span>
-            <span class="k">if</span> <span class="p">(</span><span class="n">refs</span> <span class="o">!=</span> <span class="n">null</span><span class="p">)</span>
+            <span class="c1">// Add any dictionaries to the service reference list.</span>
+            <span class="k">if</span> <span class="p">(</span><span class="n">refs</span> <span class="o">!=</span> <span class="k">null</span><span class="p">)</span>
             <span class="p">{</span>
-                <span class="k">for</span> <span class="p">(</span><span class="nb">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">refs</span><span class="o">.</span><span class="nb">length</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
+                <span class="k">for</span> <span class="p">(</span><span class="k">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mh">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">refs</span><span class="p">.</span><span class="n">length</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
                 <span class="p">{</span>
-                    <span class="sr">//</span> <span class="n">Get</span> <span class="n">the</span> <span class="n">service</span> <span class="n">object</span><span class="o">.</span>
-                    <span class="n">Object</span> <span class="n">service</span> <span class="o">=</span> <span class="n">m_context</span><span class="o">.</span><span class="n">getService</span><span class="p">(</span><span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
+                    <span class="c1">// Get the service object.</span>
+                    <span class="n">Object</span> <span class="n">service</span> <span class="o">=</span> <span class="n">m_context</span><span class="p">.</span><span class="n">getService</span><span class="p">(</span><span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
 
-                    <span class="sr">//</span> <span class="n">Make</span> <span class="n">that</span> <span class="n">the</span> <span class="n">service</span> <span class="n">is</span> <span class="ow">not</span> <span class="n">being</span> <span class="n">duplicated</span><span class="o">.</span>
-                    <span class="k">if</span> <span class="p">((</span><span class="n">service</span> <span class="o">!=</span> <span class="n">null</span><span class="p">)</span> <span class="o">&amp;&amp;</span>
-                        <span class="p">(</span><span class="n">m_refToObjMap</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">==</span> <span class="n">null</span><span class="p">))</span>
+                    <span class="c1">// Make that the service is not being duplicated.</span>
+                    <span class="k">if</span> <span class="p">((</span><span class="n">service</span> <span class="o">!=</span> <span class="k">null</span><span class="p">)</span> <span class="o">&amp;&amp;</span>
+                        <span class="p">(</span><span class="n">m_refToObjMap</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">==</span> <span class="k">null</span><span class="p">))</span>
                     <span class="p">{</span>
-                        <span class="sr">//</span> <span class="n">Add</span> <span class="n">to</span> <span class="n">the</span> <span class="n">reference</span> <span class="n">list</span><span class="o">.</span>
-                        <span class="n">m_refList</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
-                        <span class="sr">//</span> <span class="n">Map</span> <span class="n">reference</span> <span class="n">to</span> <span class="n">service</span> <span class="n">object</span> <span class="k">for</span> <span class="n">easy</span> <span class="n">look</span> <span class="n">up</span><span class="o">.</span>
-                        <span class="n">m_refToObjMap</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">service</span><span class="p">);</span>
+                        <span class="c1">// Add to the reference list.</span>
+                        <span class="n">m_refList</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
+                        <span class="c1">// Map reference to service object for easy look up.</span>
+                        <span class="n">m_refToObjMap</span><span class="p">.</span><span class="n">put</span><span class="p">(</span><span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">service</span><span class="p">);</span>
                     <span class="p">}</span>
                 <span class="p">}</span>
 
-                <span class="sr">//</span> <span class="n">Register</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span> <span class="k">if</span> <span class="n">there</span> <span class="n">are</span> <span class="n">any</span>
-                <span class="sr">//</span> <span class="n">dictionary</span> <span class="n">services</span><span class="o">.</span>
-                <span class="k">if</span> <span class="p">(</span><span class="n">m_refList</span><span class="o">.</span><span class="n">size</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span>
+                <span class="c1">// Register spell checker service if there are any</span>
+                <span class="c1">// dictionary services.</span>
+                <span class="k">if</span> <span class="p">(</span><span class="n">m_refList</span><span class="p">.</span><span class="n">size</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mh">0</span><span class="p">)</span>
                 <span class="p">{</span>
-                    <span class="n">m_reg</span> <span class="o">=</span> <span class="n">m_context</span><span class="o">.</span><span class="n">registerService</span><span class="p">(</span>
-                        <span class="n">SpellChecker</span><span class="o">.</span><span class="n">class</span><span class="o">.</span><span class="n">getName</span><span class="p">(),</span>
-                        <span class="k">new</span> <span class="n">SpellCheckerImpl</span><span class="p">(),</span> <span class="n">null</span><span class="p">);</span>
+                    <span class="n">m_reg</span> <span class="o">=</span> <span class="n">m_context</span><span class="p">.</span><span class="n">registerService</span><span class="p">(</span>
+                        <span class="n">SpellChecker</span><span class="p">.</span><span class="k">class</span><span class="p">.</span><span class="n">getName</span><span class="p">(),</span>
+                        <span class="k">new</span> <span class="n">SpellCheckerImpl</span><span class="p">(),</span> <span class="k">null</span><span class="p">);</span>
                 <span class="p">}</span>
             <span class="p">}</span>
         <span class="p">}</span>
     <span class="p">}</span>
 
-    <span class="o">/**</span>
-     <span class="o">*</span> <span class="n">Implements</span> <span class="n">BundleActivator</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span><span class="o">.</span> <span class="n">Does</span> <span class="n">nothing</span> <span class="n">since</span>
-     <span class="o">*</span> <span class="n">the</span> <span class="n">framework</span> <span class="n">will</span> <span class="n">automatically</span> <span class="n">unregister</span> <span class="n">any</span> <span class="n">registered</span> <span class="n">services</span><span class="p">,</span>
-     <span class="o">*</span> <span class="n">release</span> <span class="n">any</span> <span class="n">used</span> <span class="n">services</span><span class="p">,</span> <span class="ow">and</span> <span class="n">remove</span> <span class="n">any</span> <span class="n">event</span> <span class="n">listeners</span><span class="o">.</span>
-     <span class="o">*</span> <span class="nv">@param</span> <span class="n">context</span> <span class="n">the</span> <span class="n">framework</span> <span class="n">context</span> <span class="k">for</span> <span class="n">the</span> <span class="n">bundle</span><span class="o">.</span>
-    <span class="o">**/</span>
-    <span class="n">public</span> <span class="n">void</span> <span class="n">stop</span><span class="p">(</span><span class="n">BundleContext</span> <span class="n">context</span><span class="p">)</span>
+    <span class="cm">/**</span>
+<span class="cm">     * Implements BundleActivator.stop(). Does nothing since</span>
+<span class="cm">     * the framework will automatically unregister any registered services,</span>
+<span class="cm">     * release any used services, and remove any event listeners.</span>
+<span class="cm">     * @param context the framework context for the bundle.</span>
+<span class="cm">    **/</span>
+    <span class="n">public</span> <span class="k">void</span> <span class="n">stop</span><span class="p">(</span><span class="n">BundleContext</span> <span class="k">context</span><span class="p">)</span>
     <span class="p">{</span>
-        <span class="sr">//</span> <span class="n">NOTE:</span> <span class="n">The</span> <span class="n">services</span> <span class="n">automatically</span> <span class="n">released</span><span class="o">.</span>
+        <span class="c1">// NOTE: The services automatically released.</span>
     <span class="p">}</span>
 
-    <span class="o">/**</span>
-     <span class="o">*</span> <span class="n">Implements</span> <span class="n">ServiceListener</span><span class="o">.</span><span class="n">serviceChanged</span><span class="p">()</span><span class="o">.</span> <span class="n">Monitors</span>
-     <span class="o">*</span> <span class="n">the</span> <span class="n">arrival</span> <span class="ow">and</span> <span class="n">departure</span> <span class="n">of</span> <span class="n">dictionary</span> <span class="n">services</span><span class="p">,</span> <span class="n">adding</span> <span class="ow">and</span>
-     <span class="o">*</span> <span class="n">removing</span> <span class="n">them</span> <span class="n">from</span> <span class="n">the</span> <span class="n">service</span> <span class="n">reference</span> <span class="n">list</span><span class="p">,</span> <span class="n">respectively</span><span class="o">.</span>
-     <span class="o">*</span> <span class="n">In</span> <span class="n">the</span> <span class="k">case</span> <span class="n">where</span> <span class="nb">no</span> <span class="n">more</span> <span class="n">dictionary</span> <span class="n">services</span> <span class="n">are</span> <span class="n">available</span><span class="p">,</span>
-     <span class="o">*</span> <span class="n">the</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span> <span class="n">is</span> <span class="n">unregistered</span><span class="o">.</span> <span class="n">As</span> <span class="n">soon</span> <span class="n">as</span> <span class="n">any</span> <span class="n">dictionary</span>
-     <span class="o">*</span> <span class="n">service</span> <span class="n">becomes</span> <span class="n">available</span><span class="p">,</span> <span class="n">the</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span> <span class="n">is</span>
-     <span class="o">*</span> <span class="n">reregistered</span><span class="o">.</span>
-     <span class="o">*</span> <span class="nv">@param</span> <span class="n">event</span> <span class="n">the</span> <span class="n">fired</span> <span class="n">service</span> <span class="n">event</span><span class="o">.</span>
-    <span class="o">**/</span>
-    <span class="n">public</span> <span class="n">void</span> <span class="n">serviceChanged</span><span class="p">(</span><span class="n">ServiceEvent</span> <span class="n">event</span><span class="p">)</span>
+    <span class="cm">/**</span>
+<span class="cm">     * Implements ServiceListener.serviceChanged(). Monitors</span>
+<span class="cm">     * the arrival and departure of dictionary services, adding and</span>
+<span class="cm">     * removing them from the service reference list, respectively.</span>
+<span class="cm">     * In the case where no more dictionary services are available,</span>
+<span class="cm">     * the spell checker service is unregistered. As soon as any dictionary</span>
+<span class="cm">     * service becomes available, the spell checker service is</span>
+<span class="cm">     * reregistered.</span>
+<span class="cm">     * @param event the fired service event.</span>
+<span class="cm">    **/</span>
+    <span class="n">public</span> <span class="k">void</span> <span class="n">serviceChanged</span><span class="p">(</span><span class="n">ServiceEvent</span> <span class="k">event</span><span class="p">)</span>
     <span class="p">{</span>
         <span class="n">synchronized</span> <span class="p">(</span><span class="n">m_refList</span><span class="p">)</span>
         <span class="p">{</span>
-            <span class="sr">//</span> <span class="n">Add</span> <span class="n">the</span> <span class="k">new</span> <span class="n">dictionary</span> <span class="n">service</span> <span class="n">to</span> <span class="n">the</span> <span class="n">service</span> <span class="n">list</span><span class="o">.</span>
-            <span class="k">if</span> <span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">getType</span><span class="p">()</span> <span class="o">==</span> <span class="n">ServiceEvent</span><span class="o">.</span><span class="n">REGISTERED</span><span class="p">)</span>
+            <span class="c1">// Add the new dictionary service to the service list.</span>
+            <span class="k">if</span> <span class="p">(</span><span class="k">event</span><span class="p">.</span><span class="n">getType</span><span class="p">()</span> <span class="o">==</span> <span class="n">ServiceEvent</span><span class="p">.</span><span class="no">REGISTERED</span><span class="p">)</span>
             <span class="p">{</span>
-                <span class="sr">//</span> <span class="n">Get</span> <span class="n">the</span> <span class="n">service</span> <span class="n">object</span><span class="o">.</span>
-                <span class="n">Object</span> <span class="n">service</span> <span class="o">=</span> <span class="n">m_context</span><span class="o">.</span><span class="n">getService</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">getServiceReference</span><span class="p">());</span>
+                <span class="c1">// Get the service object.</span>
+                <span class="n">Object</span> <span class="n">service</span> <span class="o">=</span> <span class="n">m_context</span><span class="p">.</span><span class="n">getService</span><span class="p">(</span><span class="k">event</span><span class="p">.</span><span class="n">getServiceReference</span><span class="p">());</span>
 
-                <span class="sr">//</span> <span class="n">Make</span> <span class="n">that</span> <span class="n">the</span> <span class="n">service</span> <span class="n">is</span> <span class="ow">not</span> <span class="n">being</span> <span class="n">duplicated</span><span class="o">.</span>
-                <span class="k">if</span> <span class="p">((</span><span class="n">service</span> <span class="o">!=</span> <span class="n">null</span><span class="p">)</span> <span class="o">&amp;&amp;</span>
-                    <span class="p">(</span><span class="n">m_refToObjMap</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">getServiceReference</span><span class="p">())</span> <span class="o">==</span> <span class="n">null</span><span class="p">))</span>
+                <span class="c1">// Make that the service is not being duplicated.</span>
+                <span class="k">if</span> <span class="p">((</span><span class="n">service</span> <span class="o">!=</span> <span class="k">null</span><span class="p">)</span> <span class="o">&amp;&amp;</span>
+                    <span class="p">(</span><span class="n">m_refToObjMap</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="k">event</span><span class="p">.</span><span class="n">getServiceReference</span><span class="p">())</span> <span class="o">==</span> <span class="k">null</span><span class="p">))</span>
                 <span class="p">{</span>
-                    <span class="sr">//</span> <span class="n">Add</span> <span class="n">to</span> <span class="n">the</span> <span class="n">reference</span> <span class="n">list</span><span class="o">.</span>
-                    <span class="n">m_refList</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">getServiceReference</span><span class="p">());</span>
-                    <span class="sr">//</span> <span class="n">Map</span> <span class="n">reference</span> <span class="n">to</span> <span class="n">service</span> <span class="n">object</span> <span class="k">for</span> <span class="n">easy</span> <span class="n">look</span> <span class="n">up</span><span class="o">.</span>
-                    <span class="n">m_refToObjMap</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">getServiceReference</span><span class="p">(),</span> <span class="n">service</span><span class="p">);</span>
+                    <span class="c1">// Add to the reference list.</span>
+                    <span class="n">m_refList</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="k">event</span><span class="p">.</span><span class="n">getServiceReference</span><span class="p">());</span>
+                    <span class="c1">// Map reference to service object for easy look up.</span>
+                    <span class="n">m_refToObjMap</span><span class="p">.</span><span class="n">put</span><span class="p">(</span><span class="k">event</span><span class="p">.</span><span class="n">getServiceReference</span><span class="p">(),</span> <span class="n">service</span><span class="p">);</span>
 
-                    <span class="sr">//</span> <span class="n">Register</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span> <span class="k">if</span> <span class="n">necessary</span><span class="o">.</span>
-                    <span class="k">if</span> <span class="p">(</span><span class="n">m_reg</span> <span class="o">==</span> <span class="n">null</span><span class="p">)</span>
+                    <span class="c1">// Register spell checker service if necessary.</span>
+                    <span class="k">if</span> <span class="p">(</span><span class="n">m_reg</span> <span class="o">==</span> <span class="k">null</span><span class="p">)</span>
                     <span class="p">{</span>
-                        <span class="n">m_reg</span> <span class="o">=</span> <span class="n">m_context</span><span class="o">.</span><span class="n">registerService</span><span class="p">(</span>
-                            <span class="n">SpellChecker</span><span class="o">.</span><span class="n">class</span><span class="o">.</span><span class="n">getName</span><span class="p">(),</span>
-                            <span class="k">new</span> <span class="n">SpellCheckerImpl</span><span class="p">(),</span> <span class="n">null</span><span class="p">);</span>
+                        <span class="n">m_reg</span> <span class="o">=</span> <span class="n">m_context</span><span class="p">.</span><span class="n">registerService</span><span class="p">(</span>
+                            <span class="n">SpellChecker</span><span class="p">.</span><span class="k">class</span><span class="p">.</span><span class="n">getName</span><span class="p">(),</span>
+                            <span class="k">new</span> <span class="n">SpellCheckerImpl</span><span class="p">(),</span> <span class="k">null</span><span class="p">);</span>
                     <span class="p">}</span>
                 <span class="p">}</span>
-                <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">service</span> <span class="o">!=</span> <span class="n">null</span><span class="p">)</span>
+                <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">service</span> <span class="o">!=</span> <span class="k">null</span><span class="p">)</span>
                 <span class="p">{</span>
-                    <span class="n">m_context</span><span class="o">.</span><span class="n">ungetService</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">getServiceReference</span><span class="p">());</span>
+                    <span class="n">m_context</span><span class="p">.</span><span class="n">ungetService</span><span class="p">(</span><span class="k">event</span><span class="p">.</span><span class="n">getServiceReference</span><span class="p">());</span>
                 <span class="p">}</span>
             <span class="p">}</span>
-            <span class="sr">//</span> <span class="n">Remove</span> <span class="n">the</span> <span class="n">departing</span> <span class="n">service</span> <span class="n">from</span> <span class="n">the</span> <span class="n">service</span> <span class="n">list</span><span class="o">.</span>
-            <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">getType</span><span class="p">()</span> <span class="o">==</span> <span class="n">ServiceEvent</span><span class="o">.</span><span class="n">UNREGISTERING</span><span class="p">)</span>
+            <span class="c1">// Remove the departing service from the service list.</span>
+            <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="k">event</span><span class="p">.</span><span class="n">getType</span><span class="p">()</span> <span class="o">==</span> <span class="n">ServiceEvent</span><span class="p">.</span><span class="no">UNREGISTERING</span><span class="p">)</span>
             <span class="p">{</span>
-                <span class="sr">//</span> <span class="n">Make</span> <span class="n">sure</span> <span class="n">the</span> <span class="n">service</span> <span class="n">is</span> <span class="n">in</span> <span class="n">the</span> <span class="n">list</span><span class="o">.</span>
-                <span class="k">if</span> <span class="p">(</span><span class="n">m_refToObjMap</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">getServiceReference</span><span class="p">())</span> <span class="o">!=</span> <span class="n">null</span><span class="p">)</span>
+                <span class="c1">// Make sure the service is in the list.</span>
+                <span class="k">if</span> <span class="p">(</span><span class="n">m_refToObjMap</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="k">event</span><span class="p">.</span><span class="n">getServiceReference</span><span class="p">())</span> <span class="o">!=</span> <span class="k">null</span><span class="p">)</span>
                 <span class="p">{</span>
-                    <span class="sr">//</span> <span class="n">Unget</span> <span class="n">the</span> <span class="n">service</span> <span class="n">object</span><span class="o">.</span>
-                    <span class="n">m_context</span><span class="o">.</span><span class="n">ungetService</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">getServiceReference</span><span class="p">());</span>
-                    <span class="sr">//</span> <span class="n">Remove</span> <span class="n">service</span> <span class="n">reference</span><span class="o">.</span>
-                    <span class="n">m_refList</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">getServiceReference</span><span class="p">());</span>
-                    <span class="sr">//</span> <span class="n">Remove</span> <span class="n">service</span> <span class="n">reference</span> <span class="n">from</span> <span class="nb">map</span><span class="o">.</span>
-                    <span class="n">m_refToObjMap</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">getServiceReference</span><span class="p">());</span>
-
-                    <span class="sr">//</span> <span class="n">If</span> <span class="n">there</span> <span class="n">are</span> <span class="nb">no</span> <span class="n">more</span> <span class="n">dictionary</span> <span class="n">services</span><span class="p">,</span>
-                    <span class="sr">//</span> <span class="k">then</span> <span class="n">unregister</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span><span class="o">.</span>
-                    <span class="k">if</span> <span class="p">(</span><span class="n">m_refList</span><span class="o">.</span><span class="n">size</span><span class="p">()</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
+                    <span class="c1">// Unget the service object.</span>
+                    <span class="n">m_context</span><span class="p">.</span><span class="n">ungetService</span><span class="p">(</span><span class="k">event</span><span class="p">.</span><span class="n">getServiceReference</span><span class="p">());</span>
+                    <span class="c1">// Remove service reference.</span>
+                    <span class="n">m_refList</span><span class="p">.</span><span class="n">remove</span><span class="p">(</span><span class="k">event</span><span class="p">.</span><span class="n">getServiceReference</span><span class="p">());</span>
+                    <span class="c1">// Remove service reference from map.</span>
+                    <span class="n">m_refToObjMap</span><span class="p">.</span><span class="n">remove</span><span class="p">(</span><span class="k">event</span><span class="p">.</span><span class="n">getServiceReference</span><span class="p">());</span>
+
+                    <span class="c1">// If there are no more dictionary services,</span>
+                    <span class="c1">// then unregister spell checker service.</span>
+                    <span class="k">if</span> <span class="p">(</span><span class="n">m_refList</span><span class="p">.</span><span class="n">size</span><span class="p">()</span> <span class="o">==</span> <span class="mh">0</span><span class="p">)</span>
                     <span class="p">{</span>
-                        <span class="n">m_reg</span><span class="o">.</span><span class="n">unregister</span><span class="p">();</span>
-                        <span class="n">m_reg</span> <span class="o">=</span> <span class="n">null</span><span class="p">;</span>
+                        <span class="n">m_reg</span><span class="p">.</span><span class="n">unregister</span><span class="p">();</span>
+                        <span class="n">m_reg</span> <span class="o">=</span> <span class="k">null</span><span class="p">;</span>
                     <span class="p">}</span>
                 <span class="p">}</span>
             <span class="p">}</span>
         <span class="p">}</span>
     <span class="p">}</span>
 
-    <span class="o">/**</span>
-     <span class="o">*</span> <span class="n">A</span> <span class="n">private</span> <span class="n">inner</span> <span class="n">class</span> <span class="n">that</span> <span class="n">implements</span> <span class="n">a</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span><span class="p">;</span>
-     <span class="o">*</span> <span class="n">see</span> <span class="n">SpellChecker</span> <span class="k">for</span> <span class="n">details</span> <span class="n">of</span> <span class="n">the</span> <span class="n">service</span><span class="o">.</span>
-    <span class="o">**/</span>
-    <span class="n">private</span> <span class="n">class</span> <span class="n">SpellCheckerImpl</span> <span class="n">implements</span> <span class="n">SpellChecker</span>
+    <span class="cm">/**</span>
+<span class="cm">     * A private inner class that implements a spell checker service;</span>
+<span class="cm">     * see SpellChecker for details of the service.</span>
+<span class="cm">    **/</span>
+    <span class="n">private</span> <span class="k">class</span> <span class="n">SpellCheckerImpl</span> <span class="n">implements</span> <span class="n">SpellChecker</span>
     <span class="p">{</span>
-        <span class="o">/**</span>
-         <span class="o">*</span> <span class="n">Implements</span> <span class="n">SpellChecker</span><span class="o">.</span><span class="n">check</span><span class="p">()</span><span class="o">.</span> <span class="n">Checks</span> <span class="n">the</span>
-         <span class="o">*</span> <span class="n">given</span> <span class="n">passage</span> <span class="k">for</span> <span class="n">misspelled</span> <span class="n">words</span><span class="o">.</span>
-         <span class="o">*</span> <span class="nv">@param</span> <span class="n">passage</span> <span class="n">the</span> <span class="n">passage</span> <span class="n">to</span> <span class="n">spell</span> <span class="n">check</span><span class="o">.</span>
-         <span class="o">*</span> <span class="nv">@return</span> <span class="n">An</span> <span class="n">array</span> <span class="n">of</span> <span class="n">misspelled</span> <span class="n">words</span> <span class="ow">or</span> <span class="n">null</span> <span class="k">if</span> <span class="nb">no</span>
-         <span class="o">*</span>         <span class="n">words</span> <span class="n">are</span> <span class="n">misspelled</span><span class="o">.</span>
-        <span class="o">**/</span>
-        <span class="n">public</span> <span class="n">String</span><span class="o">[]</span> <span class="n">check</span><span class="p">(</span><span class="n">String</span> <span class="n">passage</span><span class="p">)</span>
+        <span class="cm">/**</span>
+<span class="cm">         * Implements SpellChecker.check(). Checks the</span>
+<span class="cm">         * given passage for misspelled words.</span>
+<span class="cm">         * @param passage the passage to spell check.</span>
+<span class="cm">         * @return An array of misspelled words or null if no</span>
+<span class="cm">         *         words are misspelled.</span>
+<span class="cm">        **/</span>
+        <span class="n">public</span> <span class="n">String</span><span class="p">[]</span> <span class="n">check</span><span class="p">(</span><span class="n">String</span> <span class="n">passage</span><span class="p">)</span>
         <span class="p">{</span>
-            <span class="sr">//</span> <span class="n">No</span> <span class="n">misspelled</span> <span class="n">words</span> <span class="k">for</span> <span class="n">an</span> <span class="n">empty</span> <span class="n">string</span><span class="o">.</span>
-            <span class="k">if</span> <span class="p">((</span><span class="n">passage</span> <span class="o">==</span> <span class="n">null</span><span class="p">)</span> <span class="o">||</span> <span class="p">(</span><span class="n">passage</span><span class="o">.</span><span class="nb">length</span><span class="p">()</span> <span class="o">==</span> <span class="mi">0</span><span class="p">))</span>
+            <span class="c1">// No misspelled words for an empty string.</span>
+            <span class="k">if</span> <span class="p">((</span><span class="n">passage</span> <span class="o">==</span> <span class="k">null</span><span class="p">)</span> <span class="o">||</span> <span class="p">(</span><span class="n">passage</span><span class="p">.</span><span class="n">length</span><span class="p">()</span> <span class="o">==</span> <span class="mh">0</span><span class="p">))</span>
             <span class="p">{</span>
-                <span class="k">return</span> <span class="n">null</span><span class="p">;</span>
+                <span class="k">return</span> <span class="k">null</span><span class="p">;</span>
             <span class="p">}</span>
 
             <span class="n">ArrayList</span> <span class="n">errorList</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ArrayList</span><span class="p">();</span>
 
-            <span class="sr">//</span> <span class="n">Tokenize</span> <span class="n">the</span> <span class="n">passage</span> <span class="n">using</span> <span class="n">spaces</span> <span class="ow">and</span> <span class="n">punctionation</span><span class="o">.</span>
+            <span class="c1">// Tokenize the passage using spaces and punctionation.</span>
             <span class="n">StringTokenizer</span> <span class="n">st</span> <span class="o">=</span> <span class="k">new</span> <span class="n">StringTokenizer</span><span class="p">(</span><span class="n">passage</span><span class="p">,</span> <span class="s">&quot; ,.!?;:&quot;</span><span class="p">);</span>
 
-            <span class="sr">//</span> <span class="n">Lock</span> <span class="n">the</span> <span class="n">service</span> <span class="n">list</span><span class="o">.</span>
+            <span class="c1">// Lock the service list.</span>
             <span class="n">synchronized</span> <span class="p">(</span><span class="n">m_refList</span><span class="p">)</span>
             <span class="p">{</span>
-                <span class="sr">//</span> <span class="n">Loop</span> <span class="n">through</span> <span class="nb">each</span> <span class="n">word</span> <span class="n">in</span> <span class="n">the</span> <span class="n">passage</span><span class="o">.</span>
-                <span class="k">while</span> <span class="p">(</span><span class="n">st</span><span class="o">.</span><span class="n">hasMoreTokens</span><span class="p">())</span>
+                <span class="c1">// Loop through each word in the passage.</span>
+                <span class="k">while</span> <span class="p">(</span><span class="n">st</span><span class="p">.</span><span class="n">hasMoreTokens</span><span class="p">())</span>
                 <span class="p">{</span>
-                    <span class="n">String</span> <span class="n">word</span> <span class="o">=</span> <span class="n">st</span><span class="o">.</span><span class="n">nextToken</span><span class="p">();</span>
+                    <span class="n">String</span> <span class="n">word</span> <span class="o">=</span> <span class="n">st</span><span class="p">.</span><span class="n">nextToken</span><span class="p">();</span>
 
                     <span class="n">boolean</span> <span class="n">correct</span> <span class="o">=</span> <span class="n">false</span><span class="p">;</span>
 
-                    <span class="sr">//</span> <span class="n">Check</span> <span class="nb">each</span> <span class="n">available</span> <span class="n">dictionary</span> <span class="k">for</span> <span class="n">the</span> <span class="n">current</span> <span class="n">word</span><span class="o">.</span>
-                    <span class="k">for</span> <span class="p">(</span><span class="nb">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="p">(</span><span class="o">!</span><span class="n">correct</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="n">i</span> <span class="o">&lt;</span> <span class="n">m_refList</span><span class="o">.</span><span class="n">size</span><span class="p">());</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
+                    <span class="c1">// Check each available dictionary for the current word.</span>
+                    <span class="k">for</span> <span class="p">(</span><span class="k">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mh">0</span><span class="p">;</span> <span class="p">(</span><span class="o">!</span><span class="n">correct</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="n">i</span> <span class="o">&lt;</span> <span class="n">m_refList</span><span class="p">.</span><span class="n">size</span><span class="p">());</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
                     <span class="p">{</span>
                         <span class="n">DictionaryService</span> <span class="n">dictionary</span> <span class="o">=</span>
-                            <span class="p">(</span><span class="n">DictionaryService</span><span class="p">)</span> <span class="n">m_refToObjMap</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">m_refList</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">i</span><span class="p">));</span>
+                            <span class="p">(</span><span class="n">DictionaryService</span><span class="p">)</span> <span class="n">m_refToObjMap</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="n">m_refList</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="n">i</span><span class="p">));</span>
 
-                        <span class="k">if</span> <span class="p">(</span><span class="n">dictionary</span><span class="o">.</span><span class="n">checkWord</span><span class="p">(</span><span class="n">word</span><span class="p">))</span>
+                        <span class="k">if</span> <span class="p">(</span><span class="n">dictionary</span><span class="p">.</span><span class="n">checkWord</span><span class="p">(</span><span class="n">word</span><span class="p">))</span>
                         <span class="p">{</span>
                             <span class="n">correct</span> <span class="o">=</span> <span class="n">true</span><span class="p">;</span>
                         <span class="p">}</span>
                     <span class="p">}</span>
 
-                    <span class="sr">//</span> <span class="n">If</span> <span class="n">the</span> <span class="n">word</span> <span class="n">is</span> <span class="ow">not</span> <span class="n">correct</span><span class="p">,</span> <span class="k">then</span> <span class="n">add</span> <span class="n">it</span>
-                    <span class="sr">//</span> <span class="n">to</span> <span class="n">the</span> <span class="n">incorrect</span> <span class="n">word</span> <span class="n">list</span><span class="o">.</span>
+                    <span class="c1">// If the word is not correct, then add it</span>
+                    <span class="c1">// to the incorrect word list.</span>
                     <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">correct</span><span class="p">)</span>
                     <span class="p">{</span>
-                        <span class="n">errorList</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">word</span><span class="p">);</span>
+                        <span class="n">errorList</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">word</span><span class="p">);</span>
                     <span class="p">}</span>
                 <span class="p">}</span>
             <span class="p">}</span>
 
-            <span class="sr">//</span> <span class="n">Return</span> <span class="n">null</span> <span class="k">if</span> <span class="nb">no</span> <span class="n">words</span> <span class="n">are</span> <span class="n">incorrect</span><span class="o">.</span>
-            <span class="k">if</span> <span class="p">(</span><span class="n">errorList</span><span class="o">.</span><span class="n">size</span><span class="p">()</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
+            <span class="c1">// Return null if no words are incorrect.</span>
+            <span class="k">if</span> <span class="p">(</span><span class="n">errorList</span><span class="p">.</span><span class="n">size</span><span class="p">()</span> <span class="o">==</span> <span class="mh">0</span><span class="p">)</span>
             <span class="p">{</span>
-                <span class="k">return</span> <span class="n">null</span><span class="p">;</span>
+                <span class="k">return</span> <span class="k">null</span><span class="p">;</span>
             <span class="p">}</span>
 
-            <span class="sr">//</span> <span class="n">Return</span> <span class="n">the</span> <span class="n">array</span> <span class="n">of</span> <span class="n">incorrect</span> <span class="n">words</span><span class="o">.</span>
-            <span class="k">return</span> <span class="p">(</span><span class="n">String</span><span class="o">[]</span><span class="p">)</span> <span class="n">errorList</span><span class="o">.</span><span class="n">toArray</span><span class="p">(</span><span class="k">new</span> <span class="n">String</span><span class="p">[</span><span class="n">errorList</span><span class="o">.</span><span class="n">size</span><span class="p">()]);</span>
+            <span class="c1">// Return the array of incorrect words.</span>
+            <span class="k">return</span> <span class="p">(</span><span class="n">String</span><span class="p">[])</span> <span class="n">errorList</span><span class="p">.</span><span class="n">toArray</span><span class="p">(</span><span class="k">new</span> <span class="n">String</span><span class="p">[</span><span class="n">errorList</span><span class="p">.</span><span class="n">size</span><span class="p">()]);</span>
         <span class="p">}</span>
     <span class="p">}</span>
 <span class="p">}</span>
@@ -359,31 +358,31 @@
 
 
 <p>Note that we do not need to unregister the service in stop() method, because the OSGi framework will automatically do so for us. The spell checker service that we have implemented is very simple; it simply parses a given passage into words and then loops through all available dictionary services for each word until it determines that the word is correct. Any incorrect words are added to an error list that will be returned to the caller. This solution is not optimal and is only intended for educational purposes. Next, we create a <code>manifest.mf</code> file that contains the meta-data for our bundle:</p>
-<div class="codehilite"><pre><span class="n">Bundle</span><span class="o">-</span><span class="n">Name:</span> <span class="n">Spell</span> <span class="n">checker</span> <span class="n">service</span>
-<span class="n">Bundle</span><span class="o">-</span><span class="n">Description:</span> <span class="n">A</span> <span class="n">bundle</span> <span class="n">that</span> <span class="n">implements</span> <span class="n">a</span> <span class="n">simple</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span>
-<span class="n">Bundle</span><span class="o">-</span><span class="n">Vendor:</span> <span class="n">Richard</span> <span class="n">Hall</span>
-<span class="n">Bundle</span><span class="o">-</span><span class="n">Version:</span> <span class="mf">1.0.0</span>
-<span class="n">Bundle</span><span class="o">-</span><span class="n">Activator:</span> <span class="n">tutorial</span><span class="o">.</span><span class="n">example6</span><span class="o">.</span><span class="n">Activator</span>
-<span class="n">Export</span><span class="o">-</span><span class="n">Package:</span> <span class="n">tutorial</span><span class="o">.</span><span class="n">example6</span><span class="o">.</span><span class="n">service</span>
-<span class="n">Import</span><span class="o">-</span><span class="n">Package:</span> <span class="n">org</span><span class="o">.</span><span class="n">osgi</span><span class="o">.</span><span class="n">framework</span><span class="p">,</span>
- <span class="n">tutorial</span><span class="o">.</span><span class="n">example2</span><span class="o">.</span><span class="n">service</span>
+<div class="codehilite"><pre><span class="n">Bundle</span><span class="o">-</span><span class="n">Name</span><span class="p">:</span> <span class="n">Spell</span> <span class="n">checker</span> <span class="n">service</span>
+<span class="n">Bundle</span><span class="o">-</span><span class="n">Description</span><span class="p">:</span> <span class="n">A</span> <span class="n">bundle</span> <span class="n">that</span> <span class="n">implements</span> <span class="n">a</span> <span class="n">simple</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span>
+<span class="n">Bundle</span><span class="o">-</span><span class="n">Vendor</span><span class="p">:</span> <span class="n">Richard</span> <span class="n">Hall</span>
+<span class="n">Bundle</span><span class="o">-</span><span class="n">Version</span><span class="p">:</span> 1<span class="p">.</span>0<span class="p">.</span>0
+<span class="n">Bundle</span><span class="o">-</span><span class="n">Activator</span><span class="p">:</span> <span class="n">tutorial</span><span class="p">.</span><span class="n">example6</span><span class="p">.</span><span class="n">Activator</span>
+<span class="n">Export</span><span class="o">-</span><span class="n">Package</span><span class="p">:</span> <span class="n">tutorial</span><span class="p">.</span><span class="n">example6</span><span class="p">.</span><span class="n">service</span>
+<span class="n">Import</span><span class="o">-</span><span class="n">Package</span><span class="p">:</span> <span class="n">org</span><span class="p">.</span><span class="n">osgi</span><span class="p">.</span><span class="n">framework</span><span class="p">,</span>
+ <span class="n">tutorial</span><span class="p">.</span><span class="n">example2</span><span class="p">.</span><span class="n">service</span>
 </pre></div>
 
 
 <p>We specify which class used to activate the bundle via the <code>Bundle-Activator</code> attribute. Our bundle exports the spell checker service interface using the <code>Export-Package</code> attribute and imports the OSGi core framework and dictionary service interface packages using the <code>Import-Package</code> attribute. (Note: Make sure your manifest file ends in a trailing carriage return or else the last line will be ignored.)</p>
 <p>To compile our source, we need to have the <code>felix.jar</code> file (found in Felix' <code>bin</code> directory) and the example2.jar file in our class path. We compile the source file using a command like:</p>
-<div class="codehilite"><pre><span class="n">javac</span> <span class="o">-</span><span class="n">d</span> <span class="n">c:</span><span class="o">\</span><span class="n">classes</span> <span class="o">*.</span><span class="n">java</span>
+<div class="codehilite"><pre><span class="n">javac</span> <span class="o">-</span><span class="n">d</span> <span class="n">c</span><span class="p">:</span><span class="o">\</span><span class="n">classes</span> <span class="o">*</span><span class="p">.</span><span class="n">java</span>
 </pre></div>
 
 
 <p>This command compiles all source files and outputs the generated classes into a subdirectory of the <code>c:\classes</code> directory; this subdirectory is <code>tutorial\example6</code>, named after the package we specified in the source file. For the above command to work, the <code>c:\classes</code> directory must exist. After compiling, we need to create a JAR file containing the generated package directories. We will also add our manifest file that contains the bundle's meta-data to the JAR file. To create the JAR file, we issue the command:</p>
-<div class="codehilite"><pre><span class="n">jar</span> <span class="n">cfm</span> <span class="n">example6</span><span class="o">.</span><span class="n">jar</span> <span class="n">manifest</span><span class="o">.</span><span class="n">mf</span> <span class="o">-</span><span class="n">C</span> <span class="n">c:</span><span class="o">\</span><span class="n">classes</span> <span class="n">tutorial</span><span class="o">\</span><span class="n">example6</span>
+<div class="codehilite"><pre><span class="n">jar</span> <span class="n">cfm</span> <span class="n">example6</span><span class="p">.</span><span class="n">jar</span> <span class="n">manifest</span><span class="p">.</span><span class="n">mf</span> <span class="o">-</span><span class="n">C</span> <span class="n">c</span><span class="p">:</span><span class="o">\</span><span class="n">classes</span> <span class="n">tutorial</span><span class="o">\</span><span class="n">example6</span>
 </pre></div>
 
 
 <p>This command creates a JAR file using the manifest file we created and includes all of the classes in the <code>tutorial\example6</code> directory inside of the <code>c:\classes</code> directory. Once the JAR file is created, we are ready to install and start the bundle.</p>
 <p>To run Felix, we follow the instructions described in usage.html. When we start Felix, it asks for a profile name, we will put all of our bundles in a profile named <code>tutorial</code>. After running Felix, we should stop all tutorial bundles except for the service bundles. Use the <code>lb</code> command to make sure that only the bundles from Example 2 and Example 2b are active; use the <code>start</code> and <code>stop</code> commands as appropriate to start and stop the various tutorial bundles, respectively. (Note: Felix uses some bundles to provide its command shell, so do not stop these bundles.) Now we can install and start our spell checker service bundle. Assuming that we created our bundle in the directory <code>c:\tutorial</code>, we can install and start it in Felix' shell using the following command:</p>
-<div class="codehilite"><pre><span class="n">start</span> <span class="n">file:</span><span class="sr">/c:/</span><span class="n">tutorial</span><span class="o">/</span><span class="n">example6</span><span class="o">.</span><span class="n">jar</span>
+<div class="codehilite"><pre><span class="n">start</span> <span class="n">file</span><span class="p">:</span><span class="o">/</span><span class="n">c</span><span class="p">:</span><span class="o">/</span><span class="n">tutorial</span><span class="o">/</span><span class="n">example6</span><span class="p">.</span><span class="n">jar</span>
 </pre></div>
 
 



Mime
View raw message