カスタム・アクションを簡単に使用できるようにする、いくつかのヘルパー・クラスが利用可能です。
カスタム・パラメーターの値を取得する最も簡単な方法は、CustomActionUtil にあるメソッドの 1 つを使うことです。例えば、getCustomParameters を使用します。
CustomActionUtil.getCustomParameters(resource, "101");
これにより、特定のリソースについて、アクション ID が 101 であるアクションの、カスタム・パラメーターが取得されます。 異なってはいるが似ているリソースに対して、同じタスクを繰り返し使用することを計画している場合は、getCustomParametersForTask をそのように使用できます。
CARMAContent[] resources = getResources();
CarmaTaskMemento taskMemento = new CarmaTaskMemento();
for (int i = 0; i < resources.length; i++) {
CustomActionUtil.getCustomParametersForTask(taskMemento, resources[i], "101");
}
上の例では、アクション呼び出しの間に使用するためにユーザーが入力した情報を保管するために taskMemento が使用されます。 taskMemento がここで使用されない場合は、すべてのリソースでユーザーに情報の入力を求める同じプロンプトが出されます。
パラメーター値を取り出すために異なるメカニズム (異なるユーザー・インターフェースなど) を使用する場合は、以下の例に示すように、直接 CustomActionParameterManager クラスと対話することができます。
CustomActionParameterManager manager = CustomActionParameterManager.getManager();
Object[] paramsToPass = manager.getCustomParameters(resource, actionId); // parameters to pass to the command
//this method will tell us whether or not the manager has all the information it needs
if (manager.isPromptNeeded(resource, actionId)) {
final Action action = resource.findActionFor(actionId);
Iterator parameters = action.getParameters().iterator();
//find the parameter you want to change this way, or look for it to be null in paramsToPass
int index = 0;
while (it.hasNext()) {
Parameter param = (Parameter) it.next();
if (param.getName().equals(targetName))
break;
index++;
}
paramsToPass[index] = new Boolean(false);
//optionally store the parameter for later
Object[] paramsToStore = new Object[paramsToPass.length];
for (int i = 0; i < paramsToStore.length; i++) {
paramsToStore[i] = null;
if (i == index)
paramsToStore[i] = new Boolean(false);
}
manager.setUserStoredParamValues(resource.getRepository(), paramsToStore);
}
上の例で、targetName とは、RAM デベロッパーによって定義されたパラメーターの名前です。