public static XScriptContext createContext(
      XModel xModel,
      XScriptInvocationContext xInvocContext,
      XComponentContext xCtxt,
      XMultiComponentFactory xMCF) {
    XScriptContext sc = null;

    try {

      Object xInterface = null;
      XDesktop xDesktop = null;

      xInterface = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xCtxt);
      xDesktop = UnoRuntime.queryInterface(XDesktop.class, xInterface);
      if (xModel != null) {
        sc = new ScriptContext(xCtxt, xDesktop, xModel, xInvocContext);
      } else {
        sc = new EditorScriptContext(xCtxt, xDesktop);
      }

    } catch (Exception e) {
      LogUtils.DEBUG(LogUtils.getTrace(e));
    }
    return sc;
  }
  ScriptImpl(
      XComponentContext ctx,
      ScriptMetaData metaData,
      XModel xModel,
      XScriptInvocationContext xContext)
      throws com.sun.star.uno.RuntimeException {
    this.metaData = metaData;
    this.m_xContext = ctx;
    this.m_xModel = xModel;
    this.m_xInvocContext = xContext;

    try {
      this.m_xMultiComponentFactory = m_xContext.getServiceManager();
    } catch (Exception e) {
      LogUtils.DEBUG(LogUtils.getTrace(e));
      throw new com.sun.star.uno.RuntimeException(
          "Error constructing  ScriptImpl [beanshell]: " + e.getMessage());
    }

    LogUtils.DEBUG("ScriptImpl [beanshell] script data = " + metaData);
  }