if (ref instanceof Wrapper) {
ref = ((Wrapper) ref).unwrap();
}
TMLContext tmlContext = WGAGlobal.fetchInitialContext(Context.getCurrentContext());
if (ref == null) {
_designContext = tmlContext.getDesignContext();
_currentAction = WGAGlobal.currentAction(Context.getCurrentContext(), null);
_isCurrentScriptDesign = true;
}
else if (ref instanceof WGDatabase) {
_designContext = tmlContext.getDesignContext().createContextDelegate((WGDatabase) ref, null);
}
else if (ref instanceof String) {
WGDatabase designDB = tmlContext.db((String) ref);
if (designDB != null && designDB.isSessionOpen()) {
_designContext = tmlContext.getDesignContext().createContextDelegate((WGDatabase) designDB, null);
}
}
else if (ref instanceof NativeObject) {
_currentObject = (NativeObject) ref;
_currentAction = WGAGlobal.currentAction(Context.getCurrentContext(), _currentObject);
if (_currentAction == null) {
throw new IllegalArgumentException("Cannot determine design of parameter object");
}
String dbKey = _currentAction.getModuleDatabase();
WGDatabase designDB = tmlContext.db(dbKey);
if (designDB != null && designDB.isSessionOpen()) {
_designContext = tmlContext.getDesignContext().createContextDelegate((WGDatabase) designDB, null);
}
}
else {
throw new IllegalArgumentException("Invalid parameter object type " + ref.getClass().getName());
}