Conversion to a script extension

When you convert a FESI extension to a script extension, the root of a script extension is the ScriptExtension interface.

You must implement this interface to create script extension.

public class ITIMExtension implements ScriptExtension {

   public List getContextItems() {
   }

   public void initialize(ScriptInterface si, ScriptContextDAO dao)
         throws ScriptException, IllegalArgumentException {
   }
}

To create object that can be used in scripts, create a POJO class that contains all of the business logic, and implements the marker interface ExtensionBean. A marker interface means that ExtensionBean does not require you to implement any methods and it does add any new data to your class. A POJO that implements ExtensionBean is treated specially by the IBM Security Identity Manager scripting components.

If your class does not implement ExtensionBean, then scripts cannot use the methods provided by the POJO. For example:

public class Extension implements ExtensionBean {
   public static void log(String msg) {
      System.out.println(msg);
   }
}

In the initialize method of your extension, create ContextItem that contains an instance of your extension and add that ContextItem to a List.

ContextItem custom = ContextItem.createItem("CustomExtension",
      new Extension());
items.add(custom);

To create global function, use ContextItem, but this time call createGlobalFunction. For example:

ContextItem func = ContextItem.createGlobalFunction("log",
      new GlobalFunction() {
         public Object call(Object[] parameters)
               throws ScriptEvaluationException {
            if (parameters.length >= 1) {
               Extension.log(parameters[0].toString());
            }
            return null;
         }
      });
items.add(func);

The second argument to createGlobalFunction is a GlobalFunction object. GlobalFunction has a single method that you must implement and call. It is similar to the doCall method from the FESI JSFunctionAdapter. GlobalFunctions are not suggested because, like the doCall method, they pass an array of parameters. You must check that all of the parameters exist and are the right types, which can be difficult to maintain over the life of your extension.