2010年12月15日水曜日

5.2.1 サービスリファレンス (Service References)

一般に, 登録されたサービスは ServiceReference オブジェクトを通して参照される. これにより, バンドルがサービスオブジェクト自体を要求することなくサービスについて知りたいというときに, バンドル間に動的なサービス依存関係を不必要に生成するという事態を避けることができる.

In general, registered services are referenced through ServiceReference objects. This avoids creating unnecessary dynamic service dependencies between bundles when a bundle needs to know about a service but does not require the service object itself.

ServiceReference オブジェクトは, 依存関係を生成することなく保存でき, また, 他のバンドルへ受け渡すことができる. バンドルがサービスを使用したいときは, ServiceReference オブジェクトを BundleContext.getService(ServiceReference) に渡すことでサービスを取得することができる. 129 ページの「サービスの特定」を参照のこと.

A ServiceReference object can be stored and passed on to other budles without the implications of dependencies. When a bundle wishes to use the service, it can be obtained by passing the ServiceReference object to BundleContext.getService(ServiceReference). See Locating Services on page 129.

ServiceReference オブジェクトは, サービスオブジェクトのプロパティー群や他のメタ情報をカプセル化している. バンドルはこのメタ情報を問い合わせることができ, 最も適合するサービスを選択するために利用できる.

A ServiceReference object encapsulates the properties and other meta-information about the service object it represents. This meta-information can be queried by a bundle to assist in the selection of a service that best suits its needs.

バンドルがフレームワークサービスレジストリーにサービスを問い合わせたとき, フレームワークは, サービス自体ではなく, 要求されたサービス群の ServiceReference オブジェクト群を,要求元のバンドルに提供しなければならない.

When a bundle queries the Framework service registry for services, the Framework must provide the requesting bundle with the ServiceReference objects of the requested services, rather than with the services themselves.

ServiceReference オブジェクトはまた, ServiceRegistration オブジェクトからも取得することができる.

A ServiceReference object may also be obtained from a ServiceRegistration object.

ServiceReference オブジェクトはサービスオブジェクトが登録されている間のみ有効である. しかし, ServiceReference オブジェクトが存在している間は, サービスオブジェクトのプロパティー群は参照可能でなければならない.

A ServiceReference object is valid only as long as the service object is registered. However, its properties must remain available as long as the ServiceReference object exists.