Rational Developer for System z バージョン 7.6

プロパティー・グループの作成

このサンプルは、事前定義プロパティーおよび Rational® Developer for System z® に登録されているプロパティーの値を持つプロパティー・グループをプログラムで作成する方法を示します。

サンプル・シナリオ

プロパティー・グループを作成するには、「リモート・システム」ビューの「MVS ファイル」ノードのポップアップ・メニューから、「API サンプル・アクション」->「プロパティー・グループの作成」アクションを選択します。

createPropertyGroup のアートワーク

プロパティー・グループの作成時およびプロパティー値の設定時には、ステートメントが表示されます。エラー条件が検出された場合は、エラー・メッセージも表示されます。これらはワークベンチに関連付けられた標準出力に表示されます。これは、ワークベンチが開始された DOS ウィンドウ、またはランタイム・ワークベンチの場合はホスティング・ワークベンチの「コンソール」ビューに表示されます。

注: 標準の Eclipse アイコンから開始されたワークベンチの標準出力は、ワークベンチのランタイム設定によっては表示されない場合があります。

以下の図は、プロパティー・グループの作成とその値の設定が正常に完了した結果を示しています。

createPropertyGroupResults のアートワーク

サンプル・コードのウォークスルー

システムのプロパティー・グループ・コンテナーの取得

以下の CreatePropertyGroupAction クラスのコード・スニペットは、選択されたシステムのプロパティー・グループ・コンテナーを取得する方法を示します。
  
if (selectedItem == null) {
  System.err.println("Create Property Group Action - Selected resource must be an MVS File subsystem.");
  return;
}
if (selectedItem instanceof ZOSSystemReference) {
  System.out.println("");
  System.out.println("-----------------------");
  System.out.println("Beginning Create Property Group Action...");
  ZOSSystemReference reference = (ZOSSystemReference) selectedItem;
  ZOSSystemImage system = (ZOSSystemImage) reference.getReferent();
  // Get the property group container for this system.
  ZOSPropertyGroupManager manager = ZOSPropertyGroupManager.getZOSPropertyGroupManager();
  IPropertyGroupContainer container = manager.getPropertyGroupContainer(system.getName());
  if (container == null) {
    System.err.println("Create Property Group Action - No container for system: " + system.getName());
    return;
  }

これは selectedItemZOSSystemReference クラスのインスタンスであることの検証から開始します。検証できた場合は、getReferent メソッドを使用して、ZOSSystemReference から ZOSSystemImage を取得します。

システム接続ごとに、プロパティー・グループ・コンテナーが存在します。 所定のシステム名のプロパティー・グループ・コンテナーを取得するには、ZOSPropertyGroupManager クラスの getPropertyGroupContainer メソッドを使用します。

プロパティー・グループの作成

以下の CreatePropertyGroupAction クラスのコード・スニペットは、ユーザー定義カテゴリーおよび事前定義カテゴリーのカテゴリー・インスタンスで構成されるプロパティー・グループを作成する方法を示します。
 
IPropertyGroup group = null;
try {
  group = container.createPropertyGroup(PROPERTY_GROUP_NAME, "");
  System.out.println(PROPERTY_GROUP_NAME + " created.");
} catch (DuplicatePropertyGroupException e1) {
  System.err.println("Create Property Group Action - Property group already exists.");
  return;
}

プロパティー・グループは、createPropertyGroup メソッドを使用して作成されます。 プロパティー・グループが既に存在する場合は、DuplicatePropertyGroupException がスローされ、エラー・メッセージが出力されます。

ユーザー定義カテゴリーの使用

以下のコード・スニペットは、ユーザー定義カテゴリーのカテゴリー・インスタンスを作成し、これをプロパティー・グループに追加する方法を示します。
// Create an instance of the user-defined category, set properties,
// and add the instance to the property group. These properties will not appear
// in the UI, but they are available through the API.
try {
  ICategory category = manager.getCategory("SAMPLE_CATEGORY");
  if (category == null) {
    System.err.println("Create Property Group Action - Could not find category SAMPLE_CATEGORY.");
    return;
  }
  ICategoryInstance instance = category.makeInstance();
  instance.setValue("PROPERTY_1", "value1");
  System.out.println("PROPERTY_1 set to value1");
  instance.setValue("PROPERTY_2", "value2");
  System.out.println("PROPERTY_2 set to value2");
  group.addCategoryInstance(instance);
} catch (UnregisteredPropertyException e) {
  System.err.println("Create Property Group Action - Unregistered property: " + e.getName());
  return;
} catch (DuplicateInstanceException e) {
  System.err.println("Create Property Group Action - Duplicate instance of category: " + e.getCategoryInstance().getCategory().getName());
  return;
}
SAMPLE_CATEGORY カテゴリーのインスタンスは、前のコード・スニペットによって作成されています。このカテゴリーは、以下の Eclipse 拡張ポイントを使用して、Rational Developer for System z に登録されます。
<extension point="com.ibm.ftt.properties.api.category">
  <category name="SAMPLE_CATEGORY">
    <property name="PROPERTY_1" />
    <property name="PROPERTY_2" />
  </category>
</extension>

これらのプロパティー値は、Rational Developer for System z ユーザー・インターフェースに表示されません。これは、このユーザー・インターフェースが拡張可能ではないためですが、API を介して使用することができます。

事前定義カテゴリーの使用

以下のコード・スニペットは、事前定義カテゴリーのカテゴリー・インスタンスを作成し、これをプロパティー・グループに追加する方法を示します。
// Create an instance of a pre-defined category, set properties,
// and add the instance to the property group. The values are not
// realistic values, this is just an example of how to work with
// pre-defined properties.
try {
  ICategory category = manager.getCategory(IPropertyGroupConstants.JCL_OPTIONS);
  if (category == null) {
    System.err.println("Create Property Group Action - Could not find category " + IPropertyGroupConstants.COBOL_SETTINGS);
    return;
  }
  ICategoryInstance instance = category.makeInstance();
  instance.setValue(IPropertyGroupConstants.JOBCARD, "//sample jobcard");
  System.out.println(IPropertyGroupConstants.JOBCARD + " set to //sample jobcard");
  instance.setValue(IPropertyGroupConstants.GENERATED_JCL_DATASET, "sample.test.jcl");
  System.out.println(IPropertyGroupConstants.GENERATED_JCL_DATASET + " set to sample.test.jcl");
  group.addCategoryInstance(instance);
} catch (UnregisteredPropertyException e) {
  System.err.println("Create Property Group Action - Unregistered property: " + e.getName());
  return;
} catch (DuplicateInstanceException e) {
  System.err.println("Create Property Group Action - Duplicate instance of category: " + e.getCategoryInstance().getCategory().getName());
}

(IPropertyGroupConstants) には、事前定義カテゴリーの名前とプロパティーが収められます。


ご利用条件 | フィードバック

このインフォメーション・センターでは Eclipse テクノロジーが採用されています。(http://www.eclipse.org)