felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r865657 [23/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-7.html
==============================================================================
--- websites/staging/felix/trunk/content/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-7.html (original)
+++ websites/staging/felix/trunk/content/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-7.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"
@@ -76,104 +75,104 @@
       <h1>Apache Felix Tutorial Example 7</h1>
       <h1 id="example-7-spell-checker-client-bundle">Example 7 - Spell Checker Client Bundle</h1>
 <p>In this example we create a client for the spell checker service we implemented in Example 6. This client monitors the dynamic availability of the spell checker service using the Service Tracker and is very similar in structure to the dictionary client we implemented in Example 5. The functionality of the spell checker client reads passages from standard input and spell checks them using the spell checker service. Our bundle uses its bundle context to create a <code>ServiceTracker</code> object to monitor spell checker services. The source code for our bundle is as follows 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">example7</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">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">util</span><span class="o">.</span><span class="n">tracker</span><span class="o">.</span><span class="n">ServiceTracker</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">uses</span> <span class="n">a</span> <span class="n">spell</span> <span class="n">checker</span>
- <span class="o">*</span> <span class="n">service</span> <span class="n">to</span> <span class="n">check</span> <span class="n">the</span> <span class="n">spelling</span> <span class="n">of</span> <span class="n">a</span> <span class="n">passage</span><span class="o">.</span> <span class="n">This</span> <span class="n">bundle</span>
- <span class="o">*</span> <span class="n">is</span> <span class="n">essentially</span> <span class="n">identical</span> <span class="n">to</span> <span class="n">Example</span> <span class="mi">5</span><span class="p">,</span> <span class="n">in</span> <span class="n">that</span> <span class="n">it</span> <span class="n">uses</span> <span class="n">the</span>
- <span class="o">*</span> <span class="n">Service</span> <span class="n">Tracker</span> <span class="n">to</span> <span class="n">monitor</span> <span class="n">the</span> <span class="n">dynamic</span> <span class="n">availability</span> <span class="n">of</span> <span class="n">the</span>
- <span class="o">*</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">service</span><span class="o">.</span> <span class="n">When</span> <span class="n">starting</span> <span class="n">this</span> <span class="n">bundle</span><span class="p">,</span> <span class="n">the</span> <span class="n">thread</span>
- <span class="o">*</span> <span class="n">calling</span> <span class="n">the</span> <span class="n">start</span><span class="p">()</span> <span class="n">method</span> <span class="n">is</span> <span class="n">used</span> <span class="n">to</span> <span class="nb">read</span> <span class="n">passages</span> <span class="n">from</span>
- <span class="o">*</span> <span class="n">standard</span> <span class="n">input</span><span class="o">.</span> <span class="n">You</span> <span class="n">can</span> <span class="n">stop</span> <span class="n">spell</span> <span class="n">checking</span> <span class="n">passages</span> <span class="n">by</span>
- <span class="o">*</span> <span class="n">entering</span> <span class="n">an</span> <span class="n">empty</span> <span class="n">line</span><span class="p">,</span> <span class="n">but</span> <span class="n">to</span> <span class="n">start</span> <span class="n">spell</span> <span class="n">checking</span> <span class="n">again</span>
- <span class="o">*</span> <span class="n">you</span> <span class="n">must</span> <span class="n">stop</span> <span class="ow">and</span> <span class="k">then</span> <span class="n">restart</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">class</span> <span class="n">Activator</span> <span class="n">implements</span> <span class="n">BundleActivator</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">example7</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">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">util</span><span class="p">.</span><span class="n">tracker</span><span class="p">.</span><span class="n">ServiceTracker</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 uses a spell checker</span>
+<span class="cm"> * service to check the spelling of a passage. This bundle</span>
+<span class="cm"> * is essentially identical to Example 5, in that it uses the</span>
+<span class="cm"> * Service Tracker to monitor the dynamic availability of the</span>
+<span class="cm"> * spell checker service. When starting this bundle, the thread</span>
+<span class="cm"> * calling the start() method is used to read passages from</span>
+<span class="cm"> * standard input. You can stop spell checking passages by</span>
+<span class="cm"> * entering an empty line, but to start spell checking again</span>
+<span class="cm"> * you must stop and then restart the bundle.</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="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">The</span> <span class="n">service</span> <span class="n">tacker</span> <span class="n">object</span><span class="o">.</span>
-    <span class="n">private</span> <span class="n">ServiceTracker</span> <span class="n">m_tracker</span> <span class="o">=</span> <span class="n">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">Creates</span> <span class="n">a</span> <span class="n">Service</span>
-     <span class="o">*</span> <span class="n">Tracker</span> <span class="n">object</span> <span class="n">to</span> <span class="n">monitor</span> <span class="n">spell</span> <span class="n">checker</span> <span class="n">services</span><span class="o">.</span> <span class="n">Enters</span>
-     <span class="o">*</span> <span class="n">a</span> <span class="n">spell</span> <span class="n">check</span> <span class="n">loop</span> <span class="n">where</span> <span class="n">it</span> <span class="n">reads</span> <span class="n">passages</span> <span class="n">from</span> <span class="n">standard</span>
-     <span class="o">*</span> <span class="n">input</span> <span class="ow">and</span> <span class="n">checks</span> <span class="n">their</span> <span class="n">spelling</span> <span class="n">using</span> <span class="n">the</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="p">(</span><span class="n">NOTE:</span> <span class="n">It</span> <span class="n">is</span> <span class="n">very</span> <span class="n">bad</span> <span class="n">practice</span> <span class="n">to</span> <span class="k">use</span> <span class="n">the</span> <span class="n">calling</span> <span class="n">thread</span>
-     <span class="o">*</span> <span class="n">to</span> <span class="n">perform</span> <span class="n">a</span> <span class="n">lengthy</span> <span class="n">process</span> <span class="n">like</span> <span class="n">this</span><span class="p">;</span> <span class="n">this</span> <span class="n">is</span> <span class="n">only</span> <span class="n">done</span>
-     <span class="o">*</span> <span class="k">for</span> <span class="n">the</span> <span class="n">purpose</span> <span class="n">of</span> <span class="n">the</span> <span class="n">tutorial</span><span class="o">.</span><span class="p">)</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="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">// The service tacker object.</span>
+    <span class="n">private</span> <span class="n">ServiceTracker</span> <span class="n">m_tracker</span> <span class="o">=</span> <span class="k">null</span><span class="p">;</span>
+
+    <span class="cm">/**</span>
+<span class="cm">     * Implements BundleActivator.start(). Creates a Service</span>
+<span class="cm">     * Tracker object to monitor spell checker services. Enters</span>
+<span class="cm">     * a spell check loop where it reads passages from standard</span>
+<span class="cm">     * input and checks their spelling using the spell checker service.</span>
+<span class="cm">     * (NOTE: It is very bad practice to use the calling thread</span>
+<span class="cm">     * to perform a lengthy process like this; this is only done</span>
+<span class="cm">     * for the purpose of the tutorial.)</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="sr">//</span> <span class="n">Create</span> <span class="n">a</span> <span class="n">service</span> <span class="n">tracker</span> <span class="n">to</span> <span class="n">monitor</span> <span class="n">dictionary</span> <span class="n">services</span><span class="o">.</span>
+        <span class="c1">// Create a service tracker to monitor dictionary services.</span>
         <span class="n">m_tracker</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ServiceTracker</span><span class="p">(</span>
             <span class="n">m_context</span><span class="p">,</span>
-            <span class="n">m_context</span><span class="o">.</span><span class="n">createFilter</span><span class="p">(</span>
-                <span class="s">&quot;(objectClass=&quot;</span> <span class="o">+</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="o">+</span> <span class="s">&quot;)&quot;</span><span class="p">),</span>
-            <span class="n">null</span><span class="p">);</span>
-        <span class="n">m_tracker</span><span class="o">.</span><span class="nb">open</span><span class="p">();</span>
+            <span class="n">m_context</span><span class="p">.</span><span class="n">createFilter</span><span class="p">(</span>
+                <span class="s">&quot;(objectClass=&quot;</span> <span class="o">+</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="o">+</span> <span class="s">&quot;)&quot;</span><span class="p">),</span>
+            <span class="k">null</span><span class="p">);</span>
+        <span class="n">m_tracker</span><span class="p">.</span><span class="n">open</span><span class="p">();</span>
 
         <span class="n">try</span>
         <span class="p">{</span>
-            <span class="n">System</span><span class="o">.</span><span class="n">out</span><span class="o">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;Enter a blank line to exit.&quot;</span><span class="p">);</span>
+            <span class="n">System</span><span class="p">.</span><span class="n">out</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;Enter a blank line to exit.&quot;</span><span class="p">);</span>
             <span class="n">String</span> <span class="n">passage</span> <span class="o">=</span> <span class="s">&quot;&quot;</span><span class="p">;</span>
-            <span class="n">BufferedReader</span> <span class="n">in</span> <span class="o">=</span> <span class="k">new</span> <span class="n">BufferedReader</span><span class="p">(</span><span class="k">new</span> <span class="n">InputStreamReader</span><span class="p">(</span><span class="n">System</span><span class="o">.</span><span class="n">in</span><span class="p">));</span>
+            <span class="n">BufferedReader</span> <span class="n">in</span> <span class="o">=</span> <span class="k">new</span> <span class="n">BufferedReader</span><span class="p">(</span><span class="k">new</span> <span class="n">InputStreamReader</span><span class="p">(</span><span class="n">System</span><span class="p">.</span><span class="n">in</span><span class="p">));</span>
 
-            <span class="sr">//</span> <span class="n">Loop</span> <span class="n">endlessly</span><span class="o">.</span>
+            <span class="c1">// Loop endlessly.</span>
             <span class="k">while</span> <span class="p">(</span><span class="n">true</span><span class="p">)</span>
             <span class="p">{</span>
-                <span class="sr">//</span> <span class="n">Ask</span> <span class="n">the</span> <span class="n">user</span> <span class="n">to</span> <span class="n">enter</span> <span class="n">a</span> <span class="n">passage</span><span class="o">.</span>
-                <span class="n">System</span><span class="o">.</span><span class="n">out</span><span class="o">.</span><span class="k">print</span><span class="p">(</span><span class="s">&quot;Enter passage: &quot;</span><span class="p">);</span>
-                <span class="n">passage</span> <span class="o">=</span> <span class="n">in</span><span class="o">.</span><span class="n">readLine</span><span class="p">();</span>
-
-                <span class="sr">//</span> <span class="n">Get</span> <span class="n">the</span> <span class="n">selected</span> <span class="n">dictionary</span> <span class="n">service</span><span class="p">,</span> <span class="k">if</span> <span class="n">available</span><span class="o">.</span>
-                <span class="n">SpellChecker</span> <span class="n">checker</span> <span class="o">=</span> <span class="p">(</span><span class="n">SpellChecker</span><span class="p">)</span> <span class="n">m_tracker</span><span class="o">.</span><span class="n">getService</span><span class="p">();</span>
-
-                <span class="sr">//</span> <span class="n">If</span> <span class="n">the</span> <span class="n">user</span> <span class="n">entered</span> <span class="n">a</span> <span class="n">blank</span> <span class="n">line</span><span class="p">,</span> <span class="k">then</span>
-                <span class="sr">//</span> <span class="nb">exit</span> <span class="n">the</span> <span class="n">loop</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="nb">length</span><span class="p">()</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
+                <span class="c1">// Ask the user to enter a passage.</span>
+                <span class="n">System</span><span class="p">.</span><span class="n">out</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="s">&quot;Enter passage: &quot;</span><span class="p">);</span>
+                <span class="n">passage</span> <span class="o">=</span> <span class="n">in</span><span class="p">.</span><span class="n">readLine</span><span class="p">();</span>
+
+                <span class="c1">// Get the selected dictionary service, if available.</span>
+                <span class="n">SpellChecker</span> <span class="k">checker</span> <span class="o">=</span> <span class="p">(</span><span class="n">SpellChecker</span><span class="p">)</span> <span class="n">m_tracker</span><span class="p">.</span><span class="n">getService</span><span class="p">();</span>
+
+                <span class="c1">// If the user entered a blank line, then</span>
+                <span class="c1">// exit the loop.</span>
+                <span class="k">if</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="n">break</span><span class="p">;</span>
+                    <span class="k">break</span><span class="p">;</span>
                 <span class="p">}</span>
-                <span class="sr">//</span> <span class="n">If</span> <span class="n">there</span> <span class="n">is</span> <span class="nb">no</span> <span class="n">spell</span> <span class="n">checker</span><span class="p">,</span> <span class="k">then</span> <span class="n">say</span> <span class="n">so</span><span class="o">.</span>
-                <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">checker</span> <span class="o">==</span> <span class="n">null</span><span class="p">)</span>
+                <span class="c1">// If there is no spell checker, then say so.</span>
+                <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="k">checker</span> <span class="o">==</span> <span class="k">null</span><span class="p">)</span>
                 <span class="p">{</span>
-                    <span class="n">System</span><span class="o">.</span><span class="n">out</span><span class="o">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;No spell checker available.&quot;</span><span class="p">);</span>
+                    <span class="n">System</span><span class="p">.</span><span class="n">out</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;No spell checker available.&quot;</span><span class="p">);</span>
                 <span class="p">}</span>
-                <span class="sr">//</span> <span class="n">Otherwise</span> <span class="n">check</span> <span class="n">passage</span> <span class="ow">and</span> <span class="k">print</span> <span class="n">misspelled</span> <span class="n">words</span><span class="o">.</span>
+                <span class="c1">// Otherwise check passage and print misspelled words.</span>
                 <span class="k">else</span>
                 <span class="p">{</span>
-                    <span class="n">String</span><span class="o">[]</span> <span class="n">errors</span> <span class="o">=</span> <span class="n">checker</span><span class="o">.</span><span class="n">check</span><span class="p">(</span><span class="n">passage</span><span class="p">);</span>
+                    <span class="n">String</span><span class="p">[]</span> <span class="n">errors</span> <span class="o">=</span> <span class="k">checker</span><span class="p">.</span><span class="n">check</span><span class="p">(</span><span class="n">passage</span><span class="p">);</span>
 
-                    <span class="k">if</span> <span class="p">(</span><span class="n">errors</span> <span class="o">==</span> <span class="n">null</span><span class="p">)</span>
+                    <span class="k">if</span> <span class="p">(</span><span class="n">errors</span> <span class="o">==</span> <span class="k">null</span><span class="p">)</span>
                     <span class="p">{</span>
-                        <span class="n">System</span><span class="o">.</span><span class="n">out</span><span class="o">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;Passage is correct.&quot;</span><span class="p">);</span>
+                        <span class="n">System</span><span class="p">.</span><span class="n">out</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;Passage is correct.&quot;</span><span class="p">);</span>
                     <span class="p">}</span>
                     <span class="k">else</span>
                     <span class="p">{</span>
-                        <span class="n">System</span><span class="o">.</span><span class="n">out</span><span class="o">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;Incorrect word(s):&quot;</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">errors</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="n">System</span><span class="p">.</span><span class="n">out</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;Incorrect word(s):&quot;</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">errors</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="n">System</span><span class="o">.</span><span class="n">out</span><span class="o">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;    &quot;</span> <span class="o">+</span> <span class="n">errors</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
+                            <span class="n">System</span><span class="p">.</span><span class="n">out</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;    &quot;</span> <span class="o">+</span> <span class="n">errors</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
                         <span class="p">}</span>
                     <span class="p">}</span>
                 <span class="p">}</span>
@@ -181,12 +180,12 @@
         <span class="p">}</span> <span class="n">catch</span> <span class="p">(</span><span class="n">Exception</span> <span class="n">ex</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">unget</span> <span class="n">any</span> <span class="n">used</span> <span class="n">services</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 unget any used services.</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="p">}</span>
 <span class="p">}</span>
@@ -194,31 +193,31 @@
 
 
 <p>The client uses the Service Tracker to listen for spell checker services. Like normal, we must create a <code>manifest.mf</code> file that contains the meta-data for our bundle; the manifest file contains the following:</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">client</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">uses</span> <span class="n">the</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">example7</span><span class="o">.</span><span class="n">Activator</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">org</span><span class="o">.</span><span class="n">osgi</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="n">tracker</span><span class="p">,</span>
- <span class="n">tutorial</span><span class="o">.</span><span class="n">example6</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">client</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">uses</span> <span class="n">the</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">example7</span><span class="p">.</span><span class="n">Activator</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">org</span><span class="p">.</span><span class="n">osgi</span><span class="p">.</span><span class="n">util</span><span class="p">.</span><span class="n">tracker</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>
 </pre></div>
 
 
 <p>We specify which class is used to activate the bundle via the <code>Bundle-Activator</code> attribute and also specify that our bundle imports the OSGi core, OSGi Service Tracker, and spell checker service interface packages with the <code>Import-Package</code> attribute. The OSGi framework will automatically handle the details of resolving import packages. (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 code, we need to have the <code>felix.jar</code> file (found in Felix' <code>bin</code> directory) and the <code>example6.jar</code> 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\example7</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">example7</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">example7</span>
+<div class="codehilite"><pre><span class="n">jar</span> <span class="n">cfm</span> <span class="n">example7</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">example7</span>
 </pre></div>
 
 
 <p>This command creates a JAR file using the manifest file we created and includes all of the classes in the tutorial\example6 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, Example 2b, and Example 6 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 client 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">example7</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">example7</span><span class="p">.</span><span class="n">jar</span>
 </pre></div>
 
 



Mime
View raw message