Creation of a constructor
To create a constructor, use ContextItem
and
the createConstructor
method.
For example:
ContextItem logger = ContextItem.createConstructor("Logger",
Extension.class);
items.add(logger);
The second parameter to createConstructor
is
the Class object for the object that you want to construct. It is
usually a POJO that implements ExtensionBean
.
In each of these examples, you add the ContextItem
to
a List. In the getContextItems
method of ScriptExtension
,
you return that List. For example, the full code is:
public class ITIMExtension implements ScriptExtension {
private List<ContextItem> items;
public List getContextItems() {
return items;
}
public void initialize(ScriptInterface si, ScriptContextDAO dao)
throws ScriptException, IllegalArgumentException {
items = new ArrayList<ContextItem>();
ContextItem custom = ContextItem.createItem("CustomExtension",
new Extension());
items.add(custom);
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);
ContextItem logger = ContextItem.createConstructor("Logger",
Extension.class);
items.add(logger);
}
}