}
public static Plugin plugin(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) throws WGException {
if (args.length != 1) {
throw new EvaluatorException("Method WGA.plugin() needs a single parameter, either string or database");
}
Object arg1 = args[0];
if (arg1 instanceof Wrapper) {
arg1 = ((Wrapper) arg1).unwrap();
}
if (arg1 instanceof String) {
TMLContext con = fetchInitialContext(Context.getCurrentContext());
WGAPlugin plugin = con.getwgacore().getPluginSet().getPluginByUniqueName((String) arg1);
if (plugin == null || !plugin.isActive() || !plugin.isValid()) {
return null;
}
WGDatabase db = con.db(plugin.buildDatabaseKey());
if (db != null) {
return new Plugin(db);
}
else {
return null;
}
}
else if (arg1 instanceof WGDatabase) {
return new Plugin((WGDatabase) arg1);
}
else {
throw new EvaluatorException("Parameter of method WGA.plugin() must be either a plugin unique name (type String) or a database (type WGDatabase)");
}
}