impl_waitForEvent(m_globalEvents, "OnLoad", 5000);
// wait for all events to arrive - OnLoad should be the last one
final XDispatchProvider dispatchProvider = UnoRuntime.queryInterface(XDispatchProvider.class, databaseDoc.getCurrentController().getFrame());
final URL url = impl_getURL(".uno:CloseDoc");
final XDispatch dispatcher = dispatchProvider.queryDispatch(url, "", 0);
impl_startObservingEvents(context);
dispatcher.dispatch(url, new PropertyValue[0]);
impl_stopObservingEvents(m_globalEvents,
new String[]
{
"OnPrepareViewClosing", "OnViewClosed", "OnPrepareUnload", "OnUnload"
}, context);