9.6. OSGi 設定を機能追加

アプリケーションが OSGi Configuration Admin サービスを使用する場合は、機能定義の config 子要素を使用して、このサービスの設定を指定できます。たとえば、prefix プロパティーの値が MyTransform であることを指定するには、以下の config 子要素を機能の設定に追加します。

<?xml version="1.0" encoding="UTF-8"?>
<features name="MyFeaturesRepo">
  <feature name="example-camel-bundle">
    <config name="org.fusesource.fuseesb.example">
      prefix=MyTransform
    </config>
  </feature>
</features>

config 要素の name 属性は、プロパティー設定の永続 ID を指定します (永続 ID は実質的にプロパティー名の名前スコープとして機能します) 。config 要素の内容は、Java プロパティーファイル と同じ方法で解析されます。

config 要素の設定は、以下のように、永続 ID にしたがって命名される InstallDir/etc ディレクトリーにある Java プロパティーファイルの設定によって、オプションで上書きできます。

InstallDir/etc/org.fusesource.fuseesb.example.cfg

前述の設定プロパティーを実際に使用する方法の例として、OSGi 設定プロパティーにアクセスする次の BlueprintXML ファイルについて考えてみます。

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">

    <!-- osgi blueprint property placeholder -->
    <cm:property-placeholder id="placeholder"
                             persistent-id="org.fusesource.fuseesb.example">
        <cm:default-properties>
            <cm:property name="prefix" value="DefaultValue"/>
        </cm:default-properties>
    </cm:property-placeholder>

    <bean id="myTransform" class="org.fusesource.fuseesb.example.MyTransform">
      <property name="prefix" value="${prefix}"/>
    </bean>

</blueprint>

この Blueprint XML ファイルが example-camel-bundle バンドルにデプロイされると、プロパティー参照 ${prefix} は、 features リポジトリーの config 要素で指定される値 MyTransform に置き換えられます。