public static SchemaDocument getDoc(
     ValueContext vc, String dataSourceId, String catalog, String schemaPattern)
     throws ParserConfigurationException, NamingException, SQLException {
   SchemaDocument schemaDoc = (SchemaDocument) docs.get(dataSourceId);
   if (schemaDoc == null) {
     DatabaseContext dbc =
         DatabaseContextFactory.getContext(vc.getRequest(), vc.getServletContext());
     schemaDoc = new SchemaDocument(dbc.getConnection(vc, dataSourceId), catalog, schemaPattern);
     docs.put(dataSourceId, schemaDoc);
   }
   return schemaDoc;
 }
  public void handleCommand(ValueContext vc, Writer writer, boolean unitTest)
      throws ComponentCommandException, IOException {
    if (dataCmd != null)
      vc.getRequest()
          .setAttribute(com.netspective.sparx.xaf.form.Dialog.PARAMNAME_DATA_CMD_INITIAL, dataCmd);

    javax.servlet.ServletContext context = vc.getServletContext();
    com.netspective.sparx.xaf.form.DialogManager manager =
        com.netspective.sparx.xaf.form.DialogManagerFactory.getManager(context);
    if (manager == null) {
      writer.write("DialogManager not found in ServletContext");
      return;
    }

    com.netspective.sparx.xaf.form.Dialog dialog =
        manager.getDialog(vc.getServletContext(), null, dialogName);
    if (dialog == null) {
      writer.write("Dialog '" + dialogName + "' not found in manager '" + manager + "'.");
      return;
    }

    com.netspective.sparx.xaf.skin.SkinFactory skinFactory = SkinFactory.getInstance();
    com.netspective.sparx.xaf.form.DialogSkin skin =
        skinName == null ? skinFactory.getDialogSkin(vc) : skinFactory.getDialogSkin(vc, skinName);
    if (skin == null) {
      writer.write("DialogSkin '" + skinName + "' not found in skin factory.");
      return;
    }

    com.netspective.sparx.xaf.form.DialogContext dc =
        dialog.createContext(
            context,
            vc.getServlet(),
            (javax.servlet.http.HttpServletRequest) vc.getRequest(),
            (javax.servlet.http.HttpServletResponse) vc.getResponse(),
            skin);
    if (debugFlagsSpec != null) dc.setDebugFlags(debugFlagsSpec);
    dc.setRetainRequestParams(DIALOG_COMMAND_RETAIN_PARAMS);
    dialog.prepareContext(dc);

    if (dialog instanceof StatementDialog) {
      dialog.retainAllRequestParams();
      dialog.renderHtml(writer, dc, true);
    } else {
      if (unitTest) dc.setRedirectDisabled(true);

      if (dc.inExecuteMode()) {
        if (dc.debugFlagIsSet(Dialog.DLGDEBUGFLAG_SHOW_FIELD_DATA)) {
          writer.write(dc.getDebugHtml());
          writer.write(dialog.getLoopSeparator());
          dc.getSkin().renderHtml(writer, dc);
        } else {
          dialog.execute(writer, dc);

          if (unitTest && dialog instanceof TableDialog)
            writer.write("<pre>Last row processed: " + dc.getLastRowManipulated() + "</pre>");

          if (!dc.executeStageHandled()) {
            writer.write("Dialog '" + dialogName + "' did not handle the execute mode.<p>");
            writer.write(dc.getDebugHtml());
          }
        }
      } else dc.getSkin().renderHtml(writer, dc);
    }
  }