<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-34320290</id><updated>2011-12-15T11:08:58.125+08:00</updated><category term='C#'/><category term='VB.NET'/><category term='OSGi'/><category term='VC++'/><category term='JAVA'/><category term='Event'/><title type='text'>TECHNOLOGY</title><subtitle type='html'>收集自己所关注的技术</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://coolflyreg.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://coolflyreg.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>coolflyr_reg</name><uri>http://www.blogger.com/profile/13114315753504344218</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_oqeis3g1k2A/SW1fbBJKK3I/AAAAAAAABiw/oQV4_U7uBwM/S220/120_136124_2.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>28</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-34320290.post-2026648993908984383</id><published>2008-12-14T22:00:00.000+08:00</published><updated>2008-12-14T22:02:14.567+08:00</updated><title type='text'>[Objective-C]分数类</title><content type='html'>&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Courier; "&gt;&lt;span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 153, 0);"&gt;// FILE FractionNumber.h&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier; color: #c41a16"&gt;&lt;span class="Apple-style-span" style="color: rgb(100, 56, 32); font-family: Monaco; font-size: 10px;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); "&gt;&lt;span class="Apple-style-span" style="color: rgb(196, 26, 22); font-family: Courier; font-size: 12px; "&gt;&lt;span style="font: 10.0px Monaco; color: #643820"&gt;#import &lt;/span&gt;&lt;cocoa/cocoa.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span style="color: #aa0d91"&gt;@interface&lt;/span&gt; FractionNumber : NSObject {&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;numerator&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;denominator&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;@property&lt;span style="color: #000000"&gt;(&lt;/span&gt;readwrite&lt;span style="color: #000000"&gt;) &lt;/span&gt;int&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;numerator&lt;/span&gt;&lt;span style="color: #000000"&gt;, &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;denominator&lt;/span&gt;&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;-(&lt;span style="color: #aa0d91"&gt;id&lt;/span&gt;)initWithIntegers:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)x numbery:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)y;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #5c2699"&gt;NSString&lt;/span&gt; *)stringValue;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;float&lt;/span&gt;)floatValue;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;double&lt;/span&gt;)doubleValue;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;void&lt;/span&gt;)add:(&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)fn;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;void&lt;/span&gt;)sub:(&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)fn;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;void&lt;/span&gt;)div:(&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)fn;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;void&lt;/span&gt;)mul:(&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)fn;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;+(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)gcd:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)x numbery:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)y;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;+(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)lcm:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)x numbery:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)y;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;+ (&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)parseFractionNumberWithString:(&lt;span style="color: #5c2699"&gt;NSString&lt;/span&gt; *)stringNumber;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;+ (&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)parseFractionNumberWithFloat:(&lt;span style="color: #aa0d91"&gt;double&lt;/span&gt;)floatNumber;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;+ (&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)parseFractionNumberWithInteger:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)intNumber;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;@end&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 153, 0);"&gt;// FILE FractionNumber.m&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier; color: #c41a16"&gt;&lt;span style="font: 10.0px Monaco; color: #643820"&gt;#import &lt;/span&gt;"FractionNumber.h"&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span style="color: #aa0d91"&gt;@implementation&lt;/span&gt; FractionNumber&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span style="color: #aa0d91"&gt;@synthesize&lt;/span&gt; numerator, denominator;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;-(&lt;span style="color: #aa0d91"&gt;id&lt;/span&gt;)init&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;[&lt;span style="color: #aa0d91"&gt;super&lt;/span&gt; &lt;span style="color: #2e0d6e"&gt;init&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;numerator&lt;span style="color: #000000"&gt; = &lt;/span&gt;&lt;span style="color: #1c00cf"&gt;0&lt;/span&gt;&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;denominator&lt;span style="color: #000000"&gt; = &lt;/span&gt;&lt;span style="color: #1c00cf"&gt;1&lt;/span&gt;&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;return&lt;span style="color: #000000"&gt; &lt;/span&gt;self&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;-(&lt;span style="color: #aa0d91"&gt;id&lt;/span&gt;)initWithIntegers:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)x numbery:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)y&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;[&lt;span style="color: #aa0d91"&gt;super&lt;/span&gt; &lt;span style="color: #2e0d6e"&gt;init&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;numerator&lt;span style="color: #000000"&gt; = x;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;denominator&lt;span style="color: #000000"&gt; = y;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;return&lt;span style="color: #000000"&gt; &lt;/span&gt;self&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #5c2699"&gt;NSString&lt;/span&gt; *)stringValue&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #2e0d6e"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;return&lt;/span&gt;&lt;span style="color: #000000"&gt; [[&lt;/span&gt;&lt;span style="color: #5c2699"&gt;NSString&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;alloc&lt;span style="color: #000000"&gt;] &lt;/span&gt;initWithFormat&lt;span style="color: #000000"&gt;:&lt;/span&gt;&lt;span style="font: 12.0px Courier; color: #c41a16"&gt;@"%.11g"&lt;/span&gt;&lt;span style="color: #000000"&gt;, [&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;self&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;doubleValue&lt;span style="color: #000000"&gt;]];&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;float&lt;/span&gt;)floatValue&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;return&lt;/span&gt;&lt;span style="color: #000000"&gt; (&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;float&lt;/span&gt;&lt;span style="color: #000000"&gt;)&lt;/span&gt;numerator&lt;span style="color: #000000"&gt;/(&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;float&lt;/span&gt;&lt;span style="color: #000000"&gt;)&lt;/span&gt;denominator&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;double&lt;/span&gt;)doubleValue&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;return&lt;/span&gt;&lt;span style="color: #000000"&gt; (&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;double&lt;/span&gt;&lt;span style="color: #000000"&gt;)&lt;/span&gt;numerator&lt;span style="color: #000000"&gt;/(&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;double&lt;/span&gt;&lt;span style="color: #000000"&gt;)&lt;/span&gt;denominator&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;id&lt;/span&gt;)copy&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;FractionNumber&lt;span style="color: #000000"&gt; *fn = [[&lt;/span&gt;FractionNumber&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #2e0d6e"&gt;alloc&lt;/span&gt;&lt;span style="color: #000000"&gt;] &lt;/span&gt;&lt;span style="color: #26474b"&gt;initWithIntegers&lt;/span&gt;&lt;span style="color: #000000"&gt;:&lt;/span&gt;numerator&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;&lt;span style="color: #000000"&gt;:&lt;/span&gt;denominator&lt;span style="color: #000000"&gt;];&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;return&lt;span style="color: #000000"&gt; fn;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;void&lt;/span&gt;)add:(&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)fn&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;&lt;span style="color: #000000"&gt; x1 = &lt;/span&gt;numerator&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;&lt;span style="color: #000000"&gt; y1 = &lt;/span&gt;denominator&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; x2 = [fn &lt;span style="color: #26474b"&gt;numerator&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; y2 = [fn denominator];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; lcmnum = [&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; &lt;span style="color: #26474b"&gt;lcm&lt;/span&gt;:y1&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;:y2];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;x1 = lcmnum / y1 * x1;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;x2 = lcmnum / y2 * x2;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;numerator&lt;/span&gt; = x1 + x2;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;denominator&lt;/span&gt; = lcmnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;&lt;span style="color: #000000"&gt; gcdnum = [&lt;/span&gt;FractionNumber&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;&lt;span style="color: #000000"&gt;:&lt;/span&gt;numerator&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;&lt;span style="color: #000000"&gt;:&lt;/span&gt;denominator&lt;span style="color: #000000"&gt;];&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;while&lt;/span&gt; (gcdnum &gt; &lt;span style="color: #1c00cf"&gt;1&lt;/span&gt;)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;numerator&lt;/span&gt; /= gcdnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;denominator&lt;/span&gt; /= gcdnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;gcdnum = [&lt;/span&gt;FractionNumber&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;&lt;span style="color: #000000"&gt;:&lt;/span&gt;numerator&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;&lt;span style="color: #000000"&gt;:&lt;/span&gt;denominator&lt;span style="color: #000000"&gt;];&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;void&lt;/span&gt;)sub:(&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)fn&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;&lt;span style="color: #000000"&gt; x1 = &lt;/span&gt;numerator&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;&lt;span style="color: #000000"&gt; y1 = &lt;/span&gt;denominator&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; x2 = [fn &lt;span style="color: #26474b"&gt;numerator&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; y2 = [fn denominator];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; lcmnum = [&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; &lt;span style="color: #26474b"&gt;lcm&lt;/span&gt;:y1&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;:y2];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;x1 = lcmnum / y1 * x1;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;x2 = lcmnum / y2 * x2;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;numerator&lt;/span&gt; = x1 - x2;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;denominator&lt;/span&gt; = lcmnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;&lt;span style="color: #000000"&gt; gcdnum = [&lt;/span&gt;FractionNumber&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;&lt;span style="color: #000000"&gt;:&lt;/span&gt;numerator&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;&lt;span style="color: #000000"&gt;:&lt;/span&gt;denominator&lt;span style="color: #000000"&gt;];&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;while&lt;/span&gt; (gcdnum &gt; &lt;span style="color: #1c00cf"&gt;1&lt;/span&gt;)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;numerator&lt;/span&gt; /= gcdnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;denominator&lt;/span&gt; /= gcdnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;gcdnum = [&lt;/span&gt;FractionNumber&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;&lt;span style="color: #000000"&gt;:&lt;/span&gt;numerator&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;&lt;span style="color: #000000"&gt;:&lt;/span&gt;denominator&lt;span style="color: #000000"&gt;];&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;void&lt;/span&gt;)div:(&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)fn&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *newFn = [[&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; &lt;span style="color: #2e0d6e"&gt;alloc&lt;/span&gt;] &lt;span style="color: #26474b"&gt;initWithIntegers&lt;/span&gt;:[fn denominator] &lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;:[fn &lt;span style="color: #26474b"&gt;numerator&lt;/span&gt;]];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;[&lt;span style="color: #aa0d91"&gt;self&lt;/span&gt; &lt;span style="color: #26474b"&gt;mul&lt;/span&gt;:newFn];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;[newFn &lt;span style="color: #2e0d6e"&gt;release&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;- (&lt;span style="color: #aa0d91"&gt;void&lt;/span&gt;)mul:(&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)fn&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;&lt;span style="color: #000000"&gt; x1 = &lt;/span&gt;numerator&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;&lt;span style="color: #000000"&gt; y1 = &lt;/span&gt;denominator&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; x2 = [fn &lt;span style="color: #26474b"&gt;numerator&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; y2 = [fn denominator];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; gcdnum = [&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; &lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;:x1 &lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;:y2];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;while&lt;/span&gt;(gcdnum &gt; &lt;span style="color: #1c00cf"&gt;1&lt;/span&gt;)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;x1 /= gcdnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;y2 /= gcdnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;gcdnum = [&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; &lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;:x1 &lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;:y2];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;gcdnum = [&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; &lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;:x2 &lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;:y1];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;while&lt;/span&gt;(gcdnum &gt; &lt;span style="color: #1c00cf"&gt;1&lt;/span&gt;)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;x2 /= gcdnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;y1 /= gcdnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;gcdnum = [&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; &lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;:x2 &lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;:y1];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;numerator&lt;/span&gt; = x1 * x2;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #3f6e74"&gt;denominator&lt;/span&gt; = y1 * y2;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;+(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)gcd:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)x numbery:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)y&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;return&lt;/span&gt; (!y)?x:[&lt;span style="color: #aa0d91"&gt;self&lt;/span&gt; &lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;:y &lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;:x%y];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;+(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)lcm:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)x numbery:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)y&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; y1 = x;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; y2 = y;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; gcdnum = [&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; &lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;:y1 &lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;:y2];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;while&lt;/span&gt;(gcdnum &gt; &lt;span style="color: #1c00cf"&gt;1&lt;/span&gt;)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;y1 /= gcdnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;y2 /= gcdnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;gcdnum = [&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; &lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;:y1 &lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;:y2];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;return&lt;/span&gt; x * y1;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;+(&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)parseFractionNumberWithString:(&lt;span style="color: #5c2699"&gt;NSString&lt;/span&gt; *)stringNumber&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;if&lt;/span&gt; (!stringNumber || [stringNumber &lt;span style="color: #2e0d6e"&gt;length&lt;/span&gt;] == &lt;span style="color: #1c00cf"&gt;0&lt;/span&gt;)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;return&lt;span style="color: #000000"&gt; &lt;/span&gt;NULL&lt;span style="color: #000000"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #5c2699"&gt;NSRange&lt;/span&gt; range = [stringNumber &lt;span style="color: #2e0d6e"&gt;rangeOfString&lt;/span&gt;:&lt;span style="font: 12.0px Courier; color: #c41a16"&gt;@"."&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;if&lt;/span&gt; (range.&lt;span style="color: #5c2699"&gt;location&lt;/span&gt; == &lt;span style="color: #2e0d6e"&gt;NSNotFound&lt;/span&gt;)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; number = [stringNumber &lt;span style="color: #2e0d6e"&gt;intValue&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #26474b"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #aa0d91"&gt;return&lt;/span&gt;&lt;span style="color: #000000"&gt; [&lt;/span&gt;&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;parseFractionNumberWithInteger&lt;span style="color: #000000"&gt;:number];&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;else&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;@try&lt;/span&gt; {&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;[stringNumber &lt;span style="color: #2e0d6e"&gt;doubleValue&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;@catch&lt;/span&gt; (&lt;span style="color: #5c2699"&gt;NSException&lt;/span&gt; * e) {&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;@throw&lt;/span&gt; e;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; floatNumberLength = [stringNumber &lt;span style="color: #2e0d6e"&gt;length&lt;/span&gt;] - range.&lt;span style="color: #5c2699"&gt;location&lt;/span&gt; - &lt;span style="color: #1c00cf"&gt;1&lt;/span&gt;;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; ten = &lt;span style="color: #2e0d6e"&gt;pow&lt;/span&gt;(&lt;span style="color: #1c00cf"&gt;10&lt;/span&gt;, floatNumberLength);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #5c2699"&gt;NSArray&lt;/span&gt; *numberparts = [stringNumber &lt;span style="color: #2e0d6e"&gt;componentsSeparatedByString&lt;/span&gt;:&lt;span style="font: 12.0px Courier; color: #c41a16"&gt;@"."&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; x = [(&lt;span style="color: #5c2699"&gt;NSString&lt;/span&gt; *)[numberparts &lt;span style="color: #2e0d6e"&gt;objectAtIndex&lt;/span&gt;:&lt;span style="color: #1c00cf"&gt;1&lt;/span&gt;] &lt;span style="color: #2e0d6e"&gt;intValue&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;//x = (x * (ten - 1) + x);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;//int y = ((ten - 1) * ten);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; y = ten;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; gcdnum = [&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; &lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;:x &lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;:y];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;while&lt;/span&gt; (gcdnum &gt; &lt;span style="color: #1c00cf"&gt;1&lt;/span&gt;)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;x /= gcdnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;y /= gcdnum;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;gcdnum = [&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; &lt;span style="color: #26474b"&gt;gcd&lt;/span&gt;:x &lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;:y];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt; num = [(&lt;span style="color: #5c2699"&gt;NSString&lt;/span&gt; *)[numberparts &lt;span style="color: #2e0d6e"&gt;objectAtIndex&lt;/span&gt;:&lt;span style="color: #1c00cf"&gt;0&lt;/span&gt;] &lt;span style="color: #2e0d6e"&gt;intValue&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;x += num * y;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;FractionNumber&lt;span style="color: #000000"&gt; *fn = [[&lt;/span&gt;FractionNumber&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #2e0d6e"&gt;alloc&lt;/span&gt;&lt;span style="color: #000000"&gt;] &lt;/span&gt;&lt;span style="color: #26474b"&gt;initWithIntegers&lt;/span&gt;&lt;span style="color: #000000"&gt;:x&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;&lt;span style="color: #000000"&gt;:y];&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #aa0d91"&gt;return&lt;/span&gt; fn;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;+(&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)parseFractionNumberWithFloat:(&lt;span style="color: #aa0d91"&gt;double&lt;/span&gt;)floatNumber&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #5c2699"&gt;NSString&lt;/span&gt; *numberString = [[&lt;span style="color: #5c2699"&gt;NSString&lt;/span&gt; &lt;span style="color: #2e0d6e"&gt;alloc&lt;/span&gt;] &lt;span style="color: #2e0d6e"&gt;initWithFormat&lt;/span&gt;:&lt;span style="font: 12.0px Courier; color: #c41a16"&gt;@"%.11g"&lt;/span&gt;, floatNumber];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #26474b"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt;&lt;span style="color: #000000"&gt; *fn = [&lt;/span&gt;&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;parseFractionNumberWithString&lt;span style="color: #000000"&gt;:numberString];&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;[numberString &lt;span style="color: #2e0d6e"&gt;release&lt;/span&gt;];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;return&lt;span style="color: #000000"&gt; fn;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;+(&lt;span style="color: #3f6e74"&gt;FractionNumber&lt;/span&gt; *)parseFractionNumberWithInteger:(&lt;span style="color: #aa0d91"&gt;int&lt;/span&gt;)intNumber&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;FractionNumber&lt;span style="color: #000000"&gt; *fn = [[&lt;/span&gt;FractionNumber&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #2e0d6e"&gt;alloc&lt;/span&gt;&lt;span style="color: #000000"&gt;] &lt;/span&gt;&lt;span style="color: #26474b"&gt;initWithIntegers&lt;/span&gt;&lt;span style="color: #000000"&gt;:intNumber&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #26474b"&gt;numbery&lt;/span&gt;&lt;span style="color: #000000"&gt;:&lt;/span&gt;&lt;span style="color: #1c00cf"&gt;1&lt;/span&gt;&lt;span style="color: #000000"&gt;];&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;&lt;span style="color: #000000"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;return&lt;span style="color: #000000"&gt; fn;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"&gt;}&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91"&gt;@end&lt;/p&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(170, 13, 145);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34320290-2026648993908984383?l=coolflyreg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://coolflyreg.blogspot.com/feeds/2026648993908984383/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34320290&amp;postID=2026648993908984383' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/2026648993908984383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/2026648993908984383'/><link rel='alternate' type='text/html' href='http://coolflyreg.blogspot.com/2008/12/objective-c.html' title='[Objective-C]分数类'/><author><name>coolflyr_reg</name><uri>http://www.blogger.com/profile/13114315753504344218</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_oqeis3g1k2A/SW1fbBJKK3I/AAAAAAAABiw/oQV4_U7uBwM/S220/120_136124_2.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34320290.post-2295646460045990953</id><published>2008-07-24T23:47:00.003+08:00</published><updated>2008-07-25T16:42:42.798+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><category scheme='http://www.blogger.com/atom/ns#' term='Event'/><title type='text'>[JAVA]OSGi开发之Event:事件处理</title><content type='html'>&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px SimSun;color: rgb(157, 69, 16);"&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;首先配置&lt;/span&gt;OSGi Framework&lt;span style="font: 12.0px STHeiti Light"&gt;的运行环境，我的&lt;/span&gt;Eclipse&lt;span style="font: 12.0px STHeiti Light"&gt;是&lt;/span&gt;3.3&lt;span style="font: 12.0px STHeiti Light"&gt;的，运行环境需要以下的&lt;/span&gt;Bundle&lt;span style="font: 12.0px STHeiti Light"&gt;：&lt;/span&gt; &lt;/p&gt; &lt;ul style="list-style-type: disc"&gt; &lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;&lt;/li&gt; &lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;org.eclipse.osgi &lt;/li&gt; &lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;org.eclipse.equinox.ds &lt;/li&gt; &lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;org.eclipse.equinox.registry &lt;/li&gt; &lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;org.eclipse.equinox.common &lt;/li&gt; &lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;org.eclipse.equinox.log &lt;/li&gt; &lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;org.eclipse.osgi.services &lt;/li&gt; &lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;org.eclipse.equinox.event &lt;/li&gt; &lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;org.eclipse.osgi.util &lt;/li&gt; &lt;/ul&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;操作步骤：点击菜单&lt;/span&gt;Run-&gt;Open Run Dialog…&lt;span style="font: 12.0px STHeiti Light"&gt;，在左侧的列表中，找到&lt;/span&gt;OSGi Framework&lt;span style="font: 12.0px STHeiti Light"&gt;，右键单击，&lt;/span&gt;New&lt;span style="font: 12.0px STHeiti Light"&gt;，修改&lt;/span&gt;Name&lt;span style="font: 12.0px STHeiti Light"&gt;为&lt;/span&gt;EventDemo&lt;span style="font: 12.0px STHeiti Light"&gt;，并在&lt;/span&gt;Bundles&lt;span style="font: 12.0px STHeiti Light"&gt;选项卡中，选中以上列举的&lt;/span&gt;Bundle&lt;span style="font: 12.0px STHeiti Light"&gt;，然后点击&lt;/span&gt;Apply&lt;span style="font: 12.0px STHeiti Light"&gt;，点&lt;/span&gt;Run&lt;span style="font: 12.0px STHeiti Light"&gt;。&lt;/span&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px STHeiti Light; color: #9d4510"&gt;在&lt;span style="font: 12.0px Verdana"&gt;Console&lt;/span&gt;中输入&lt;span style="font: 12.0px Verdana"&gt;ss&lt;/span&gt;来查看我们的环境是否成功运行：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/p&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;1&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;2&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;3&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;4&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;5&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;6&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;7&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;8&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;9&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;10&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;11&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;12&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;13&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;14&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;15&lt;/p&gt; &lt;/td&gt; &lt;td valign="top" style="width: 483.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;osgi&gt; ss&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;Framework is launched.&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;id&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;State       Bundle&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;0&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;ACTIVE      org.eclipse.osgi_3.3.1.R33x_v20070828&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;1&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;ACTIVE      org.eclipse.equinox.common_3.3.0.v20070426&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;2&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;ACTIVE      org.eclipse.equinox.log_1.0.100.v20070226&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;3&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;ACTIVE      org.eclipse.equinox.ds_1.0.0.qualifier&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;4&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;ACTIVE      org.eclipse.equinox.registry_3.3.1.R33x_v20070802&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;5&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;ACTIVE      org.eclipse.osgi.services_3.1.200.v20070605&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;6&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;ACTIVE      org.eclipse.equinox.event_1.0.100.v20070516&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;7&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;ACTIVE      org.eclipse.osgi.util_3.1.200.v20070605&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;osgi&gt;&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;OK&lt;span style="font: 12.0px STHeiti Light"&gt;，这样我们的&lt;/span&gt;Spring-OSGi&lt;span style="font: 12.0px STHeiti Light"&gt;的环境就启动好了，现在先关闭它。我们来建立一个&lt;/span&gt;Plug-in Project&lt;span style="font: 12.0px STHeiti Light"&gt;，命名为：&lt;/span&gt;EventPublisher&lt;span style="font: 12.0px STHeiti Light"&gt;。&lt;/span&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;首先新建一个类：&lt;/span&gt;com.demo.eventpublisher.Log&lt;span style="font: 12.0px STHeiti Light"&gt;，代码如下：&lt;/span&gt; &lt;/p&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;1&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;2&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;3&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;4&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;5&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;6&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;7&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;8&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;9&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;10&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;11&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;12&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;13&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;14&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;15&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;16&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;17&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;18&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;19&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;20&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;21&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;22&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;23&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;24&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;25&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;26&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;27&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;28&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;29&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;30&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;31&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;32&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;33&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;34&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;35&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;36&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;37&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;38&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;39&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;40&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;41&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;42&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;43&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;44&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;45&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;46&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;47&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;48&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;49&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;50&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;51&lt;/p&gt; &lt;/td&gt; &lt;td valign="top" style="width: 567.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; com.demo.eventpublisher;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.framework.BundleContext;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.service.log.LogService;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.util.tracker.ServiceTracker;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #2b610f"&gt;/**&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #2b610f"&gt; * Utility class with static methods for logging to LogService, if available &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #2b610f"&gt; * &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #2b610f"&gt; * @version $Revision: 1.1 $&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #2b610f"&gt; */&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;span style="color: #9d4510"&gt; &lt;/span&gt;&lt;b&gt;class&lt;/b&gt;&lt;span style="color: #9d4510"&gt; Log &lt;/span&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; ServiceTracker logTracker;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; Log() &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; init(BundleContext bc) &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;logTracker = &lt;span style="color: #000d7d"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; ServiceTracker(bc, LogService.class.getName(), &lt;span style="color: #000d7d"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;logTracker.open();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; dispose() &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (logTracker != &lt;span style="color: #000d7d"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;) &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;logTracker.close();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;logTracker = &lt;span style="color: #000d7d"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; log(&lt;span style="color: #000d7d"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; level, String message) &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;log(level, message, &lt;span style="color: #000d7d"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;);&lt;span style="font: 12.0px STHeiti Light"&gt;、&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; log(&lt;span style="color: #000d7d"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; level, String message, Throwable e) &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;LogService logService = (LogService) logTracker.getService();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (logService != &lt;span style="color: #000d7d"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;) &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;logService.log(level, message, e);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; info(String message)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;info(message, &lt;span style="color: #000d7d"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; info(String message, Throwable e)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;log(LogService.LOG_INFO, message, e);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #000d7d"&gt;}&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;接下来创建一个循环发布事件的线程：&lt;/span&gt;com.demo.eventpublisher.TimerEvent&lt;span style="font: 12.0px STHeiti Light"&gt;，代码如下：&lt;/span&gt; &lt;/p&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;1&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;2&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;3&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;4&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;5&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;6&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;7&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;8&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;9&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;10&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;11&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;12&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;13&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;14&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;15&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;16&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;17&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;18&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;19&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;20&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;21&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;22&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;23&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;24&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;25&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;26&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;27&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;28&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;29&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;30&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;31&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;32&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;33&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;34&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;35&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;36&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;37&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;38&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;39&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;40&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;41&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;42&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;43&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;44&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;45&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;46&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;47&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;48&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;49&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;50&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;51&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;52&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;53&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;54&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;55&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;56&lt;/p&gt; &lt;/td&gt; &lt;td valign="top" style="width: 560.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; com.demo.eventpublisher;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; java.util.Calendar;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; java.util.Hashtable;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.framework.BundleActivator;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.framework.BundleContext;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.service.event.Event;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.service.event.EventAdmin;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.util.tracker.ServiceTracker;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; TimerEvent &lt;span style="color: #000d7d"&gt;&lt;b&gt;extends&lt;/b&gt;&lt;/span&gt; Thread &lt;span style="color: #000d7d"&gt;&lt;b&gt;implements&lt;/b&gt;&lt;/span&gt; BundleActivator &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    Hashtable time = &lt;span style="color: #000d7d"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; Hashtable();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    ServiceTracker tracker;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; TimerEvent() &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #e02d13"&gt;&lt;span style="color: #9d4510"&gt;        &lt;/span&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;super&lt;/b&gt;&lt;/span&gt;&lt;span style="color: #9d4510"&gt;(&lt;/span&gt;"TimerEvent"&lt;span style="color: #9d4510"&gt;);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; start(BundleContext context) &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        Log.init(context);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        tracker = &lt;span style="color: #000d7d"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; ServiceTracker(context, EventAdmin.class.getName(), &lt;span style="color: #000d7d"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        tracker.open();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        start();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; stop(BundleContext context) &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        interrupt();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        tracker.close();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        Log.dispose();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; run() &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        &lt;span style="color: #000d7d"&gt;&lt;b&gt;while&lt;/b&gt;&lt;/span&gt; (!Thread.interrupted())&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;            &lt;span style="color: #000d7d"&gt;&lt;b&gt;try&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;                Log.info(&lt;span style="color: #e02d13"&gt;"Rasie Event"&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;                Calendar c = Calendar.getInstance();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;                set(c, Calendar.MINUTE, &lt;span style="color: #e02d13"&gt;"minutes"&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;                set(c, Calendar.HOUR, &lt;span style="color: #e02d13"&gt;"hours"&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;                set(c, Calendar.DAY_OF_MONTH, &lt;span style="color: #e02d13"&gt;"day"&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;                set(c, Calendar.MONTH, &lt;span style="color: #e02d13"&gt;"month"&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;                set(c, Calendar.YEAR, &lt;span style="color: #e02d13"&gt;"year"&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;                EventAdmin ea = (EventAdmin) tracker.getService();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;                &lt;span style="color: #000d7d"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (ea != &lt;span style="color: #000d7d"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;                    ea.sendEvent(&lt;span style="color: #000d7d"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; Event(&lt;span style="color: #e02d13"&gt;"com/demo/timer"&lt;/span&gt;, time));&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;                Thread.sleep(60000 - c.get(Calendar.SECOND) * 1000);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;            &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;            &lt;span style="color: #000d7d"&gt;&lt;b&gt;catch&lt;/b&gt;&lt;/span&gt; (InterruptedException e) &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;                &lt;span style="color: #2b610f"&gt;// &lt;/span&gt;&lt;span style="font: 12.0px STHeiti Light; color: #2b610f"&gt;忽略&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;            &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; set(Calendar c, &lt;span style="color: #000d7d"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; field, String key) &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        time.put(key, &lt;span style="color: #000d7d"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; Integer(c.get(field)));&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #000d7d"&gt;}&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;在&lt;/span&gt;Plug-in ManiFest Editor&lt;span style="font: 12.0px STHeiti Light"&gt;中打开&lt;/span&gt;META-INF/MANIFEST.MF&lt;span style="font: 12.0px STHeiti Light"&gt;，如果安装了&lt;/span&gt;PDE&lt;span style="font: 12.0px STHeiti Light"&gt;，将会默认使用&lt;/span&gt;Plug-in ManiFest Editor&lt;span style="font: 12.0px STHeiti Light"&gt;打开。将&lt;/span&gt;Activator&lt;span style="font: 12.0px STHeiti Light"&gt;设置为&lt;/span&gt;com.demo.eventpublisher.TimerEvent&lt;span style="font: 12.0px STHeiti Light"&gt;，此时&lt;/span&gt;MANIFEST.MF&lt;span style="font: 12.0px STHeiti Light"&gt;文件中的内容如下：&lt;/span&gt; &lt;/p&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;1&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;2&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;3&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;4&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;5&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;6&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;7&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;8&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;9&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;10&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;11&lt;/p&gt; &lt;/td&gt; &lt;td valign="top" style="width: 364.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;Manifest-Version: 1.0&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;Bundle-ManifestVersion: 2&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;Bundle-Name: EventPublisher Plug-in&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;Bundle-SymbolicName: EventPublisher&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;Bundle-Version: 1.0.0&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;Bundle-Activator: com.demo.eventpublisher.TimerEvent&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;Import-Package: org.osgi.framework;version=&lt;span style="color: #e02d13"&gt;"1.3.0"&lt;/span&gt;,&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; org.osgi.service.event;version=&lt;span style="color: #e02d13"&gt;"1.1.0"&lt;/span&gt;,&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; org.osgi.service.log;version=&lt;span style="color: #e02d13"&gt;"1.3.0"&lt;/span&gt;,&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; org.osgi.util.tracker;version=&lt;span style="color: #e02d13"&gt;"1.3.2"&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px STHeiti Light; color: #9d4510"&gt;注意：手工写&lt;span style="font: 12.0px Verdana"&gt;MANIFEST.MF&lt;/span&gt;文件时，最后一行一定要有一个回车。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;接下来我们再来建立一个&lt;/span&gt;Plug-in Project&lt;span style="font: 12.0px STHeiti Light"&gt;，命名为&lt;/span&gt;EventHander&lt;span style="font: 12.0px STHeiti Light"&gt;。&lt;/span&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;我们建立一个类，名为：&lt;/span&gt;com.demo.eventhandler.CustomEventHandler&lt;span style="font: 12.0px STHeiti Light"&gt;，代码如下&lt;/span&gt; &lt;/p&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;1&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;2&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;3&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;4&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;5&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;6&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;7&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;8&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;9&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;10&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;11&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;12&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;13&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;14&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;15&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;16&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;17&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;18&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;19&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;20&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;21&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;22&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;23&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;24&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;25&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;26&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;27&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;28&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;29&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;30&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;31&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;32&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;33&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;34&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;35&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;36&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;37&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;38&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;39&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;40&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;41&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;42&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;43&lt;/p&gt; &lt;/td&gt; &lt;td valign="top" style="width: 1211.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; com.demo.eventhandler;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; java.util.Dictionary;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; java.util.Hashtable;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.framework.BundleContext;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.service.event.Event;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.service.event.EventConstants;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.service.event.EventHandler;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; com.demo.internal.Log;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; CustomEventHandler &lt;span style="color: #000d7d"&gt;&lt;b&gt;implements&lt;/b&gt;&lt;/span&gt; EventHandler&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #000d7d"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt; String [] topics = &lt;span style="color: #000d7d"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; String[] &lt;span style="color: #000d7d"&gt;{&lt;/span&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #2b610f"&gt;//        "org/osgi/service/log/LogEntry/LOG_INFO", &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #2b610f"&gt;//        "org/osgi/service/log/LogEntry/LOG_WARNING",&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #2b610f"&gt;//        "org/osgi/framework/ServiceEvent/REGISTERED",&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #2b610f"&gt;//        "org/osgi/framework/ServiceEvent/MODIFIED",&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #2b610f"&gt;//        "org/osgi/framework/ServiceEvent/UNREGISTERING",&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #2b610f"&gt;//        "org/osgi/framework/FrameworkEvent/STARTED",&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #2b610f"&gt;//        "org/osgi/service/log/LogEntry/LOG_ERROR",&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #e02d13"&gt;&lt;span style="color: #9d4510"&gt;        &lt;/span&gt;"com/demo/timer"&lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;span style="color: #9d4510"&gt;; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;    &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; registry(BundleContext context)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        Dictionary d = &lt;span style="color: #000d7d"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; Hashtable(); &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        d.put(EventConstants.EVENT_TOPIC, topics ); &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        context.registerService( EventHandler.class.getName(), this, d ); &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; handleEvent(Event event)&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        &lt;span style="color: #000d7d"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (&lt;span style="color: #e02d13"&gt;"com/acme/timer"&lt;/span&gt;.equals(event.getTopic()))&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;            Log.info(&lt;span style="color: #e02d13"&gt;"Received event, EventTopic "&lt;/span&gt; + event.getTopic() + &lt;span style="color: #e02d13"&gt;" "&lt;/span&gt; + event.getProperty(&lt;span style="color: #e02d13"&gt;"year"&lt;/span&gt;) + &lt;span style="color: #e02d13"&gt;"-"&lt;/span&gt; + event.getProperty(&lt;span style="color: #e02d13"&gt;"month"&lt;/span&gt;) + &lt;span style="color: #e02d13"&gt;"-"&lt;/span&gt; + event.getProperty(&lt;span style="color: #e02d13"&gt;"day"&lt;/span&gt;));&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        &lt;span style="color: #000d7d"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;            Log.info(&lt;span style="color: #e02d13"&gt;"Received event, EventTopic "&lt;/span&gt; + event.getTopic());&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;  &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #000d7d"&gt;}&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;我们再建立一个&lt;/span&gt;Activator&lt;span style="font: 12.0px STHeiti Light"&gt;，名为：&lt;/span&gt;com.demo.eventhandler.internal.Activator&lt;span style="font: 12.0px STHeiti Light"&gt;，代码如下&lt;/span&gt; &lt;/p&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;1&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;2&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;3&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;4&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;5&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;6&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;7&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;8&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;9&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;10&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;11&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;12&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;13&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;14&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;15&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;16&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;17&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;18&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;19&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;20&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;21&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #555555"&gt;22&lt;/p&gt; &lt;/td&gt; &lt;td valign="top" style="width: 469.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; com.demo.internal;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.framework.BundleActivator;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.framework.BundleContext;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; com.demo.eventhandler.CustomEventHandler;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;&lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; Activator &lt;span style="color: #000d7d"&gt;&lt;b&gt;implements&lt;/b&gt;&lt;/span&gt; BundleActivator&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #000d7d"&gt;{&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; start(BundleContext context) &lt;span style="color: #000d7d"&gt;&lt;b&gt;throws&lt;/b&gt;&lt;/span&gt; Exception&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        Log.init(context);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        CustomEventHandler eventhandler = &lt;span style="color: #000d7d"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; CustomEventHandler();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        eventhandler.registry(context);&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #000d7d"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; stop(BundleContext context) &lt;span style="color: #000d7d"&gt;&lt;b&gt;throws&lt;/b&gt;&lt;/span&gt; Exception&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;        Log.dispose();&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt;    &lt;span style="color: #000d7d"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #000d7d"&gt;}&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px STHeiti Light; color: #9d4510"&gt;&lt;span style="font: 12.0px Verdana"&gt;OK&lt;/span&gt;，我们将新建立的这两个&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;加入到运行环境中，&lt;span style="font: 12.0px Verdana"&gt;Run&lt;/span&gt;。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px STHeiti Light; color: #9d4510"&gt;在&lt;span style="font: 12.0px Verdana"&gt;Console&lt;/span&gt;中等待大约&lt;span style="font: 12.0px Verdana"&gt;60&lt;/span&gt;秒后，输入&lt;span style="font: 12.0px Verdana"&gt;log&lt;/span&gt;后可以在最后找到如下日志信息：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px STHeiti; color: #666666"&gt;引用原文&lt;span style="font: 12.0px Verdana"&gt;&lt;b&gt;:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; background-color: #808080; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #519698; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #519698"&gt;&gt;Info [1] Rasie Event initial@reference:file:../../../../../../../../Documents/workspace/EventPublisher/ &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #519698"&gt;&gt;Info [7] Received event, EventTopic com/demo/timer initial@reference:file:../../../../../../../../Documents/workspace/ConsumerServiceDemo/ &lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 6.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; background-color: #808080; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510; min-height: 15.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Verdana; color: #9d4510"&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;瞧，我们已经收到打印出来的事件接收信息了&lt;/span&gt; Received event, EventTopic com/demo/timer&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34320290-2295646460045990953?l=coolflyreg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://coolflyreg.blogspot.com/feeds/2295646460045990953/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34320290&amp;postID=2295646460045990953' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/2295646460045990953'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/2295646460045990953'/><link rel='alternate' type='text/html' href='http://coolflyreg.blogspot.com/2008/07/javaosgievent.html' title='[JAVA]OSGi开发之Event:事件处理'/><author><name>coolflyr_reg</name><uri>http://www.blogger.com/profile/13114315753504344218</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_oqeis3g1k2A/SW1fbBJKK3I/AAAAAAAABiw/oQV4_U7uBwM/S220/120_136124_2.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34320290.post-8101647038815881502</id><published>2008-06-25T15:14:00.005+08:00</published><updated>2008-07-12T22:10:07.176+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><title type='text'>[JAVA] OSGi入门：Declarative Services和依赖[译]</title><content type='html'>&lt;div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-align: justify; font: normal normal normal 10.5px/normal SimSun; "&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-style-span"  style="color:#AF3E00;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;欢迎回来&lt;span style="font: 12.0px Verdana"&gt;EclipseZone"OSGi&lt;/span&gt;入门&lt;span style="font: 12.0px Verdana"&gt;"&lt;/span&gt;系列讲座。进入到今天这节课之前我希望你能找到所有讲座以前的部分在&lt;a href="http://neilbartlett.name/blog/osgi-articles/"&gt;&lt;span style="text-decoration: underline ; color:#d96b18;"&gt;我的个人博客&lt;/span&gt;&lt;/a&gt;上。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;上次我们首次接触了&lt;span style="font: 12.0px Verdana"&gt;Declarative Service&lt;/span&gt;。这次我们将看看&lt;span style="font: 12.0px Verdana"&gt;Declarative Service&lt;/span&gt;的消费者那边。记得以前我们注册了一个服务在&lt;span style="font: 12.0px Verdana"&gt;java.lang.Runnable&lt;/span&gt;接口下；现在我们将创建一个组件依赖在这个服务上。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;正如讨论的那样，&lt;span style="font: 12.0px Verdana"&gt;Declarative Services&lt;/span&gt;规范是所有关于让你聚焦于你的代码的应用逻辑上，而不是在以前的课程中写的&lt;span style="font: 12.0px Verdana"&gt;OSGi"glue"&lt;/span&gt;代码。鉴于此，我们只是潜入到代码中，但是因此我们需要创建一个项目。以下是最后课程中同样的步骤，但是使用&lt;span style="font: 12.0px Verdana"&gt;"SimpleImporter"&lt;/span&gt;作为项目名称。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;现在从你的浏览器复制以下代码并粘帖到新建的&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;工程中的&lt;span style="font: 12.0px Verdana"&gt;src&lt;/span&gt;文件夹里面：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;13&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;14&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;15&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;16&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;17&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;18&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;19&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;20&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;21&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;22&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;23&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;24&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;25&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;26&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 469.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; org.example.ds;&lt;/div&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier;  min-height: 14.0pxcolor:#9d4510;"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.eclipse.osgi.framework.console.CommandInterpreter;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.eclipse.osgi.framework.console.CommandProvider;&lt;/div&gt;&lt;p color="#9d4510" style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier;  min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; SampleCommandProvider1 &lt;span style="color:#000d7d;"&gt;&lt;b&gt;implements&lt;/b&gt;&lt;/span&gt; CommandProvider &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;p color="#9d4510" style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier;  min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; Runnable runnable;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;synchronized&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; setRunnable(Runnable r) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;runnable = r;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;synchronized&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; unsetRunnable(Runnable r) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;runnable = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;synchronized&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; _run(CommandInterpreter ci) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt;(runnable != &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;runnable.run();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;}&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;b&gt;else&lt;/b&gt;&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;{&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;ci.println(&lt;/span&gt;"Error, no Runnable available"&lt;span style="color:#9d4510;"&gt;);&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; String getHelp() &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;"\trun - execute a Runnable service"&lt;span style="color:#9d4510;"&gt;;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;这个类实现了&lt;span style="font: 12.0px Verdana"&gt;CommandProvider&lt;/span&gt;接口，这是个用来扩展当你运行&lt;span style="font: 12.0px Verdana"&gt;Equinox&lt;/span&gt;的时候在&lt;span style="font: 12.0px Verdana"&gt;"osgi&gt;"&lt;/span&gt;提示符中有效的命令集合。写一个&lt;span style="font: 12.0px Verdana"&gt;CommandProvider&lt;/span&gt;的原因是用来提供一个方便我们测试代码互动性的方法。在&lt;span style="font: 12.0px Verdana"&gt;IBM developerWork&lt;/span&gt;上的&lt;a href="http://mea-bloga.blogspot.com/"&gt;&lt;span style="font: 12.0px Verdana; text-decoration: underline ; color:#d96b18;"&gt;Chris Aniszczyk&lt;/span&gt;&lt;/a&gt;的&lt;a href="http://www.ibm.com/developerworks/library/os-ecl-osgiconsole/index.html"&gt;&lt;span style="text-decoration: underline ; color:#d96b18;"&gt;文章&lt;/span&gt;&lt;/a&gt;中有更多命令提供器的详细讨论。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;注意我们在这个类中没有调用任何&lt;span style="font: 12.0px Verdana"&gt;OSGi API&lt;/span&gt;，事实上我们甚至无需从&lt;span style="font: 12.0px Verdana"&gt;org.osgi.*&lt;/span&gt;包导入任何东西。我们依赖的这个服务&lt;span style="font: 12.0px Verdana"&gt;——&lt;/span&gt;在这个情况中，一个&lt;span style="font: 12.0px Verdana"&gt;java.lang.Runnable&lt;/span&gt;的实例&lt;span style="font: 12.0px Verdana"&gt;——&lt;/span&gt;我们通过&lt;span style="font: 12.0px Verdana"&gt;setRunnable&lt;/span&gt;方法提供使用并使用&lt;span style="font: 12.0px Verdana"&gt;unsetRunnable&lt;/span&gt;方法带走它。我们可以认为这是一种&lt;a href="http://en.wikipedia.org/wiki/Dependency_injection"&gt;&lt;span style="text-decoration: underline ; color:#d96b18;"&gt;依赖注入&lt;/span&gt;&lt;/a&gt;的形式。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;其他的两个方法，&lt;span style="font: 12.0px Verdana"&gt;getHelp&lt;/span&gt;和&lt;span style="font: 12.0px Verdana"&gt;_run&lt;/span&gt;是为命令提供器实现的。没错，&lt;span style="font: 12.0px Verdana"&gt;"_run"&lt;/span&gt;是个有趣的名称，它以下划线开头，但是那仅仅是一个&lt;span style="font: 12.0px Verdana"&gt;Equinox&lt;/span&gt;控制台&lt;span style="font: 12.0px Verdana"&gt;API&lt;/span&gt;的奇怪的特性，并且&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;或者&lt;span style="font: 12.0px Verdana"&gt;Declarative Service&lt;/span&gt;什么都不做。使用下划线开头模式的方法在&lt;span style="font: 12.0px Verdana"&gt;Equinox&lt;/span&gt;控制台中变成命令，所以通过提供一个叫做&lt;span style="font: 12.0px Verdana"&gt;_run&lt;/span&gt;的方法我们添加了一个命令&lt;span style="font: 12.0px Verdana"&gt;"run"&lt;/span&gt;。另外注意的事情关于这个类我们需要关心确保&lt;span style="font: 12.0px Verdana"&gt;runnable&lt;/span&gt;字段能够以线程安全的方式被更新和访问。线程安全在&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;中&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;相当重要，因为它本质上就是多线程的。坦率的说，我们始终应该把我们的代码写成线程安全的。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;如以前一样，我们需要提供一个&lt;/span&gt;XML&lt;span style="font: 12.0px STHeiti Light"&gt;文件包含&lt;/span&gt;DS&lt;span style="font: 12.0px STHeiti Light"&gt;声明得到这些。复制以下到&lt;/span&gt;OSGI-INF/commandprovider1.xml&lt;span style="font: 12.0px STHeiti Light"&gt;到你的&lt;/span&gt;plug-in&lt;span style="font: 12.0px STHeiti Light"&gt;项目中：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;13&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 623.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&amp;lt;?xml version=&lt;span style="color:#e02d13;"&gt;"1.0"&lt;/span&gt; encoding=&lt;span style="color:#e02d13;"&gt;"UTF-8"&lt;/span&gt;?&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&amp;lt;component name=&lt;/span&gt;"commandprovider1"&lt;span style="color:#9d4510;"&gt;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;implementation class=&lt;/span&gt;"org.example.ds.SampleCommandProvider1"&lt;span style="color:#9d4510;"&gt;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;service&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&amp;lt;provide interface=&lt;/span&gt;"org.eclipse.osgi.framework.console.CommandProvider"&lt;span style="color:#9d4510;"&gt;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;/service&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;reference name=&lt;span style="color:#e02d13;"&gt;"RUNNABLE"&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;interface=&lt;/span&gt;"java.lang.Runnable"&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;bind=&lt;/span&gt;"setRunnable"&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;unbind=&lt;/span&gt;"unsetRunnable"&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;cardinality=&lt;span style="color:#e02d13;"&gt;"0..1"&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;policy=&lt;span style="color:#e02d13;"&gt;"dynamic"&lt;/span&gt;/&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&amp;lt;/component&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;这是我们上次叙述疏忽了的另一个重要的步骤。&lt;span style="font: 12.0px Verdana"&gt;(&lt;/span&gt;感谢&lt;span style="font: 12.0px Verdana"&gt;Seamus Venasse&lt;/span&gt;指出来。&lt;span style="font: 12.0px Verdana"&gt;)&lt;/span&gt;你需要编辑&lt;span style="font: 12.0px Verdana"&gt;build.properties&lt;/span&gt;文件到在你的&lt;span style="font: 12.0px Verdana"&gt;plug-in&lt;/span&gt;项目中，并且检查&lt;span style="font: 12.0px Verdana"&gt;OSGI-INF&lt;/span&gt;文件夹是否选中。当&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;使用&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;的导出向导导出时必须保证文件夹被包含在里面，或者使用&lt;span style="font: 12.0px Verdana"&gt;PDE Build&lt;/span&gt;来建立。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;那么我们需要添加下面一行到&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;的&lt;span style="font: 12.0px Verdana"&gt;manifest&lt;/span&gt;中：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 336.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Service-Component: OSGI-INF/commandprovider1.xml&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;这个定义有我们之前看过的同样的两个元素，&lt;span style="font: 12.0px Verdana"&gt;implementation&lt;/span&gt;和&lt;span style="font: 12.0px Verdana"&gt;service&lt;/span&gt;节点。&lt;span style="font: 12.0px Verdana"&gt;implementation&lt;/span&gt;节点提供实现组件的类的名称，&lt;span style="font: 12.0px Verdana"&gt;service&lt;/span&gt;节点告诉&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;像一个服务那样注册这个组件。这种情况下我们注册到&lt;span style="font: 12.0px Verdana"&gt;CommandProvider&lt;/span&gt;接口下，这个是我们如何让&lt;span style="font: 12.0px Verdana"&gt;Equinox&lt;/span&gt;控制台获知关于我们的命令提供器的存在。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;下个节点叫做&lt;span style="font: 12.0px Verdana"&gt;reference&lt;/span&gt;，是我们以前没有见过的&lt;span style="font: 12.0px Verdana"&gt;——&lt;/span&gt;它对&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;声明了我们的组件已经依赖在一个服务上。&lt;span style="font: 12.0px Verdana"&gt;name&lt;/span&gt;属性只是一个依赖的名称的随意的字符串&lt;span style="font: 12.0px Verdana"&gt;(&lt;/span&gt;我们仍然不需要担心这个是用来干什么的&lt;span style="font: 12.0px Verdana"&gt;)&lt;/span&gt;并且&lt;span style="font: 12.0px Verdana"&gt;interface&lt;/span&gt;属性指定我们依赖的接口的名称。&lt;span style="font: 12.0px Verdana"&gt;bind&lt;/span&gt;属性是当一个服务有效时将调用实现的类中的一个方法名称，换句话说，当一个&lt;span style="font: 12.0px Verdana"&gt;Runnable&lt;/span&gt;服务用&lt;span style="font: 12.0px Verdana"&gt;Service Registry&lt;/span&gt;注册了，&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;将获取一个此新服务的引用并提供使用这个指定的方法提供给我们的组件。同样的&lt;span style="font: 12.0px Verdana"&gt;unbind&lt;/span&gt;属性是当我们使用的一个服务变成无效的时候通过&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;调用它。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px Verdana"&gt;Cardinality&lt;/span&gt;属性显示了&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;真正的强大。这个属性控制是否这个依赖是可选的或是必需的，并且是否它是单独的或多个的。可能的值有：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal STHeiti; color: rgb(102, 102, 102); "&gt;引用原文&lt;span style="font: 12.0px Verdana"&gt;&lt;b&gt;:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); background-color: rgb(128, 128, 128); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(81, 150, 152); "&gt;? 0..1&lt;span style="font: 12.0px STHeiti Light"&gt;：可选和单个，&lt;/span&gt;"0&lt;span style="font: 12.0px STHeiti Light"&gt;或&lt;/span&gt;1" &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(81, 150, 152); "&gt;&lt;span style="font: 12.0px Verdana"&gt;? 1..1&lt;/span&gt;：有且仅有一个，&lt;span style="font: 12.0px Verdana"&gt;"&lt;/span&gt;只有一个&lt;span style="font: 12.0px Verdana"&gt;" &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(81, 150, 152); "&gt;? 0..n&lt;span style="font: 12.0px STHeiti Light"&gt;：可选和多个，&lt;/span&gt;"0&lt;span style="font: 12.0px STHeiti Light"&gt;到多&lt;/span&gt;" &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(81, 150, 152); "&gt;&lt;span style="font: 12.0px Verdana"&gt;? 1..n&lt;/span&gt;：必须或者多个，&lt;span style="font: 12.0px Verdana"&gt;"0&lt;/span&gt;到多&lt;span style="font: 12.0px Verdana"&gt;"&lt;/span&gt;或&lt;span style="font: 12.0px Verdana"&gt;"&lt;/span&gt;至少一个&lt;span style="font: 12.0px Verdana"&gt;"&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); background-color: rgb(128, 128, 128); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;在这个例子中我们选择可选和单个，意味着我们的命令提供器能够应付依赖服务变成无效的情况。回来看看&lt;span style="font: 12.0px Verdana"&gt;_run&lt;/span&gt;方法的代码，你可以看到它必须处理检查到&lt;span style="font: 12.0px Verdana"&gt;null&lt;/span&gt;的情况。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;让我们看看如果我们运行了这个&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;会发生什么。如果你的&lt;span style="font: 12.0px Verdana"&gt;SimpleExporterBundle&lt;/span&gt;从上次一直存在，当你在命令行提示符&lt;span style="font: 12.0px Verdana"&gt;osgi&gt;&lt;/span&gt;输入&lt;span style="font: 12.0px Verdana"&gt;"run"&lt;/span&gt;你将看到如下响应：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 175.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Hello from SampleRunnable&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;太好了！这次确定了我们成功的导入了上节课我们写的&lt;span style="font: 12.0px Verdana"&gt;Runnable&lt;/span&gt;服务。现在试着使用&lt;span style="font: 12.0px Verdana"&gt;"stop"&lt;/span&gt;命令关闭&lt;span style="font: 12.0px Verdana"&gt;SampleExporter&lt;/span&gt;的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;。当你再次输入&lt;span style="font: 12.0px Verdana"&gt;"run"&lt;/span&gt;命令，你将看到：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 196.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Error, no Runnable available&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;通知的意思是&lt;span style="font: 12.0px Verdana"&gt;Runnable&lt;/span&gt;服务消失了，并且调用了我们的&lt;span style="font: 12.0px Verdana"&gt;unsetRunnable&lt;/span&gt;方法让我们知道。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;再看看&lt;span style="font: 12.0px Verdana"&gt;cardinality&lt;/span&gt;属性，如果我们改变成&lt;span style="font: 12.0px Verdana"&gt;"1..1"&lt;/span&gt;你认为将会发生什么，例如从一个可选到必须的依赖切换过来？试着换下并重启动&lt;span style="font: 12.0px Verdana"&gt;Equinox&lt;/span&gt;。如果&lt;span style="font: 12.0px Verdana"&gt;SampleExporter&lt;/span&gt;的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;是激活的当我们输入&lt;span style="font: 12.0px Verdana"&gt;"run"&lt;/span&gt;之后我们将看到和之前一样的信息&lt;span style="font: 12.0px Verdana"&gt;"Hello from SampleRunnable"&lt;/span&gt;。但是，如果&lt;span style="font: 12.0px Verdana"&gt;SampleExporter&lt;/span&gt;是未激活的之后我们将看到一个与之前非常不同的错误信息。事实上，我们将看到&lt;span style="font: 12.0px Verdana"&gt;Equinox&lt;/span&gt;的控制台帮助信息，那是对于未被识别的命令的标准响应。这表示我们的命令提供其它自己已经通过&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;注销了！直到组件有一个必须的依赖前都不会满足，&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;只能被迫撤消它提供的任何服务。反过来说&lt;span style="font: 12.0px Verdana"&gt;Equinox&lt;/span&gt;控制台忘掉了&lt;span style="font: 12.0px Verdana"&gt;"run"&lt;/span&gt;命令。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;你可能会对&lt;span style="font: 12.0px Verdana"&gt;policy&lt;/span&gt;属性感到奇怪，知道现在我仍然没有提及。这个值是&lt;span style="font: 12.0px Verdana"&gt;"static"&lt;/span&gt;或&lt;span style="font: 12.0px Verdana"&gt;"dynamic"&lt;/span&gt;中的一个，它指出是否这个组件能够应付服务的动态切换。如果不是动态的，那么每次目标服务改变了它必须为&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;撤消组件并创建一个新的实例。正如你可能期望的，这相当于一个重量级的方法，最好编码你的组件来支持任何时候可能的动态切换。不幸的是默认值是&lt;span style="font: 12.0px Verdana"&gt;static&lt;/span&gt;，所以你一定要记得明确的设置它为&lt;span style="font: 12.0px Verdana"&gt;dynamic&lt;/span&gt;。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;那么我们看过了可选单一和仅一个，但是什么是多重依赖呢？可能在&lt;span style="font: 12.0px Verdana"&gt;Service Registry&lt;/span&gt;中存在多余一个的&lt;span style="font: 12.0px Verdana"&gt;Runnable&lt;/span&gt;，并且如果我们只绑定它们中间的一个之后选择的那一个我们得到的是任意的。。或许我们喜欢实现一个&lt;span style="font: 12.0px Verdana"&gt;"runall"&lt;/span&gt;命令来运行所有的当前注册了的&lt;span style="font: 12.0px Verdana"&gt;Runnable&lt;/span&gt;。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;如果我们改变&lt;span style="font: 12.0px Verdana"&gt;cardinality&lt;/span&gt;为&lt;span style="font: 12.0px Verdana"&gt;"0..n"&lt;/span&gt;的话将会发生什么？在某一方面它将总是运作：代替只调用一次&lt;span style="font: 12.0px Verdana"&gt;setRunnable&lt;/span&gt;方法，&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;将为每个&lt;span style="font: 12.0px Verdana"&gt;Registry&lt;/span&gt;中的&lt;span style="font: 12.0px Verdana"&gt;Runnable&lt;/span&gt;实例调用&lt;span style="font: 12.0px Verdana"&gt;setRunnable&lt;/span&gt;一次。问题是我们写的类将会混乱。代替设置一个单独的&lt;span style="font: 12.0px Verdana"&gt;Runnable&lt;/span&gt;字段，我们需要储存&lt;span style="font: 12.0px Verdana"&gt;Runnable&lt;/span&gt;到一个集合。在这里类的版本有细小的改变，即将重新复制并粘贴到你的项目的&lt;span style="font: 12.0px Verdana"&gt;src&lt;/span&gt;文件夹中：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;13&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;14&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;15&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;16&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;17&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;18&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;19&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;20&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;21&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;22&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;23&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;24&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;25&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;26&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;27&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;28&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 483.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; org.example.ds;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; java.util.*;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.eclipse.osgi.framework.console.CommandInterpreter;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.eclipse.osgi.framework.console.CommandProvider;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; SampleCommandProvider2 &lt;span style="color:#000d7d;"&gt;&lt;b&gt;implements&lt;/b&gt;&lt;/span&gt; CommandProvider &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; List&amp;lt;Runnable&gt; runnables =&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;Collections.synchronizedList(&lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; ArrayList&amp;lt;Runnable&gt;());&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; addRunnable(Runnable r) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;runnables.add(r);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; removeRunnable(Runnable r) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;runnables.remove(r);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; _runall(CommandInterpreter ci) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;synchronized&lt;/b&gt;&lt;/span&gt;(runnables) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/span&gt;(Runnable r : runnables) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;r.run();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; String getHelp() &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;"\trunall - Run all registered Runnables"&lt;span style="color:#9d4510;"&gt;;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;现在创建&lt;/span&gt;OSGI-INF/commandprovider2.xml&lt;span style="font: 12.0px STHeiti Light"&gt;并复制以下内容：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;13&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 623.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&amp;lt;?xml version=&lt;span style="color:#e02d13;"&gt;"1.0"&lt;/span&gt; encoding=&lt;span style="color:#e02d13;"&gt;"UTF-8"&lt;/span&gt;?&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&amp;lt;component name=&lt;/span&gt;"commandprovider2"&lt;span style="color:#9d4510;"&gt;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;implementation class=&lt;/span&gt;"org.example.ds.SampleCommandProvider2"&lt;span style="color:#9d4510;"&gt;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;service&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&amp;lt;provide interface=&lt;/span&gt;"org.eclipse.osgi.framework.console.CommandProvider"&lt;span style="color:#9d4510;"&gt;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;/service&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;reference name=&lt;span style="color:#e02d13;"&gt;"RUNNABLE"&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;interface=&lt;/span&gt;"java.lang.Runnable"&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;bind=&lt;/span&gt;"addRunnable"&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;unbind=&lt;/span&gt;"removeRunnable"&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;cardinality=&lt;span style="color:#e02d13;"&gt;"0..n"&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;policy=&lt;span style="color:#e02d13;"&gt;"dynamic"&lt;/span&gt;/&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&amp;lt;/component&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;最终添加这个文件到&lt;/span&gt;manifest&lt;span style="font: 12.0px STHeiti Light"&gt;的&lt;/span&gt;Service-Component&lt;span style="font: 12.0px STHeiti Light"&gt;头去，看起来就像这样：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 343.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Service-Component: OSGI-INF/commandprovider1.xml,&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;  OSGI-INF/commandprovider2.xml&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;这个声明同之前的一样不可缺少，除了我们对&lt;span style="font: 12.0px Verdana"&gt;bind&lt;/span&gt;和&lt;span style="font: 12.0px Verdana"&gt;unbind&lt;/span&gt;方法重命名并改变&lt;span style="font: 12.0px Verdana"&gt;cardinality&lt;/span&gt;为&lt;span style="font: 12.0px Verdana"&gt;"0..n"&lt;/span&gt;。就像练习一样，试着注册一些附加的&lt;span style="font: 12.0px Verdana"&gt;Runnable&lt;/span&gt;服务并检查&lt;span style="font: 12.0px Verdana"&gt;"runall"&lt;/span&gt;命令执行它们全部。下次，如果我们改变&lt;span style="font: 12.0px Verdana"&gt;cardinality&lt;/span&gt;为&lt;span style="font: 12.0px Verdana"&gt;"1..n"&lt;/span&gt;你认为会将会发生什么呢？尝试着验证你的想象。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;That's all for this lesson. Remember that the OSGi Alliance Community Event is happening next week in Munich, Germany, and I believe it's still not too late to register . See you there! &lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34320290-8101647038815881502?l=coolflyreg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://coolflyreg.blogspot.com/feeds/8101647038815881502/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34320290&amp;postID=8101647038815881502' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/8101647038815881502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/8101647038815881502'/><link rel='alternate' type='text/html' href='http://coolflyreg.blogspot.com/2008/06/java-osgideclarative-services.html' title='[JAVA] OSGi入门：Declarative Services和依赖[译]'/><author><name>coolflyr_reg</name><uri>http://www.blogger.com/profile/13114315753504344218</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_oqeis3g1k2A/SW1fbBJKK3I/AAAAAAAABiw/oQV4_U7uBwM/S220/120_136124_2.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34320290.post-6645625663629519742</id><published>2008-06-25T15:14:00.004+08:00</published><updated>2008-07-12T22:10:07.177+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><title type='text'>[JAVA]OSGi入门：介绍Declarative Services[译]</title><content type='html'>&lt;div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-align: justify; font: normal normal normal 10.5px/normal SimSun; "&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-style-span"  style="color:#AF3E00;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;欢迎来到&lt;span style="font: 12.0px Verdana"&gt;"OSGi&lt;/span&gt;入门&lt;span style="font: 12.0px Verdana"&gt;"&lt;/span&gt;系列的下个部分。这个部分十分的有趣，因为我们将开始尝试使用&lt;span style="font: 12.0px Verdana"&gt;Declarative Services&lt;/span&gt;。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px Verdana"&gt;Declarative Service(&lt;/span&gt;或者&lt;span style="font: 12.0px Verdana"&gt;"DS")&lt;/span&gt;规范是&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;最新的一个部分，并且它来自于跨越&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;将服务配置到一起的结果。并非这个任务困难&lt;span style="font: 12.0px Verdana"&gt;——&lt;/span&gt;正如我希望我以前讲课中展示的&lt;span style="font: 12.0px Verdana"&gt;——&lt;/span&gt;它需要相当数量的样板代码。它也要求你对内容的条理很谨慎，也就是说你很容易搬起石头砸自己的脚。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;早期试图解决此问题的是一个叫做&lt;span style="font: 12.0px Verdana"&gt;Service Binder&lt;/span&gt;的工具。由&lt;span style="font: 12.0px Verdana"&gt; &lt;a href="http://www.humbertocervantes.net/"&gt;&lt;span style="text-decoration: underline ; color:#d96b18;"&gt;Humberto Cervantes &lt;/span&gt;&lt;/a&gt;&lt;/span&gt;和&lt;span style="font: 12.0px Verdana"&gt; &lt;a href="http://www-adele.imag.fr/users/Richard.Hall"&gt;&lt;span style="text-decoration: underline ; color:#d96b18;"&gt;Richard Hall &lt;/span&gt;&lt;/a&gt;&lt;/span&gt;开发的工具。&lt;span style="font: 12.0px Verdana"&gt;Service Binder&lt;/span&gt;引入了&lt;span style="font: 12.0px STHeiti"&gt;自动化的服务依赖关系管理&lt;/span&gt;，允许开发人员可以集中精力编写他们的服务。服务之间的配置通过声明处理，并且声明都写在&lt;span style="font: 12.0px Verdana"&gt;XML&lt;/span&gt;中。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;这个&lt;/span&gt;Declarative Service&lt;span style="font: 12.0px STHeiti Light"&gt;规范是从&lt;/span&gt;Service Binder&lt;span style="font: 12.0px STHeiti Light"&gt;进化而来，并且是&lt;/span&gt;OSGi&lt;span style="font: 12.0px STHeiti Light"&gt;的&lt;/span&gt;4.0&lt;span style="font: 12.0px STHeiti Light"&gt;版本的一个标准部分。那么，让我们看看它能做什么。&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;正如我在课程的上一个部分叙述的，我厌倦了在命令行做任何事情：从这点上，我将使用&lt;span style="font: 12.0px Verdana"&gt;Eclipse SDK&lt;/span&gt;。请记住我所介绍的事实上并不依赖&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;。虽然&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;对我们有或多或少的帮助，不过没什么黑色魔法，所以我们在这里看到的任何东西在&lt;span style="font: 12.0px Verdana"&gt;NetBeans&lt;/span&gt;、&lt;span style="font: 12.0px Verdana"&gt;IntelliJ&lt;/span&gt;甚至在老旧的&lt;span style="font: 12.0px Verdana"&gt;vi&lt;/span&gt;上都是完全可行的。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;第一件事，我们需要下载&lt;span style="font: 12.0px Verdana"&gt;Declarative Services&lt;/span&gt;的&lt;span style="font: 12.0px Verdana"&gt;Equinox&lt;/span&gt;实现。假如你使用当前稳定的&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;版本是&lt;span style="font: 12.0px Verdana"&gt;3.2.2&lt;/span&gt;，那就从&lt;a href="http://download.eclipse.org/eclipse/equinox/drops/R-3.2.2-200702121330/download.php?dropFile=org.eclipse.equinox.ds_1.0.0.v20060601a.jar"&gt;&lt;span style="text-decoration: underline ; color:#d96b18;"&gt;这里&lt;/span&gt;&lt;/a&gt;下载。如果你使用不同的版本，你需要从顶层的&lt;a href="http://download.eclipse.org/eclipse/equinox"&gt;&lt;span style="font: 12.0px Verdana; text-decoration: underline ; color:#d96b18;"&gt;Equinox&lt;/span&gt;&lt;span style="text-decoration: underline ; color:#d96b18;"&gt;下载页&lt;/span&gt;&lt;/a&gt;找到这个版本，并下载&lt;span style="font: 12.0px Verdana"&gt;org.eclipse.equinox.ds_x.x.x_xxxxx.jar&lt;/span&gt;文件。把下载下来的文件放到你的&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;安装目录的&lt;span style="font: 12.0px Verdana"&gt;plugins&lt;/span&gt;下，并重启&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;。事实上，如果你已经对&lt;span style="font: 12.0px Verdana"&gt;Eclipse Plug-in&lt;/span&gt;开发有一点点了解，你可以把这个&lt;span style="font: 12.0px Verdana"&gt;jar&lt;/span&gt;文件放入你的目标平台文件夹下。如果你不知道什么是&lt;span style="font: 12.0px Verdana"&gt;"&lt;/span&gt;目标平台&lt;span style="font: 12.0px Verdana"&gt;"&lt;/span&gt;，不用担心，只要把这个&lt;span style="font: 12.0px Verdana"&gt;jar&lt;/span&gt;放到&lt;span style="font: 12.0px Verdana"&gt;plugins&lt;/span&gt;目录下就可以了。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;现在，我们将创建一个新的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;。做这些事情，我们使用&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;中的&lt;span style="font: 12.0px Verdana"&gt;Plug-in&lt;/span&gt;项目向导来创建一个项目：&lt;span style="font: 12.0px Verdana"&gt;[list=decimal] &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;从主菜单，选择&lt;/span&gt;File-&gt;New-&gt;Project&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;选择&lt;/span&gt;Plug-in Project&lt;span style="font: 12.0px STHeiti Light"&gt;并单击下一步&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;输入项目名称：&lt;/span&gt;SimpleExporter&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;在底部，&lt;/span&gt;"This plug-in is targeted to run with"&lt;span style="font: 12.0px STHeiti Light"&gt;文字下面，选择&lt;/span&gt;"an OSGi framework"&lt;span style="font: 12.0px STHeiti Light"&gt;之后在下拉框中选择&lt;/span&gt;"standard"&lt;span style="font: 12.0px STHeiti Light"&gt;。这一步不是绝对必须的，它只是防止我们使用盒外无效的其他&lt;/span&gt;OSGi&lt;span style="font: 12.0px STHeiti Light"&gt;框架实现的特性。&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;单击下一步。在向导接下来的页面中，取消选中的&lt;span style="font: 12.0px Verdana"&gt;"Generate an activator"&lt;/span&gt;复选框。单击结束&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;[/list]&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;我们现在有个空的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;项目，所以我们需要添加一些代码。为了尽可能的简单，我们将提供一个使用了在所有的&lt;span style="font: 12.0px Verdana"&gt;Java Runtime&lt;/span&gt;中都有效的接口：&lt;span style="font: 12.0px Verdana"&gt;java.lang.Runnable&lt;/span&gt;，使用一个顺手的小的&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;快捷方式，仅仅从你的浏览器复制下面的代码，然后选择&lt;span style="font: 12.0px Verdana"&gt;SampleExporter&lt;/span&gt;项目中的&lt;span style="font: 12.0px Verdana"&gt;src&lt;/span&gt;文件夹并点击&lt;span style="font: 12.0px Verdana"&gt;Edit -&gt; Paste&lt;/span&gt;。&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;将为你创建包和源文件。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 448.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; org.example.ds;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; SampleRunnable &lt;span style="color:#000d7d;"&gt;&lt;b&gt;implements&lt;/b&gt;&lt;/span&gt; Runnable &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;public&lt;/b&gt;&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;b&gt;void&lt;/b&gt;&lt;span style="color:#9d4510;"&gt; run() &lt;/span&gt;{&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;System.out.println(&lt;/span&gt;"Hello from SampleRunnable"&lt;span style="color:#9d4510;"&gt;);&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;到目前为止我们没有看到任何新东西，但是，接下来会有趣些：我们将创建一个&lt;span style="font: 12.0px Verdana"&gt;XML&lt;/span&gt;文件来声明&lt;span style="font: 12.0px Verdana"&gt;SampleRunnable&lt;/span&gt;为一个服务。在顶级目录下创建一个名为&lt;span style="font: 12.0px Verdana"&gt;OSGI-INF&lt;/span&gt;的文件夹，并复制下面的例子到文件&lt;span style="font: 12.0px Verdana"&gt;samplerunnable.xml&lt;/span&gt;中：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 441.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&amp;lt;?xml version=&lt;span style="color:#e02d13;"&gt;"1.0"&lt;/span&gt; encoding=&lt;span style="color:#e02d13;"&gt;"UTF-8"&lt;/span&gt;?&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&amp;lt;component name=&lt;span style="color:#e02d13;"&gt;"samplerunnable"&lt;/span&gt;&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;implementation class=&lt;/span&gt;"org.example.ds.SampleRunnable"&lt;span style="color:#9d4510;"&gt;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;service&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&amp;lt;provide interface=&lt;span style="color:#e02d13;"&gt;"java.lang.Runnable"&lt;/span&gt;/&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;/service&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&amp;lt;/component&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;这是我们将看到的&lt;/span&gt;DS&lt;span style="font: 12.0px STHeiti Light"&gt;中简单声明中的一个。它描述了一个提供一个服务到&lt;/span&gt;OSGI Service Registry&lt;span style="font: 12.0px STHeiti Light"&gt;的叫做&lt;/span&gt;"samplerunnable"&lt;span style="font: 12.0px STHeiti Light"&gt;的在&lt;/span&gt;java.lang.Runnable&lt;span style="font: 12.0px STHeiti Light"&gt;下的组件，并且这个组件通过类&lt;/span&gt;org.example.ds.SampleRunnable&lt;span style="font: 12.0px STHeiti Light"&gt;来实现。&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;最后一步是告诉&lt;/span&gt;Declarative Service&lt;span style="font: 12.0px STHeiti Light"&gt;运行时关于这个&lt;/span&gt;XML&lt;span style="font: 12.0px STHeiti Light"&gt;文件的存在。我们为&lt;/span&gt;Bundle&lt;span style="font: 12.0px STHeiti Light"&gt;做这个事情是通过添加一个字段到&lt;/span&gt;MANIFEST.MF&lt;span style="font: 12.0px STHeiti Light"&gt;文件。因此，在编辑器中打开&lt;/span&gt;manifest(&lt;span style="font: 12.0px STHeiti Light"&gt;试着右键点击这个项目并选择&lt;/span&gt;PDE&lt;span style="font: 12.0px STHeiti Light"&gt;工具&lt;/span&gt; -&gt; Open Manifest)&lt;span style="font: 12.0px STHeiti Light"&gt;，跳到名为&lt;/span&gt;"MANIFEST.MF"&lt;span style="font: 12.0px STHeiti Light"&gt;的标签，这允许我们直接编辑&lt;/span&gt;manifest&lt;span style="font: 12.0px STHeiti Light"&gt;的文本内容。添加下面的一行：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 322.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Service-Component: OSGI-INF/samplerunnable.xml&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;然后保存这个文件。正如在上个部分中说的，&lt;span style="font: 12.0px Verdana"&gt;manifest&lt;/span&gt;的最后一个空行是非常重要的，但是不像以前，如果你忘记了，你将从&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;获得一个错误信息。&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;在走的更远之前，让我们运行&lt;span style="font: 12.0px Verdana"&gt;Equniox&lt;/span&gt;来检查这些工作。在&lt;span style="font: 12.0px Verdana"&gt;Run&lt;/span&gt;菜单中选择&lt;span style="font: 12.0px Verdana"&gt;"Run…"&lt;/span&gt;。对话框打开后，在左边的树形列表中选择&lt;span style="font: 12.0px Verdana"&gt;"Equniox OSGi Framework"&lt;/span&gt;，然后点击&lt;span style="font: 12.0px Verdana"&gt;New&lt;/span&gt;按钮。如果你是一个有经验的&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;用户但是没有做过&lt;span style="font: 12.0px Verdana"&gt;OSGI&lt;/span&gt;开发，这个对话框可能看上去有些陌生。第一个标签是&lt;span style="font: 12.0px Verdana"&gt;Bundles&lt;/span&gt;，允许我们选择哪些&lt;span style="font: 12.0px Verdana"&gt;Bundles&lt;/span&gt;将包含在运行配置中，并且是否我们将在启动时便初始化。要获得最小集合，点击&lt;span style="font: 12.0px Verdana"&gt;Deselect All&lt;/span&gt;并仅对以下&lt;span style="font: 12.0px Verdana"&gt;Bundles&lt;/span&gt;做标记&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;[list=decimal] &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;SampleExporter(underneath Workspace)&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;org.eclipse.equniox.ds(underneath Target Platform)&lt;br /&gt;[/list]&lt;br /&gt;&lt;br /&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;这些是我们感兴趣的&lt;/span&gt;Bundles&lt;span style="font: 12.0px STHeiti Light"&gt;，但是它们有些依赖，所以单击&lt;/span&gt;Add Required Bundles&lt;span style="font: 12.0px STHeiti Light"&gt;来添加那些依赖。所以，更好的主意是选中&lt;/span&gt;"Validate bundles automatically prior to launching"&lt;span style="font: 12.0px STHeiti Light"&gt;。最后，点击&lt;/span&gt;Run&lt;span style="font: 12.0px STHeiti Light"&gt;，并稍等片刻，&lt;/span&gt;osgi&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;提示符将出现在&lt;/span&gt;Eclipse&lt;span style="font: 12.0px STHeiti Light"&gt;控制台中。&lt;/span&gt;OSGi&lt;span style="font: 12.0px STHeiti Light"&gt;框架正在运行，并且你可以使用你以前学过的相同的命令与之交互。&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;那么是否我们的服务被注册了？我么可以通过键入&lt;/span&gt;services&lt;span style="font: 12.0px STHeiti Light"&gt;命令来检查。在服务列表中的某个地方&lt;/span&gt;—&lt;span style="font: 12.0px STHeiti Light"&gt;可能在底部&lt;/span&gt;—&lt;span style="font: 12.0px STHeiti Light"&gt;你将看到如下显示：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 581.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;java.lang.Runnable&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;=&lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;component.name=samplerunnable, component.id=1, service.id=22&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;  Registered by bundle: initial@reference:file:..../SampleExporter/ [5]&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;  No bundles using service.&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;是的，它被注册了！并且注意一件重要的事情：它通过我们的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;注册的，不是通过&lt;span style="font: 12.0px Verdana"&gt;Declarative Services Bundle&lt;/span&gt;。事实上&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;代表了我们的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;注册了它。我们将迟些了解它如何做的，但是这节课的目的，足够说明了我们的服务的消费者不需要任何具体的工作，事实上，它们连我们使用&lt;span style="font: 12.0px Verdana"&gt;Declarative Services&lt;/span&gt;也不必知道。如果那些消费者愿意那可以很好的使用&lt;span style="font: 12.0px Verdana"&gt;Declarative Services&lt;/span&gt;，但是它们也能使用简单的&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;代码。&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;另外要注意的是在我们的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;中，没有具体的&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;的&lt;span style="font: 12.0px Verdana"&gt;Java&lt;/span&gt;代码。换句话说，我们写了个&lt;span style="font: 12.0px Verdana"&gt;POJO&lt;/span&gt;类，这是&lt;span style="font: 12.0px Verdana"&gt;Declarative Services&lt;/span&gt;的一个主要特性。&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;这些就够了，我很抱歉，这节课程只是一个小小的基础。下次，我们将看看如何用&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;以不同的方式消费服务，这将真正的展示出&lt;span style="font: 12.0px Verdana"&gt;DS&lt;/span&gt;提供的的强大和便利。&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;参考&lt;span style="font: 12.0px Verdana"&gt;:&lt;br /&gt;&lt;/span&gt;本文原文&lt;a href="http://www.eclipsezone.com/eclipse/forums/t96740.html"&gt;&lt;span style="font: 12.0px Verdana; text-decoration: underline ; color:#d96b18;"&gt;http://www.eclipsezone.com/eclipse/forums/t96740.html&lt;/span&gt;&lt;/a&gt;&lt;span style="font: 12.0px Verdana"&gt; &lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34320290-6645625663629519742?l=coolflyreg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://coolflyreg.blogspot.com/feeds/6645625663629519742/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34320290&amp;postID=6645625663629519742' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/6645625663629519742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/6645625663629519742'/><link rel='alternate' type='text/html' href='http://coolflyreg.blogspot.com/2008/06/javaosgideclarative-services.html' title='[JAVA]OSGi入门：介绍Declarative Services[译]'/><author><name>coolflyr_reg</name><uri>http://www.blogger.com/profile/13114315753504344218</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_oqeis3g1k2A/SW1fbBJKK3I/AAAAAAAABiw/oQV4_U7uBwM/S220/120_136124_2.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34320290.post-3920503247844614106</id><published>2008-06-25T15:13:00.002+08:00</published><updated>2008-07-12T22:10:07.177+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><title type='text'>[JAVA]OSGi入门：动态服务跟踪[译]</title><content type='html'>&lt;div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-align: justify; font: normal normal normal 10.5px/normal SimSun; "&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-style-span"  style="color:#AF3E00;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;欢迎来到&lt;/span&gt;EclipseZone OSGi&lt;span style="font: 12.0px STHeiti Light"&gt;迷你系列&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;上回，我们看了如何消费一个服务，使用了一个来自&lt;span style="font: 12.0px Verdana"&gt;Martin Fowler&lt;/span&gt;的启发：一个&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;依赖在一个&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;上来搜索通过指定目标的电影。我们还看了使用&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;服务的动态性质的应对策略，如果它不能找到&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;的一个实例该做什么。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;这是另一个我们上次没有考虑的：如果存在有一个以上的有效&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;怎么办？之后任何&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;可以注册一个服务在&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;接口下，并且所有的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;在&lt;span style="font: 12.0px Verdana"&gt;Registry&lt;/span&gt;的眼中都是平等的。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;我们能简单的忽略此问题，并且事实是我们的代码上次做了什么。通过在&lt;span style="font: 12.0px Verdana"&gt;ServiceTracker&lt;/span&gt;上调用&lt;span style="font: 12.0px Verdana"&gt;getService()&lt;/span&gt;方法，我们获得了通过&lt;span style="font: 12.0px Verdana"&gt;ServiceRegistry&lt;/span&gt;选择的一个任意的&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;的单独实例。有各种方式影响判断（例如一个&lt;span style="font: 12.0px Verdana"&gt;SERVICE_RANKING&lt;/span&gt;属性可以在&lt;span style="font: 12.0px Verdana"&gt;ServiceRegistration&lt;/span&gt;中被指定），但是正如一个消费者，我们将在这个判断上从来没有完全的控制。事实上没有太多的控制是一件好事&lt;span style="font: 12.0px Verdana"&gt;——&lt;/span&gt;终究我们真正能使用所有&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;的实例。这是使用在第一个位置点的接口。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;或者，它可能在某些时候觉得使用多个服务实例。例如，如果有多个&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;服务有效，可能意味着有多个电影数据的来源供&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;使用。当处理一个电影搜索时通过使用所有的服务，我们可以转换为更宽广的网络并为用户提供更好的搜索结果。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;另一个变化，我们回到上次讨论的问题：当没有可用的&lt;/span&gt;MovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;服务存在的时候我们应该做什么？我们简单的返回&lt;/span&gt;null&lt;span style="font: 12.0px STHeiti Light"&gt;不论何时调用&lt;/span&gt;listByDirector()&lt;span style="font: 12.0px STHeiti Light"&gt;方法并且&lt;/span&gt;MovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;是不可用的。&lt;/span&gt;But what if we made it impossible for methods on MovieLister to be called when the MovieFinder isn't present? &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;MovieLister&lt;span style="font: 12.0px STHeiti Light"&gt;是一个服务，就像&lt;/span&gt;MovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;。如果&lt;/span&gt;MovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;消失了，如何让&lt;/span&gt;MovieLister&lt;span style="font: 12.0px STHeiti Light"&gt;消失？换句话说，我们想要&lt;/span&gt;MovieLister&lt;span style="font: 12.0px STHeiti Light"&gt;服务有个一对多的依赖在&lt;/span&gt;MovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;上。在指导的上个部分，我们有个&lt;/span&gt;0..1&lt;span style="font: 12.0px STHeiti Light"&gt;的依赖。&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;让我们对&lt;span style="font: 12.0px Verdana"&gt;MovieListerImpl&lt;/span&gt;做些改变。替换成以下代码：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;13&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;14&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;15&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;16&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;17&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;18&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;19&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;20&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;21&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;22&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;23&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;24&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;25&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;26&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;27&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;28&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;29&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;30&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;31&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;32&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;33&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;34&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;35&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 525.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; osgitut.movies.impl;&lt;/div&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier;  min-height: 14.0pxcolor:#9d4510;"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; java.util.*;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; osgitut.movies.*;&lt;/div&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier;  min-height: 14.0pxcolor:#9d4510;"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; MovieListerImpl &lt;span style="color:#000d7d;"&gt;&lt;b&gt;implements&lt;/b&gt;&lt;/span&gt; MovieLister &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier;  min-height: 14.0pxcolor:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; Collection finders =&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;Collections.synchronizedCollection(&lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; ArrayList());&lt;/div&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier;  min-height: 14.0pxcolor:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;protected&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; bindFinder(MovieFinder finder) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;finders.add(finder);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;System.out.println(&lt;/span&gt;"MovieLister: added a finder"&lt;span style="color:#9d4510;"&gt;);&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;p color="#9d4510" style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier;  min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;protected&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; unbindFinder(MovieFinder finder) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;finders.remove(finder);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;System.out.println(&lt;/span&gt;"MovieLister: removed a finder"&lt;span style="color:#9d4510;"&gt;);&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;p color="#9d4510" style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier;  min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; List listByDirector(String director) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;MovieFinder[] finderArray = (MovieFinder[])&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;finders.toArray(&lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; MovieFinder[finders.size()]);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;List result = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; LinkedList();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/span&gt;(&lt;span style="color:#000d7d;"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; j=0; j&amp;lt;finderArray.length; j++) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;Movie[] all = finderArray[j].findAll();&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/span&gt;(&lt;span style="color:#000d7d;"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; i=0; i&gt;&amp;lt;all.length; i++) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt;(director.equals(all[i].getDirector())) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;     &lt;/span&gt;result.add(all[i]);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; result;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;我们事实上已经从&lt;/span&gt;MovieListerImpl&lt;span style="font: 12.0px STHeiti Light"&gt;移除了所有&lt;/span&gt;OSGi&lt;span style="font: 12.0px STHeiti Light"&gt;依赖&lt;/span&gt;——&lt;span style="font: 12.0px STHeiti Light"&gt;它现在是个纯粹的&lt;/span&gt;POJO&lt;span style="font: 12.0px STHeiti Light"&gt;。然而它需要某人或某物去跟踪&lt;/span&gt;MovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;服务并通过&lt;/span&gt;bindFinder()&lt;span style="font: 12.0px STHeiti Light"&gt;方法提供它们，所以我们创建一个新的文件&lt;/span&gt;osgitut/movies/impl/MovieFinderTracker.java&lt;span style="font: 12.0px STHeiti Light"&gt;来做这个：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;13&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;14&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;15&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;16&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;17&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;18&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;19&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;20&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;21&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;22&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;23&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;24&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;25&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;26&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;27&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;28&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;29&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;30&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;31&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;32&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;33&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;34&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;35&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;36&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;37&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;38&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;39&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;40&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;41&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;42&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;43&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;44&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;45&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;46&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;47&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;48&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;49&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;50&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;51&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;52&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;53&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;54&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;55&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;56&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;57&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;58&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;59&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;60&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;61&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 574.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; osgitut.movies.impl;&lt;/div&gt;&lt;p color="#9d4510" style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier;  min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.framework.*;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.util.tracker.*;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; osgitut.movies.*;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; MovieFinderTracker &lt;span style="color:#000d7d;"&gt;&lt;b&gt;extends&lt;/b&gt;&lt;/span&gt; ServiceTracker &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt; MovieListerImpl lister = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; MovieListerImpl();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; finderCount = 0;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; ServiceRegistration registration = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; MovieFinderTracker(BundleContext context) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;super&lt;/b&gt;&lt;/span&gt;(context, MovieFinder.class.getName(), &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;boolean&lt;/b&gt;&lt;/span&gt; registering = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;false&lt;/b&gt;&lt;/span&gt;; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; Object addingService(ServiceReference reference) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;MovieFinder finder = (MovieFinder) context.getService(reference); &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;lister.bindFinder(finder); &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;synchronized&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;(&lt;/span&gt;&lt;b&gt;this&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;) &lt;/span&gt;{&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;finderCount ++; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (registering) &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; finder; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;registering = (finderCount == 1); &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (!registering) &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; finder; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;ServiceRegistration reg = context.registerService( &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;MovieLister.class.getName(), lister, &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;); &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;synchronized&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;(&lt;/span&gt;&lt;b&gt;this&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;) &lt;/span&gt;{&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;registering = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;false&lt;/b&gt;&lt;/span&gt;; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;registration = reg; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; finder; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; removedService(ServiceReference reference, Object service) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;MovieFinder finder = (MovieFinder) service; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;lister.unbindFinder(finder); &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;context.ungetService(reference); &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;ServiceRegistration needsUnregistration = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;&lt;span style="color:#9d4510;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;synchronized&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;(&lt;/span&gt;&lt;b&gt;this&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;) &lt;/span&gt;{&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;finderCount --; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (finderCount == 0) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;needsUnregistration = registration; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;registration = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt;(needsUnregistration != &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;needsUnregistration.unregister(); &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;这个类覆盖了上次我们谈到的&lt;/span&gt;ServiceTracker&lt;span style="font: 12.0px STHeiti Light"&gt;类，并且制定了当服务来去时&lt;/span&gt;ServiceTracker&lt;span style="font: 12.0px STHeiti Light"&gt;的举动。特别的，当一个&lt;/span&gt;MovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;被添加了的时候调用&lt;/span&gt;addingService()&lt;span style="font: 12.0px STHeiti Light"&gt;方法，并且当一个&lt;/span&gt;MovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;被移除了的时候调用&lt;/span&gt;removedService()&lt;span style="font: 12.0px STHeiti Light"&gt;方法。还有一个&lt;/span&gt;modifiedService()&lt;span style="font: 12.0px STHeiti Light"&gt;方法我们可以覆盖，但是我们在这里不需要它。&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;这里的两个方法值得细看。首先，在&lt;span style="font: 12.0px Verdana"&gt;addingService()&lt;/span&gt;中我们看到传递给我们的参数与其实施记得服务实现对象不如是一个&lt;span style="font: 12.0px Verdana"&gt;ServiceReference&lt;/span&gt;。&lt;span style="font: 12.0px Verdana"&gt;ServiceReference&lt;/span&gt;是一个可以被随意当作参数传递的轻量句柄，并且它能够被用来获取服务的属性，比如那些用&lt;span style="font: 12.0px Verdana"&gt;ServiceRegistration&lt;/span&gt;提供的。关键，获取一个&lt;span style="font: 12.0px Verdana"&gt;ServiceReference&lt;/span&gt;对象不会造成&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;框架增加目标服务的使用计数。你因此可以认为这类似于&lt;span style="font: 12.0px Verdana"&gt;Java&lt;/span&gt;反射&lt;span style="font: 12.0px Verdana"&gt;API&lt;/span&gt;中的&lt;span style="font: 12.0px Verdana"&gt;WeakReference&lt;/span&gt;类。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;第一件事我们在我们的例子中用&lt;/span&gt;ServiceReference&lt;span style="font: 12.0px STHeiti Light"&gt;来获得真实的&lt;/span&gt;MovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;服务对象。为了做这些我们再次需要&lt;/span&gt;BundleContext——&lt;span style="font: 12.0px STHeiti Light"&gt;记住，所有同&lt;/span&gt;OSGi&lt;span style="font: 12.0px STHeiti Light"&gt;框架的交互都是通过&lt;/span&gt;BundleContext&lt;span style="font: 12.0px STHeiti Light"&gt;接口完成的。很巧的是我们的父类&lt;/span&gt;ServiceTracker&lt;span style="font: 12.0px STHeiti Light"&gt;保持了&lt;/span&gt;BundleContext&lt;span style="font: 12.0px STHeiti Light"&gt;引用在一个叫做&lt;/span&gt;context&lt;span style="font: 12.0px STHeiti Light"&gt;的&lt;/span&gt;protected&lt;span style="font: 12.0px STHeiti Light"&gt;成员字段，这样我们可以一直使用。&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;下次，我们用上面定义的&lt;span style="font: 12.0px Verdana"&gt;bindFinder()&lt;/span&gt;方法绑定&lt;span style="font: 12.0px Verdana"&gt;finder&lt;/span&gt;到我们的&lt;span style="font: 12.0px Verdana"&gt;MovieListerImpl&lt;/span&gt;，之后我们注册&lt;span style="font: 12.0px Verdana"&gt;MovieListerImpl&lt;/span&gt;成为一个服务，在&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;接口的下面。注意，我们要很小心的仅在它没有被注册过的时候注册服务，因为在这个情景中我们想要一个独立的跟踪多个&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;服务的&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;最终，我们从这个方法返回。这还有另一个点很有趣&lt;span style="font: 12.0px Verdana"&gt;——addingService&lt;/span&gt;的返回类型只是&lt;span style="font: 12.0px Verdana"&gt;Object&lt;/span&gt;，所以我们要返回什么呢？事实上&lt;span style="font: 12.0px Verdana"&gt;ServiceTracker&lt;/span&gt;不关心，我们能返回我们喜欢的任何东西。然而，我们当我们调用&lt;span style="font: 12.0px Verdana"&gt;modifiedService&lt;/span&gt;和&lt;span style="font: 12.0px Verdana"&gt;/&lt;/span&gt;或&lt;span style="font: 12.0px Verdana"&gt;removedService&lt;/span&gt;时返回给我们从&lt;span style="font: 12.0px Verdana"&gt;addingService&lt;/span&gt;返回的对象。所以你看我们的&lt;span style="font: 12.0px Verdana"&gt;removedService&lt;/span&gt;方法的第一行，你可以看到我们立刻转换&lt;span style="font: 12.0px Verdana"&gt;Object&lt;/span&gt;为&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;那样我们就能从&lt;span style="font: 12.0px Verdana"&gt;lister&lt;/span&gt;中解除绑定。然后如果跟踪到的&lt;span style="font: 12.0px Verdana"&gt;finder&lt;/span&gt;变为了&lt;span style="font: 12.0px Verdana"&gt;0&lt;/span&gt;，那么我们注销&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;服务。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;通常的，我们在&lt;span style="font: 12.0px Verdana"&gt;addingService&lt;/span&gt;中做的任何事都要在&lt;span style="font: 12.0px Verdana"&gt;removedService&lt;/span&gt;方法中销毁。因此我们将从&lt;span style="font: 12.0px Verdana"&gt;addingService&lt;/span&gt;方法返回任何能帮助我们找到它曾做过的任何事。可能是一个&lt;span style="font: 12.0px Verdana"&gt;HashMap&lt;/span&gt;中的键，或者可能是一个&lt;span style="font: 12.0px Verdana"&gt;ServiceRegistration&lt;/span&gt;对象，或者&lt;span style="font: 12.0px Verdana"&gt;(&lt;/span&gt;正如在这个情况中&lt;span style="font: 12.0px Verdana"&gt;)&lt;/span&gt;可能是实际的服务对象。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;像&lt;span style="font: 12.0px Verdana"&gt;removedService&lt;/span&gt;中的最后一步，我们需要&lt;span style="font: 12.0px Verdana"&gt;"unget"&lt;/span&gt;我们上次的&lt;span style="font: 12.0px Verdana"&gt;"got"&lt;/span&gt;。这是非常重要的，因为&lt;span style="font: 12.0px Verdana"&gt;Service Registry&lt;/span&gt;因此来减少此服务的使用计数器，那将允许当计数器置为&lt;span style="font: 12.0px Verdana"&gt;0&lt;/span&gt;时释放服务。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;现在我们需要一个激活器，&lt;/span&gt;osgitut/movies/impl/TrackingMovieListerActivator.java&lt;span style="font: 12.0px STHeiti Light"&gt;：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;13&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;14&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;15&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;16&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;17&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 490.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; osgitut.movies.impl;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.framework.*;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; TrackingMovieListerActivator &lt;span style="color:#000d7d;"&gt;&lt;b&gt;implements&lt;/b&gt;&lt;/span&gt; BundleActivator &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; MovieFinderTracker tracker;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; start(BundleContext context) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;tracker = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; MovieFinderTracker(context);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;tracker.open();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; stop(BundleContext context) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;tracker.close();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;和一个&lt;/span&gt;manifest&lt;span style="font: 12.0px STHeiti Light"&gt;，&lt;/span&gt;TrackingMovieLister.mf&lt;span style="font: 12.0px STHeiti Light"&gt;：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 462.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Manifest-Version: 1.0&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-ManifestVersion: 2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-Name: Tracking Movie Lister&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-SymbolicName: TrackingMovieLister&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-Version: 1.0.0&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-Activator: osgitut.movies.impl.TrackingMovieListerActivator&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Import-Package: org.osgi.framework,&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt; org.osgi.util.tracker,&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt; osgitut.movies;version=&lt;span style="color:#e02d13;"&gt;"[1.0.0,2.0.0)"&lt;/span&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;并且，我将脱离它让你像一个联系那样建立和部署这个&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;到&lt;span style="font: 12.0px Verdana"&gt;Equinox&lt;/span&gt;。这些做完，试试按以下步骤的序列来看看每件事在工作：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal STHeiti; color: rgb(102, 102, 102); "&gt;引用原文&lt;span style="font: 12.0px Verdana"&gt;&lt;b&gt;:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); background-color: rgb(128, 128, 128); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(81, 150, 152); "&gt;1. &lt;span style="font: 12.0px STHeiti Light"&gt;启动&lt;/span&gt;BasicMovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;和启动&lt;/span&gt;TrackingMovieLister&lt;span style="font: 12.0px STHeiti Light"&gt;。检查&lt;/span&gt;"MovieLister: added a finder"&lt;span style="font: 12.0px STHeiti Light"&gt;信息的显示；&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(81, 150, 152); "&gt;2. &lt;span style="font: 12.0px STHeiti Light"&gt;输入&lt;/span&gt;services&lt;span style="font: 12.0px STHeiti Light"&gt;命令并检查&lt;/span&gt;MovieLister&lt;span style="font: 12.0px STHeiti Light"&gt;服务已经存在注册；&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(81, 150, 152); "&gt;3. &lt;span style="font: 12.0px STHeiti Light"&gt;停止&lt;/span&gt;BasicMovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;并检查&lt;/span&gt;"MovieLister: removed a finder"&lt;span style="font: 12.0px STHeiti Light"&gt;消息的显示；&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(81, 150, 152); "&gt;4. &lt;span style="font: 12.0px STHeiti Light"&gt;再次输入&lt;/span&gt;services&lt;span style="font: 12.0px STHeiti Light"&gt;命令并检查没有&lt;/span&gt;MovieLister&lt;span style="font: 12.0px STHeiti Light"&gt;服务被注册。&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); background-color: rgb(128, 128, 128); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;到这里我们完成了一项强大技术的播种。我们约束了一个服务的生命周期到另外的服务的生命周期&lt;span style="font: 12.0px Verdana"&gt;——&lt;/span&gt;事实上是多个。进一步发展这个技术，我们能够让其他服务约束到&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;，并且仍然是另外的服务依赖在那个上面，等等。我们最终构建了一个相互依赖服务的图表，但是不同于通过一些静态&lt;span style="font: 12.0px Verdana"&gt;IoC&lt;/span&gt;容器构建的&lt;span style="font: 12.0px Verdana"&gt;Bean&lt;/span&gt;的图表，我们图表是可靠的，自我恢复的并能够适应变化的环境。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;另一方面，我们写的代码有些问题。&lt;span style="font: 12.0px Verdana"&gt;MovieFinderTracker&lt;/span&gt;和&lt;span style="font: 12.0px Verdana"&gt;TrackingMovieListerActivator&lt;/span&gt;类事实上只是一个模板形式的加载，并且如果我们要开始扩展这个系统之后我们将一遍又一遍的写着相同的代码来获得完美的约束，只是每次有些略微的修改。因此下个部分我们将看到仅仅通过一对&lt;span style="font: 12.0px Verdana"&gt;XML&lt;/span&gt;标记行来替换所有的那些代码。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;所以在下个部分我们将停止用命令行工具在一个目录中建立任何东西。在这个指导开始的时候我的目标是展示&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;是一个简单但仍然强大的框架，并且你无需一个像&lt;span style="font: 12.0px Verdana"&gt;Eclipse&lt;/span&gt;那样强大的，重量级的&lt;span style="font: 12.0px Verdana"&gt;IDE&lt;/span&gt;来开发&lt;span style="font: 12.0px Verdana"&gt;OSGi Bundle&lt;/span&gt;。但一些东西显示的太过简单，总是怀疑&lt;span style="font: 12.0px Verdana"&gt;IDE&lt;/span&gt;释放了一些黑魔法代替我们处理。我希望我展示的不存在这种情况，&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;不需要黑魔法。另一方面，如果你已经像我一样把任何代码都放到这目录的话，你将开始渴望一个正式的开发环境。我也是。对于&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;这不是问题，当然&lt;span style="font: 12.0px Verdana"&gt;——&lt;/span&gt;任何&lt;span style="font: 12.0px Verdana"&gt;Java&lt;/span&gt;项目如果像这样仅仅使用标准工具，将会很快的失控。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;然而，我恐怕你将要知道&lt;span style="font: 12.0px Verdana"&gt;EclipseCon&lt;/span&gt;之后才能读到下个部分。我将跳上一个飞机在我去往&lt;span style="font: 12.0px Verdana"&gt;Santa Clara&lt;/span&gt;的路上待上不到&lt;span style="font: 12.0px Verdana"&gt;24&lt;/span&gt;小时。希望在那里看到你。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;感谢&lt;span style="font: 12.0px Verdana"&gt;BJ Hargrave&lt;/span&gt;为统一代码所建议的更好的解决方案。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;参考&lt;/span&gt;: &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(217, 107, 24); "&gt;&lt;span style="font: 12.0px STHeiti Light; color:#9d4510;"&gt;原始文章&lt;a href="http://www.eclipsezone.com/eclipse/forums/t91059.rhtml"&gt;&lt;span style="font: 12.0px Verdana; text-decoration: underline ; color:#d96b18;"&gt;http://www.eclipsezone.com/eclipse/forums/t91059.rhtml&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;以下是&lt;/span&gt;BJ Hargrave&lt;span style="font: 12.0px STHeiti Light"&gt;的建议：&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;At 11:14 AM on Mar 3, 2007, BJ Hargrave wrote: &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;Re: Getting Started with OSGi: Dynamic Service Tracking &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;Great example. &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;In the spirit of being pedantic , I would like to observe that the MovieFinderTracker class is not thread-safe which is important in a ServiceTracker since ServiceEvents are synchronously delivered from potentially numerous threads. The issue is the registration field which is shared mutable state. Reading and writing of this field MUST be protected. &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;Here is a thread-safe version: &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;13&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;14&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;15&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;16&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;17&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;18&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;19&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;20&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;21&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;22&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;23&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;24&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;25&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;26&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;27&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;28&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;29&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;30&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;31&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;32&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;33&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;34&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;35&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;36&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;37&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;38&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;39&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;40&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;41&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;42&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;43&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 511.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;&lt;b&gt;private&lt;/b&gt;&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;b&gt;boolean&lt;/b&gt;&lt;span style="color:#9d4510;"&gt; registering = &lt;/span&gt;&lt;b&gt;false&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; Object addingService(ServiceReference reference) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;MovieFinder finder = (MovieFinder) context.getService(reference); &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;lister.bindFinder(finder); &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;&lt;b&gt;synchronized&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;(&lt;/span&gt;&lt;b&gt;this&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;) &lt;/span&gt;{&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;finderCount ++; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (registering) &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; finder; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;registering = (finderCount == 1); &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (!registering) &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; finder; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;ServiceRegistration reg = context.registerService( &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;MovieLister.class.getName(), lister, &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;); &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;&lt;b&gt;synchronized&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;(&lt;/span&gt;&lt;b&gt;this&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;) &lt;/span&gt;{&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;registering = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;false&lt;/b&gt;&lt;/span&gt;; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;registration = reg; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; finder; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; removedService(ServiceReference reference, Object service) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;MovieFinder finder = (MovieFinder) service; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;lister.unbindFinder(finder); &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;context.ungetService(reference); &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;ServiceRegistration needsUnregistration = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;&lt;b&gt;synchronized&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;(&lt;/span&gt;&lt;b&gt;this&lt;/b&gt;&lt;span style="color:#9d4510;"&gt;) &lt;/span&gt;{&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;finderCount --; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (finderCount == 0) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;needsUnregistration = registration; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;registration = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt;(needsUnregistration != &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;needsUnregistration.unregister(); &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;You were also missing the ungetService call in removedService (even though the text mentions the importance of this). &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;I think your articles are excellent. I just want to make them more accurate!&gt; &lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34320290-3920503247844614106?l=coolflyreg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://coolflyreg.blogspot.com/feeds/3920503247844614106/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34320290&amp;postID=3920503247844614106' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/3920503247844614106'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/3920503247844614106'/><link rel='alternate' type='text/html' href='http://coolflyreg.blogspot.com/2008/06/javaosgi_6941.html' title='[JAVA]OSGi入门：动态服务跟踪[译]'/><author><name>coolflyr_reg</name><uri>http://www.blogger.com/profile/13114315753504344218</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_oqeis3g1k2A/SW1fbBJKK3I/AAAAAAAABiw/oQV4_U7uBwM/S220/120_136124_2.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34320290.post-7926346143353363961</id><published>2008-06-25T15:12:00.005+08:00</published><updated>2008-07-12T22:10:07.178+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><title type='text'>[JAVA]OSGi入门：消费一个服务[译]</title><content type='html'>&lt;div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-align: justify; font: normal normal normal 10.5px/normal SimSun; "&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-style-span"  style="color:#AF3E00;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;在我们的上个部分，我们看了如何注册一个服务。现在哦我们需要从另外的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;查找并使用服务。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;我们将问题放到我们的需求的上下文中，那个通过&lt;span style="font: 12.0px Verdana"&gt;Martin Fowler&lt;/span&gt;的依赖反转的页面获得的灵感。我们建立了一个&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;的服务并通过&lt;span style="font: 12.0px Verdana"&gt;Service Registry&lt;/span&gt;注册了它。现在我们想要建立使用了&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;的一个&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;来搜索定向的电影。我们假定&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;它自己将是被其它&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;消费的一个服务，例如一个&lt;span style="font: 12.0px Verdana"&gt;GUI&lt;/span&gt;应用程序。问题是，&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;服务是动态的&lt;span style="font: 12.0px Verdana"&gt;……&lt;/span&gt;它们来去都是动态的。意思就是有时我们想要调用&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;服务但是它恰巧无效。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;所以，如果&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;没有呈现，那么&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;将做什么？显然，通过&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;完成工作的重要部分是调用&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;，所以这有一些有用的选择给我们：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;[list=decimal] &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;生成一个错误，例如返回&lt;span style="font: 12.0px Verdana"&gt;null&lt;/span&gt;或者抛出一个异常&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;等待&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;在第一次里不要调用&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;[/list]&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;在这篇文章中我们将首先看前两项，它们十分简单。第三个选项可能甚至仍然没有什么感觉，但是看过前两个后你将会对它抱有希望。&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;第一件事我们需要为&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;服务定义接口。复制以下代码到&lt;span style="font: 12.0px Verdana"&gt;osgitut/movies/MovieLister.java&lt;/span&gt;文件中：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 259.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; osgitut.movies;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; java.util.List;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510"&gt; &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;&lt;b&gt;public&lt;/b&gt;&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;b&gt;interface&lt;/b&gt;&lt;span style="color:#9d4510;"&gt; MovieLister &lt;/span&gt;{&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    List listByDirector(String name);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;现在创建文件&lt;/span&gt;osgitut/movies/impl/MovieListerImpl.java&lt;span style="font: 12.0px STHeiti Light"&gt;：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;13&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;14&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;15&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;16&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;17&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;18&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;19&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;20&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;21&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;22&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;23&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;24&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;25&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;26&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;27&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;28&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;29&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;30&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;31&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;32&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;33&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;34&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;35&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 476.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; osgitut.movies.impl;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; java.util.*;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; osgitut.movies.*;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.framework.*;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.util.tracker.ServiceTracker;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; MovieListerImpl &lt;span style="color:#000d7d;"&gt;&lt;b&gt;implements&lt;/b&gt;&lt;/span&gt; MovieLister &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt; ServiceTracker finderTrack;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; MovieListerImpl(ServiceTracker finderTrack) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        this.finderTrack = finderTrack;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; List listByDirector(String name) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        MovieFinder finder = (MovieFinder) finderTrack.getService();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        &lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt;(finder == &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;            &lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;            &lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; doSearch(name, finder);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; List doSearch(String name, MovieFinder finder) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        Movie[] movies = finder.findAll();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        List result = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; LinkedList();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        &lt;span style="color:#000d7d;"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/span&gt; (&lt;span style="color:#000d7d;"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; i = 0; i &amp;lt; movies.length; i++) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;            &lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt;(movies[i].getDirector().indexOf(name) &gt; -1) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;                result.add(movies[i]);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;            &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        &lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; result;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;这可能是我们的目前最长的代码样本！那么这里将要做什么？首先你注意搜索电影的实际的逻辑被分隔在&lt;span style="font: 12.0px Verdana"&gt;doSearch(String, MovieFinder)&lt;/span&gt;方法中，来帮助我们隔离&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;具体代码。偶然的，我们执行搜索的方式是相当的愚笨和低效率，但是这不是这节指导的重点。我们无论如何只有两个电影在数据库中！&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;有趣的部分是在&lt;span style="font: 12.0px Verdana"&gt;listByDirector(String name)&lt;/span&gt;方法中，使用了一个&lt;span style="font: 12.0px Verdana"&gt;ServiceTracker&lt;/span&gt;对象来从&lt;span style="font: 12.0px Verdana"&gt;Service Registry&lt;/span&gt;中获得&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;。&lt;span style="font: 12.0px Verdana"&gt;ServiceTracker&lt;/span&gt;是将最低级别的&lt;span style="font: 12.0px Verdana"&gt;OSGi API&lt;/span&gt;中的大量令人不愉快的细节抽象出来的非常有用的类。然而我们仍然要检查服务是否确实存在。我们采取在我们的构造函数中传递给我们的&lt;span style="font: 12.0px Verdana"&gt;ServiceTracker&lt;/span&gt;。&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;注意，你可能见过其他地方的代码从&lt;span style="font: 12.0px Verdana"&gt;Registry&lt;/span&gt;获得一个服务而不使用&lt;span style="font: 12.0px Verdana"&gt;ServiceTracker&lt;/span&gt;。例如，它可能调用&lt;span style="font: 12.0px Verdana"&gt;BundleContext&lt;/span&gt;使用&lt;span style="font: 12.0px Verdana"&gt;getServiceReference&lt;/span&gt;和&lt;span style="font: 12.0px Verdana"&gt;getService&lt;/span&gt;。可是这个代码你不得不写的十分复杂并且它不得不小心的自行清理。以我所见，放到低级别的&lt;span style="font: 12.0px Verdana"&gt;API&lt;/span&gt;中处理的益处很少，并且有很多的问题。总是单独使用&lt;span style="font: 12.0px Verdana"&gt;ServiceTracker&lt;/span&gt;更好。&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;一个不错的创建&lt;span style="font: 12.0px Verdana"&gt;ServiceTracker&lt;/span&gt;的地方是在&lt;span style="font: 12.0px Verdana"&gt;Bundler&lt;/span&gt;的激活器中。复制这段代码到&lt;span style="font: 12.0px Verdana"&gt;osgitut/movies/impl/MovieListerActivator.java&lt;/span&gt;：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;13&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;14&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;15&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;16&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;17&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;18&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;19&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;20&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;21&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;22&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;23&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;24&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;25&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;26&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;27&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;28&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;29&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;30&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;31&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;32&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;33&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;34&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;35&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;36&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;37&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;38&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;39&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;40&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;41&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;42&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;43&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;44&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;45&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 609.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; osgitut.movies.impl;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; java.util.*;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.framework.*;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.util.tracker.ServiceTracker;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; osgitut.movies.*;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; MovieListerActivator &lt;span style="color:#000d7d;"&gt;&lt;b&gt;implements&lt;/b&gt;&lt;/span&gt; BundleActivator &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; ServiceTracker finderTracker;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; ServiceRegistration listerReg;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; start(BundleContext context) &lt;span style="color:#000d7d;"&gt;&lt;b&gt;throws&lt;/b&gt;&lt;/span&gt; Exception &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(43, 97, 15); "&gt;&lt;span style="color:#9d4510;"&gt;        &lt;/span&gt;// Create and open the MovieFinder ServiceTracker&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        finderTracker = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; ServiceTracker(context, MovieFinder.class.getName(), &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        finderTracker.open();&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(43, 97, 15); "&gt;&lt;span style="color:#9d4510;"&gt;        &lt;/span&gt;// Create the MovieLister and register as a service&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        MovieLister lister = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; MovieListerImpl(finderTracker);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        listerReg = context.registerService(MovieLister.class.getName(), lister, &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;);&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(43, 97, 15); "&gt;&lt;span style="color:#9d4510;"&gt;        &lt;/span&gt;// Execute the sample search&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        doSampleSearch(lister);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; stop(BundleContext context) &lt;span style="color:#000d7d;"&gt;&lt;b&gt;throws&lt;/b&gt;&lt;/span&gt; Exception &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(43, 97, 15); "&gt;&lt;span style="color:#9d4510;"&gt;        &lt;/span&gt;// Unregister the MovieLister service&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        listerReg.unregister();&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;         &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(43, 97, 15); "&gt;&lt;span style="color:#9d4510;"&gt;        &lt;/span&gt;// Close the MovieFinder ServiceTracker&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        finderTracker.close();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; doSampleSearch(MovieLister lister) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        List movies = lister.listByDirector(&lt;span style="color:#e02d13;"&gt;"Miyazaki"&lt;/span&gt;);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        &lt;span style="color:#000d7d;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt;(movies == &lt;span style="color:#000d7d;"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;            System.err.println(&lt;span style="color:#e02d13;"&gt;"Could not retrieve movie list"&lt;/span&gt;);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;            &lt;span style="color:#000d7d;"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/span&gt; (Iterator it = movies.iterator(); it.hasNext();) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;                Movie movie = (Movie) it.next();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;                System.out.println(&lt;span style="color:#e02d13;"&gt;"Title: "&lt;/span&gt; + movie.getTitle());&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;            &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;现在来看看这个激活器的启动。首先，在&lt;/span&gt;start&lt;span style="font: 12.0px STHeiti Light"&gt;方法中它创建了一个&lt;/span&gt;ServiceTracker&lt;span style="font: 12.0px STHeiti Light"&gt;对象，在我们刚写的&lt;/span&gt;MovieLister&lt;span style="font: 12.0px STHeiti Light"&gt;中使用。然后&lt;/span&gt;"&lt;span style="font: 12.0px STHeiti Light"&gt;打开&lt;/span&gt;"ServiceTracker&lt;span style="font: 12.0px STHeiti Light"&gt;告诉它启动跟踪&lt;/span&gt;Registry&lt;span style="font: 12.0px STHeiti Light"&gt;中&lt;/span&gt;MovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;服务的实例。之后，创建我们的&lt;/span&gt;MovieListerImpl&lt;span style="font: 12.0px STHeiti Light"&gt;对象并在&lt;/span&gt;Registry&lt;span style="font: 12.0px STHeiti Light"&gt;注册它到名为&lt;/span&gt;"MovieLister"&lt;span style="font: 12.0px STHeiti Light"&gt;的接口下。最后，为了在我们启动&lt;/span&gt;Bundle&lt;span style="font: 12.0px STHeiti Light"&gt;时看到有意思的事情，激活器靠&lt;/span&gt;MovieLister&lt;span style="font: 12.0px STHeiti Light"&gt;运行了一个简单的搜索并打印出结果。&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;我们需要建立并安装这个&lt;/span&gt;Bundle&lt;span style="font: 12.0px STHeiti Light"&gt;。我这次将不给出完整的介绍&lt;/span&gt;——&lt;span style="font: 12.0px STHeiti Light"&gt;你可以复习一下上个部分并使它工作。记得你需要创建一个&lt;/span&gt;manifest&lt;span style="font: 12.0px STHeiti Light"&gt;文件，并且它指示&lt;/span&gt;osgitut.movies.impl.MovieListerActivator&lt;span style="font: 12.0px STHeiti Light"&gt;类为&lt;/span&gt;Bundle-Activator&lt;span style="font: 12.0px STHeiti Light"&gt;。并且&lt;/span&gt;Import-Package&lt;span style="font: 12.0px STHeiti Light"&gt;行需要包含三个包，名称是&lt;/span&gt;org.osgi.framework&lt;span style="font: 12.0px STHeiti Light"&gt;，&lt;/span&gt;org.osgi.util.tracker&lt;span style="font: 12.0px STHeiti Light"&gt;和&lt;/span&gt;osgitut.movies&lt;span style="font: 12.0px STHeiti Light"&gt;。&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;一旦你已经安装了&lt;/span&gt;MovieLister.jar&lt;span style="font: 12.0px STHeiti Light"&gt;到&lt;/span&gt;Equinox&lt;span style="font: 12.0px STHeiti Light"&gt;运行时，你可以启动它。在那点上你将看到两条信息中的一条，依赖于是否这个&lt;/span&gt;BasicMovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;的&lt;/span&gt;Bundle&lt;span style="font: 12.0px STHeiti Light"&gt;在上一次一直在运行。如果它没有运行，你将看到：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 203.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;osgi&gt; start 2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Could not retrieve movie list&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;但是如果它正在运行你将看到：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 140.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;osgi&gt; start 2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Title: Spirited Away&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;通过停止和启动各个&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;，你将能够显示任一信息。并且那些几乎是这部分的全部，除了记得我说过当一个服务无效时等待的事情？代码我们已经有了，这实际上是很琐碎的：简单的改变&lt;span style="font: 12.0px Verdana"&gt;MovieListerImpl&lt;/span&gt;的&lt;span style="font: 12.0px Verdana"&gt;16&lt;/span&gt;行来调用&lt;span style="font: 12.0px Verdana"&gt;waitForService(5000)&lt;/span&gt;在&lt;span style="font: 12.0px Verdana"&gt;ServiceTracker&lt;/span&gt;上代替&lt;span style="font: 12.0px Verdana"&gt;getService()&lt;/span&gt;，并且添加&lt;span style="font: 12.0px Verdana"&gt;try/catch&lt;/span&gt;块来捕捉&lt;span style="font: 12.0px Verdana"&gt;InterruptedException&lt;/span&gt;。&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;listByDirector()&lt;/span&gt;方法等待&lt;span style="font: 12.0px Verdana"&gt;5000&lt;/span&gt;毫秒的原因是要等&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;服务被显示出来。如果一个&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;服务那时已经安装了，当然，如果它已经存在&lt;span style="font: 12.0px Verdana"&gt;——&lt;/span&gt;我们将立即获得它来使用。&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;通常，我们建议不要像这样挂起线程。特别在这种情况下，它可能很危险因为&lt;span style="font: 12.0px Verdana"&gt;listByDirector()&lt;/span&gt;方法实际是从我们的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;激活器的&lt;span style="font: 12.0px Verdana"&gt;start&lt;/span&gt;方法调用的，这是一个从框架线程调用的方法。&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;/span&gt;激活器意味着要迅速地返回，因为当一个&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;启动了的时候会有一定数量的其它事情。事实上最坏的情况下我们可能引起死锁，因为我们会进入一个在属于框架对象的&lt;span style="font: 12.0px Verdana"&gt;synchronized&lt;/span&gt;块，那可能已经被其他的一些给锁定了。通常的做法是从不在&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;激活器的&lt;span style="font: 12.0px Verdana"&gt;start&lt;/span&gt;方法中处理任何长时间运行或者阻塞操作，或者在框架直接调用的代码不做任何操作。&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;在下个部分中，我们将看看在使用应付神奇的第三个选项：&lt;span style="font: 12.0px Verdana"&gt;"Don't exist in the first place"&lt;/span&gt;。稍候！&lt;span style="font: 12.0px Verdana"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;参考&lt;span style="font: 12.0px Verdana"&gt;:&lt;br /&gt;&lt;/span&gt;原始文章&lt;a href="http://www.eclipsezone.com/eclipse/forums/t90796.html"&gt;&lt;span style="font: 12.0px Verdana; text-decoration: underline ; color:#d96b18;"&gt;http://www.eclipsezone.com/eclipse/forums/t90796.html&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34320290-7926346143353363961?l=coolflyreg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://coolflyreg.blogspot.com/feeds/7926346143353363961/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34320290&amp;postID=7926346143353363961' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/7926346143353363961'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/7926346143353363961'/><link rel='alternate' type='text/html' href='http://coolflyreg.blogspot.com/2008/06/javaosgi_7144.html' title='[JAVA]OSGi入门：消费一个服务[译]'/><author><name>coolflyr_reg</name><uri>http://www.blogger.com/profile/13114315753504344218</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_oqeis3g1k2A/SW1fbBJKK3I/AAAAAAAABiw/oQV4_U7uBwM/S220/120_136124_2.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34320290.post-1182815406340574749</id><published>2008-06-25T15:12:00.004+08:00</published><updated>2008-07-12T22:10:07.178+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><title type='text'>[JAVA]OSGi入门：注册一个服务[译]</title><content type='html'>&lt;div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-align: justify; font: normal normal normal 10.5px/normal SimSun; "&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-style-span"  style="color:#AF3E00;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;欢迎回来&lt;span style="font: 12.0px Verdana"&gt;EclipseZone OSGi&lt;/span&gt;迷你系列。终于，我们准备接触&lt;span style="font: 12.0px Verdana"&gt;Services&lt;/span&gt;了。我认为，&lt;span style="font: 12.0px Verdana"&gt;Service&lt;/span&gt;层是&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;最精彩的部分，所以接下来的部分将会很有趣。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;上一次我们看了&lt;/span&gt;MovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;接口的例子，我们讲了将使用&lt;/span&gt;MovieLister&lt;span style="font: 12.0px STHeiti Light"&gt;搜索影片。事实上你可以认为这个例子&lt;/span&gt;——&lt;span style="font: 12.0px STHeiti Light"&gt;它从&lt;/span&gt;Martin Fowler&lt;span style="font: 12.0px STHeiti Light"&gt;的&lt;a href="http://www.martinfowler.com/articles/injection.html"&gt;&lt;span style="text-decoration: underline ; color:#d96b18;"&gt;著名页&lt;/span&gt;&lt;/a&gt;上的&lt;/span&gt;"&lt;span style="font: 12.0px STHeiti Light"&gt;依赖注入&lt;/span&gt;"&lt;span style="font: 12.0px STHeiti Light"&gt;，也正如所知道的&lt;/span&gt;"&lt;span style="font: 12.0px STHeiti Light"&gt;反转控制&lt;/span&gt;"(Inversion of Control)&lt;span style="font: 12.0px STHeiti Light"&gt;或&lt;/span&gt;IoC&lt;span style="font: 12.0px STHeiti Light"&gt;。&lt;/span&gt; &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;重新用&lt;span style="font: 12.0px Verdana"&gt;IoC&lt;/span&gt;来尝试解决这个问题。一个&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;并不特别关心原始电影数据的出处，所以我们使用&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;接口来从它隐藏细节。思想是我们可以代替&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;的任一细节，比如获取数据库或者甚至调用一个&lt;span style="font: 12.0px Verdana"&gt;Amazon Web Service&lt;/span&gt;，既&lt;span style="font: 12.0px Verdana"&gt;MoiveLister&lt;/span&gt;仅仅依赖于这个接口，不是任意具体实现。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;到目前为止一切顺利，但是在一些点上，我们必须确实给一个具体的&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;到&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;的实现。与其让&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;到外面去调用一个查找方法，不如我们用一个外部的容器&lt;span style="font: 12.0px Verdana"&gt;"&lt;/span&gt;推&lt;span style="font: 12.0px Verdana"&gt;"&lt;/span&gt;一个合适的对象给它。因此这个成为反转控制。不少这样的容器已经被开发出来了，例如&lt;span style="font: 12.0px Verdana"&gt;PicoContainer&lt;/span&gt;，&lt;span style="font: 12.0px Verdana"&gt;HiveMind&lt;/span&gt;，&lt;span style="font: 12.0px Verdana"&gt;Spring&lt;/span&gt;甚至是&lt;span style="font: 12.0px Verdana"&gt;EJB3.0&lt;/span&gt;。可是所有这些容器都有一个限制：它们大多是静态的。一旦一个&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;给予了一个&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;，它就相当于&lt;span style="font: 12.0px Verdana"&gt;JVM&lt;/span&gt;的生命期。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;也允许我们实现&lt;span style="font: 12.0px Verdana"&gt;IoC&lt;/span&gt;模式，但是在动态方法中。它可能动态的提供&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;的实现给&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;并在之后移除它们。接下来，我们能够做到在一个文本文件查找电影的应用程序到使用&lt;span style="font: 12.0px Verdana"&gt;Amazon Web Services&lt;/span&gt;的查找它们的热交换。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;这就是服务层帮我们做的。十分简单，我们注册一个&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;服务到&lt;span style="font: 12.0px Verdana"&gt;Service Regisgry&lt;/span&gt;中。之后&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;可以用那个&lt;span style="font: 12.0px Verdana"&gt;MovieFinder&lt;/span&gt;服务被提供出来。一个服务因此不比一个&lt;span style="font: 12.0px Verdana"&gt;Java&lt;/span&gt;对象&lt;span style="font: 12.0px Verdana"&gt;——POJO&lt;/span&gt;多些什么&lt;span style="font: 12.0px Verdana"&gt;——&lt;/span&gt;并且它被注册在&lt;span style="font: 12.0px Verdana"&gt;Java&lt;/span&gt;接口的名称下面（一个&lt;span style="font: 12.0px Verdana"&gt;POJI&lt;/span&gt;？）。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;这次，我们将这是看看使用&lt;span style="font: 12.0px Verdana"&gt;registry&lt;/span&gt;来注册服务。稍后，我们看看如何获得这个&lt;span style="font: 12.0px Verdana"&gt;registry&lt;/span&gt;外的服务并提供一个&lt;span style="font: 12.0px Verdana"&gt;MovieLister&lt;/span&gt;。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;我们将添加上次我们建立的&lt;/span&gt;BasicMovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;的&lt;/span&gt;Bundle&lt;span style="font: 12.0px STHeiti Light"&gt;。我们不需要修改已存在的类，我们仅仅需要添加一个&lt;/span&gt;Bundle&lt;span style="font: 12.0px STHeiti Light"&gt;的激活器。所以复制以下代码到&lt;/span&gt;osgitut/movies/impl/BasicMovieFinderActivator.java&lt;span style="font: 12.0px STHeiti Light"&gt;文件中：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;13&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;14&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;15&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;16&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;17&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;18&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;19&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;20&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;21&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;22&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;23&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;24&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;25&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;26&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 469.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; osgitut.movies.impl;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; org.osgi.framework.*;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; osgitut.movies.*;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; java.util.Properties;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; java.util.Dictionary;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; BasicMovieFinderActivator &lt;span style="color:#000d7d;"&gt;&lt;b&gt;implements&lt;/b&gt;&lt;/span&gt; BundleActivator &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; ServiceRegistration registration;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; start(BundleContext context) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        MovieFinder finder = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; BasicMovieFinderImpl();&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        Dictionary props = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; Properties();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        props.put(&lt;span style="color:#e02d13;"&gt;"category"&lt;/span&gt;, &lt;span style="color:#e02d13;"&gt;"misc"&lt;/span&gt;);&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        registration = context.registerService(&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;                               MovieFinder.class.getName(),&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;                               finder, props);&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; stop(BundleContext context) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        registration.unregister();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;现在替换&lt;/span&gt;BasicMovieFinder.mf&lt;span style="font: 12.0px STHeiti Light"&gt;的内容：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 441.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Manifest-Version: 1.0&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-ManifestVersion: 2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-Name: Basic Movie Finder&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-SymbolicName: BasicMovieFinder&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-Version: 1.0.0&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-Activator: osgitut.movies.impl.BasicMovieFinderActivator&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Import-Package: org.osgi.framework,&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt; osgitut.movies;version=&lt;span style="color:#e02d13;"&gt;"[1.0.0,2.0.0)"&lt;/span&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;自从上一次以来，有两个信息被添加到这个&lt;span style="font: 12.0px Verdana"&gt;manifest&lt;/span&gt;。第一个是&lt;span style="font: 12.0px Verdana"&gt;Bundle-Activator&lt;/span&gt;行，它告诉框架关于我们的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;的新激活器&lt;span style="font: 12.0px Verdana"&gt;——&lt;/span&gt;我们上次没有用到它。同样，我添加了&lt;span style="font: 12.0px Verdana"&gt;org.osgi.framework&lt;/span&gt;到这个导入到包。正如我们的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;的上版本不能同框架交互，它不需要导入这个&lt;span style="font: 12.0px Verdana"&gt;OSGi API&lt;/span&gt;包。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;现在你可以重新建立&lt;/span&gt;BasicMovieFinder.jar&lt;span style="font: 12.0px STHeiti Light"&gt;文件：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 546.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&gt; javac -classpath equinox.jar:MoviesInterface.jar osgitut/movies/impl&lt;span style="color:#2b610f;"&gt;/*.java&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(43, 97, 15); "&gt;&gt; jar cfm BasicMovieFinder.jar BasicMovieFinder.mf osgitut/movies/impl/*.class&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;回到&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;控制台，你将看到上次的&lt;span style="font: 12.0px Verdana"&gt;BasicMovieFinder.jar&lt;/span&gt;仍然被安装着。那么你只需要通过输入&lt;span style="font: 12.0px Verdana"&gt;update N&lt;/span&gt;来告诉&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;去更新这个&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;，这个&lt;span style="font: 12.0px Verdana"&gt;N&lt;/span&gt;是&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;的数字标识（你用&lt;span style="font: 12.0px Verdana"&gt;ss&lt;/span&gt;命令找到的那个）。现在使用&lt;span style="font: 12.0px Verdana"&gt;start N&lt;/span&gt;来启动&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;并且你会看见&lt;span style="font: 12.0px Verdana"&gt;……&lt;/span&gt;很小的事情发生了。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;事实上，我们仅仅用&lt;span style="font: 12.0px Verdana"&gt;OSGi Service Registry&lt;/span&gt;注册了我们第一个服务，但是可惜的是没有人在&lt;span style="font: 12.0px Verdana"&gt;"&lt;/span&gt;另一端&lt;span style="font: 12.0px Verdana"&gt;"&lt;/span&gt;，所以这个注册不能产生任何可视化的影响。如果我们想要亲自保证我们的代码实际做了些什么，我们将继续挖掘，并且我们可以使用以下命令：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 245.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;services (objectClass=*MovieFinder)&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;我们将看到以下输出：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 413.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;osgitut.movies.MovieFinder&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;=&lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;category=misc, service.id=22&lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;  Registered by bundle: file:BasicMovieFinder.jar [4]&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;  No bundles using service.&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;很好，我们的服务被注册了，并且我很想继续告诉你如何查找服务并在其他的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;中使用它，但是那将在另外一天了。在这期间，看看你可以用&lt;span style="font: 12.0px Verdana"&gt;services&lt;/span&gt;命令做些什么。开始时常是输入没有任何表达式的&lt;span style="font: 12.0px Verdana"&gt;services&lt;/span&gt;，之后&lt;span style="font: 12.0px Verdana"&gt;——&lt;/span&gt;那确实可以通过服务的过滤仅仅显示器中的一个。不使用过滤，你将看到所有的注册了的服务。有着令人惊讶的巨大数字。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;参考&lt;/span&gt;: &lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(217, 107, 24); "&gt;&lt;span style="font: 12.0px STHeiti Light; color:#9d4510;"&gt;原始文章&lt;a href="http://eclipsezone.com/eclipse/forums/t90688.html"&gt;&lt;span style="font: 12.0px Verdana; text-decoration: underline ; color:#d96b18;"&gt;http://eclipsezone.com/eclipse/forums/t90688.html&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#9D4510;"&gt;&lt;span class="Apple-style-span" style="line-height: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34320290-1182815406340574749?l=coolflyreg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://coolflyreg.blogspot.com/feeds/1182815406340574749/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=34320290&amp;postID=1182815406340574749' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/1182815406340574749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34320290/posts/default/1182815406340574749'/><link rel='alternate' type='text/html' href='http://coolflyreg.blogspot.com/2008/06/javaosgi_5547.html' title='[JAVA]OSGi入门：注册一个服务[译]'/><author><name>coolflyr_reg</name><uri>http://www.blogger.com/profile/13114315753504344218</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_oqeis3g1k2A/SW1fbBJKK3I/AAAAAAAABiw/oQV4_U7uBwM/S220/120_136124_2.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34320290.post-5915695556519937516</id><published>2008-06-25T15:11:00.002+08:00</published><updated>2008-07-12T22:10:07.178+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><title type='text'>[JAVA]OSGi入门：Bundle之间的依赖[译]</title><content type='html'>&lt;div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-align: justify; font: normal normal normal 10.5px/normal SimSun; "&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span class="Apple-style-span"  style="color:#AF3E00;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;在我们上个指导部分，我们看了&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;如何能启动和停止，和它们如何能与框架交互和每一个生命周期。那么&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;真正能做什么呢？&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px Verdana"&gt;Bundles&lt;/span&gt;是一个模块。它们允许我们分割我们完整的项目为能够被单独载入到&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;运行时的可管理的片段。问题是，是否我们喜欢与否，模块总是以来在一些其他的模块上。在原来旧的&lt;span style="font: 12.0px Verdana"&gt;Jar&lt;/span&gt;里，从没有一个可靠的方法来指定一个对其他&lt;span style="font: 12.0px Verdana"&gt;Jar&lt;/span&gt;的依赖&lt;span style="font: 12.0px Verdana"&gt;(&lt;/span&gt;有的，&lt;span style="font: 12.0px Verdana"&gt;manifest&lt;/span&gt;文件中的&lt;span style="font: 12.0px Verdana"&gt;Class-Path&lt;/span&gt;条目&lt;span style="font: 12.0px STHeiti"&gt;不是&lt;/span&gt;做这个的可靠方法&lt;span style="font: 12.0px Verdana"&gt;)&lt;/span&gt;。因此，你从不能真正明确是否这个代码在&lt;span style="font: 12.0px Verdana"&gt;Jar&lt;/span&gt;包里正常工作，或者在运行时将抛出&lt;span style="font: 12.0px Verdana"&gt;ClassNotFoundException&lt;/span&gt;异常。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;非常优美的修正了这个问题。但是展示出来比告诉你更好&lt;span style="font: 12.0px Verdana"&gt;……&lt;/span&gt;那么让我们赶紧获得这些代码。不幸的是我们知道现在还在使用默认的包，但是这不会再继续了；我们将开始使用正式的包来开始工作。所以让我们使用一个非常简单的&lt;span style="font: 12.0px Verdana"&gt;JavaBean&lt;/span&gt;风格的类开始，你要复制以下代码到&lt;span style="font: 12.0px Verdana"&gt;osgitut/movies/Movie.jar&lt;/span&gt;文件中：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 371.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; osgitut.movies;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;&lt;b&gt;public&lt;/b&gt;&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;b&gt;class&lt;/b&gt;&lt;span style="color:#9d4510;"&gt; Movie &lt;/span&gt;{&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt; String title;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt; String director;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; Movie(String title, String director) &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;        this.title = title; this.director = director;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; String getTitle() &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; title; &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    &lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; String getDirector() &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; director; &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;现在我们将在相同的包里创建一个接口。创建文件&lt;span style="font: 12.0px Verdana"&gt;osgitut/movies/MovieFinder.java&lt;/span&gt;，并复制以下代码到里面：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 210.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; osgitut.movies;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;&lt;b&gt;public&lt;/b&gt;&lt;span style="color:#9d4510;"&gt; &lt;/span&gt;&lt;b&gt;interface&lt;/b&gt;&lt;span style="color:#9d4510;"&gt; MovieFinder &lt;/span&gt;{&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;    Movie[] findAll();&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;现在让我们将这两个类放到一个&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;中。是的，我们的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;将荒谬的小而且几乎没用，但是现在已经&lt;span style="font: 12.0px Verdana"&gt;OK&lt;/span&gt;了。就像之前我们需要创建一个&lt;span style="font: 12.0px Verdana"&gt;manifest&lt;/span&gt;文件一样，打开&lt;span style="font: 12.0px Verdana"&gt;MoviesInterface.mf&lt;/span&gt;，并且拷贝下面的内容到里面：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 322.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Manifest-Version: 1.0&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-ManifestVersion: 2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-Name: Movies Interface&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-SymbolicName: MoviesInterface&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-Version: 1.0.0&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Export-Package: osgitut.movies;version=&lt;span style="color:#e02d13;"&gt;"1.0.0"&lt;/span&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;在这里有了一个之前我们没见过的新的行：&lt;span style="font: 12.0px Verdana"&gt;Export-Package&lt;/span&gt;。这只是说包&lt;span style="font: 12.0px Verdana"&gt;osgitut.movies&lt;/span&gt;从这个&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;被输出了。这可能第一次看的话有些莫名其妙，因为在旧的&lt;span style="font: 12.0px Verdana"&gt;Jar&lt;/span&gt;包里，所有的东西都被输出了。但是你没曾想在你的&lt;span style="font: 12.0px Verdana"&gt;Jar&lt;/span&gt;中能看见的内部中放入一些代码？当然，你能建立一些&lt;span style="font: 12.0px Verdana"&gt;private&lt;/span&gt;或&lt;span style="font: 12.0px Verdana"&gt;protected&lt;/span&gt;的类，但是它们在你的&lt;span style="font: 12.0px Verdana"&gt;Jar&lt;/span&gt;中都不可见。所以&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;有效的引入了一个新的代码保护级别：如果包在你的&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;中没有在&lt;span style="font: 12.0px Verdana"&gt;Export-Package&lt;/span&gt;列表中出现，那么它只能在你的模块内部被访问到。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;你也可能注意到了我们在包的后面附着了个版本号。这个很重要我们稍后将见到。它不是绝对需要提供一个版本号的，顺便说一句，如果你没做，&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;将自动的分配版本号&lt;span style="font: 12.0px Verdana"&gt;"0.0.0"&lt;/span&gt;给你的包。我认为总是明确的添加一个版本号是很好的策略。&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;现在我们来建立这个&lt;span style="font: 12.0px Verdana"&gt;Bundle&lt;/span&gt;：&lt;span style="font: 12.0px Verdana"&gt; &lt;/span&gt;&lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 504.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&gt; javac osgitut/movies/Movie.java osgitut/movies/MovieFinder.java&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&gt; jar -cfm MoviesInterface.jar MoviesInterface.mf osgitut/movies&lt;span style="color:#2b610f;"&gt;/*.class&lt;/span&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;我们先不把这个&lt;/span&gt;Bundle&lt;span style="font: 12.0px STHeiti Light"&gt;安装到运行时。首先，我们将建立依赖于它的另一个&lt;/span&gt;Bundle&lt;span style="font: 12.0px STHeiti Light"&gt;。我们要创建一个具体的&lt;/span&gt;MovieFinder&lt;span style="font: 12.0px STHeiti Light"&gt;接口的实现，那么复制以下代码到&lt;/span&gt;osgitut/movies/impl/BasicMovieFinderImpl.java&lt;span style="font: 12.0px STHeiti Light"&gt;文件中：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 14.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;7&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;8&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;9&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;10&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;11&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;12&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 406.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt; osgitut.movies.impl;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt; osgitut.movies.*;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; BasicMovieFinderImpl &lt;span style="color:#000d7d;"&gt;&lt;b&gt;implements&lt;/b&gt;&lt;/span&gt; MovieFinder &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;  &lt;span style="color:#000d7d;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt; Movie[] MOVIES = &lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; Movie[] &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;    &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#9d4510;"&gt; Movie(&lt;/span&gt;"The Godfather"&lt;span style="color:#9d4510;"&gt;, &lt;/span&gt;"Francis Ford Coppola"&lt;span style="color:#9d4510;"&gt;),&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(224, 45, 19); "&gt;&lt;span style="color:#9d4510;"&gt;    &lt;/span&gt;&lt;span style="color:#000d7d;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#9d4510;"&gt; Movie(&lt;/span&gt;"Spirited Away"&lt;span style="color:#9d4510;"&gt;, &lt;/span&gt;"Hayao Miyazaki"&lt;span style="color:#9d4510;"&gt;)&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;  &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;;&lt;/div&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 12.0px Courier; color: #9d4510; min-height: 14.0px"&gt;  &lt;/p&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;  &lt;span style="color:#000d7d;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; Movie[] findAll() &lt;span style="color:#000d7d;"&gt;{&lt;/span&gt; &lt;span style="color:#000d7d;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; MOVIES; &lt;span style="color:#000d7d;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(0, 13, 125); "&gt;}&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); "&gt;&lt;span style="font: 12.0px STHeiti Light"&gt;现在我们需要一个&lt;/span&gt;manifest&lt;span style="font: 12.0px STHeiti Light"&gt;文件，那么创建&lt;/span&gt;BasicMovieFinder.mf&lt;span style="font: 12.0px STHeiti Light"&gt;：&lt;/span&gt; &lt;/div&gt; &lt;table cellspacing="0" cellpadding="0" style="background-color: #999999"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" style="width: 7.0px; background-color: #dddddd; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;1&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;3&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;4&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;5&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(85, 85, 85); "&gt;6&lt;/div&gt; &lt;/td&gt; &lt;td valign="top" style="width: 378.0px; background-color: #ffffff; margin: 0.5px 0.5px 0.5px 0.5px; padding: 6.0px 6.0px 6.0px 6.0px"&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Manifest-Version: 1.0&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-ManifestVersion: 2&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-Name: Basic Movie Finder&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-SymbolicName: BasicMovieFinder&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Bundle-Version: 1.0.0&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Courier; color: rgb(157, 69, 16); "&gt;Import-Package: osgitut.movies;version=&lt;span style="color:#e02d13;"&gt;"[1.0.0,2.0.0)"&lt;/span&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal 'STHeiti Light'; color: rgb(157, 69, 16); "&gt;注意了我们导入了从另一个包输出的&lt;span style="font: 12.0px Verdana"&gt;osgitut.movies&lt;/span&gt;包。我们也在此时添加了导入版本号的范围。框架在运行期使用范围来匹配导入一个适合的输出。&lt;span style="font: 12.0px Verdana"&gt;OSGi&lt;/span&gt;为版本范围使用了一个语法，与将会与绝大多数的数学方式一样熟悉：方括号意味着包括含&lt;span style="font: 12.0px Verdana"&gt;(inclusive)&lt;/span&gt;，圆括号意味着排除&lt;span style="font: 12.0px Verdana"&gt;(exclusive)&lt;/span&gt;。我们将有效的指定版本&lt;span style="font: 12.0px Verdana"&gt;"1.x" &lt;/span&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: normal normal normal 12px/normal Verdana; color: rgb(157, 69, 16); min-height: 15px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 18px; font: nor
