特定の設定専用の操作を追加するだけではなく、操作をモジュール全体で使用できるように、Extension レベルで操作を追加することができます。
Extension クラスが唯一の Config クラスではない限り、Extension レベルの操作に設定を割り当てることはできません。つまり、操作は特定の設定にはバインドされません。Extension レベルで操作を定義するには、Extension クラスを唯一の設定とするのではなく、設定を定義してから Extension クラスに @Operations アノテーションを付加します。
これは、複数の設定がある場合にのみ意味があることに注意してください。Extension クラス (唯一の設定) しかない場合は、定義するすべての操作はその設定にバインドされるからです。
次の例では、2 つの設定を追加して、それぞれに操作を定義しています。そして、モジュールに対してグローバルな操作をいくつか追加しています。
@Extension(name = "Foo")
@Operations(GlobalOperations.class)
@Configurations({FooConfig.class, BarConfig.class})
public class FooModule {
}
public class GlobalOperations {
public String fooModuleOperation() {
return "this operation is global to the module!";
}
}
上記の例では、FooConfig と BarConfig の 2 つの設定と、GlobalOperations に定義された操作のセットを持つモジュールを定義しています。
@Operations({FooConfigOperations.class})
public class FooConfig {
@Parameter
private String fooParameter;
public String getFooParameter() {
return fooParameter;
}
}
public class FooConfigOperations {
public String fooConfigOperation(@Config FooConfig config) {
return "this operation receives the FooConfig which has a fooParameter with value: " + config.getFooParameter();
}
}
上記の例では、FooConfigOperations にいくつかの専用操作を定義して、FooConfig という新しい設定を定義しています 。 そして、fooConfigOperation という操作を定義しています 。 この操作は FooConfig という設定に属するため、Config クラスを特別な @Config アノテーション付きの引数として受け取ることができます。
@Operations({BarConfigOperations.class})
public class BarConfig {
@Parameter
private String barParameter;
public String getBarParameter() {
return barParameter;
}
}
public class BarConfigOperations {
public String barConfigOperation(@Config BarConfig config){
return "this operation receives the BarConfig which has a barParameter with value: " + config.getBarParameter();
}
}
操作を (上記の GlobalOperations メソッドと同じように) Extension レベルで定義することは、定義される操作が操作対象の設定を受け取らないこと (したがって設定を必要としないこと) を意味します。
設定の詳細については、設定についての説明を参照してください。