public boolean preLaunchCheck(
      ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
      throws CoreException {
    ExporterAttributes attributes = new ExporterAttributes(configuration);

    String configName = attributes.getConsoleConfigurationName();
    if (StringHelper.isEmpty(configName)) {
      abort(
          HibernateConsoleMessages
                  .CodeGenerationLaunchDelegate_console_configuration_name_is_empty_in
              + configuration.getName(),
          null,
          ICodeGenerationLaunchConstants.ERR_UNSPECIFIED_CONSOLE_CONFIGURATION);
    }

    if (KnownConfigurations.getInstance().find(configName) == null) {
      String out =
          NLS.bind(
              HibernateConsoleMessages
                  .CodeGenerationLaunchDelegate_console_configuration_not_found_in,
              configName,
              configuration.getName());
      abort(out, null, ICodeGenerationLaunchConstants.ERR_CONSOLE_CONFIGURATION_NOTFOUND);
    }

    if (StringHelper.isEmpty(attributes.getOutputPath())) {
      abort(
          HibernateConsoleMessages.CodeGenerationLaunchDelegate_output_has_to_be_specified_in
              + configuration.getName(),
          null,
          ICodeGenerationLaunchConstants.ERR_OUTPUT_PATH_NOTFOUND);
    }

    List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
    for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext(); ) {
      ExporterFactory exFactory = iter.next();
      if (exFactory.isEnabled(configuration)
          && exFactory
              .getExporterDefinitionId()
              .equals("org.hibernate.tools.query")) { // $NON-NLS-1$
        if (!exFactory.getProperties().containsKey("query_string")) { // $NON-NLS-1$
          abort(
              "Query property should be explicitly set for Query Exporter",
              null,
              ICodeGenerationLaunchConstants.ERR_OUTPUT_PATH_NOTFOUND); // $NON-NLS-1$
        }
      }
    }

    return super.preLaunchCheck(configuration, mode, monitor);
  }
  private ArtifactCollector runExporters(
      final ExporterAttributes attributes,
      final ExporterFactory[] exporterFactories,
      final Set<String> outputDirectories,
      final IProgressMonitor monitor)
      throws CoreException {

    monitor.beginTask(
        HibernateConsoleMessages.CodeGenerationLaunchDelegate_generating_code_for
            + attributes.getConsoleConfigurationName(),
        exporterFactories.length + 1);

    if (monitor.isCanceled()) return null;

    ConsoleConfiguration cc =
        KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
    if (attributes.isReverseEngineer()) {
      monitor.subTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_reading_jdbc_metadata);
    }
    final Configuration cfg =
        buildConfiguration(attributes, cc, ResourcesPlugin.getWorkspace().getRoot());

    monitor.worked(1);

    if (monitor.isCanceled()) return null;

    return (ArtifactCollector)
        cc.execute(
            new Command() {

              public Object execute() {
                ArtifactCollector artifactCollector = new ArtifactCollector();

                // Global properties
                Properties props = new Properties();
                props.put(
                    CodeGenerationStrings.EJB3, "" + attributes.isEJB3Enabled()); // $NON-NLS-1$
                props.put(
                    CodeGenerationStrings.JDK5, "" + attributes.isJDK5Enabled()); // $NON-NLS-1$

                for (int i = 0; i < exporterFactories.length; i++) {
                  monitor.subTask(exporterFactories[i].getExporterDefinition().getDescription());

                  Properties globalProperties = new Properties();
                  globalProperties.putAll(props);

                  Exporter exporter;
                  try {
                    exporter =
                        exporterFactories[i].createConfiguredExporter(
                            cfg,
                            attributes.getOutputPath(),
                            attributes.getTemplatePath(),
                            globalProperties,
                            outputDirectories,
                            artifactCollector);
                  } catch (CoreException e) {
                    throw new HibernateConsoleRuntimeException(
                        HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_setting_up
                            + exporterFactories[i].getExporterDefinition(),
                        e);
                  }

                  try {
                    exporter.start();
                  } catch (HibernateException he) {
                    throw new HibernateConsoleRuntimeException(
                        HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_running
                            + exporterFactories[i].getExporterDefinition().getDescription(),
                        he);
                  }
                  monitor.worked(1);
                }
                return artifactCollector;
              }
            });
  }
  public void launch(
      ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
      throws CoreException {
    Assert.isNotNull(configuration);
    Assert.isNotNull(monitor);
    ExporterAttributes attributes = new ExporterAttributes(configuration);
    ConsoleConfiguration cc =
        KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
    ConsoleExtension consoleExtension =
        ConsoleExtensionManager.getConsoleExtension(cc.getHibernateExtension());
    Map<String, File[]> generatedFiles =
        consoleExtension.launchExporters(configuration, mode, launch, monitor);
    // code formatting needs to happen *after* refresh to make sure eclipse will format the uptodate
    // files!
    if (generatedFiles != null) {
      formatGeneratedCode(monitor, generatedFiles);
    }

    /* The code is moved to consoleExtension and delegated method is called instead.

    List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
    for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext();) {
    	ExporterFactory exFactory = iter.next();
    	if (!exFactory.isEnabled(configuration)) {
    		iter.remove();
    	}
    }
    if (attributes.isUseExternalProcess()) {
    	// create temporary build.xml and then erase it after code generation complete
    	String fileName = null;
    	try {
    		fileName = getPath2GenBuildXml().toString();
        	createBuildXmlFile(configuration, fileName);
    	} catch (UnsupportedEncodingException e) {
    		throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
    	} catch (IOException e) {
    		throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
    	}
    	configuration = updateLaunchConfig(configuration);
    	super.launch(configuration, mode, launch, monitor);
       	//
       	final Properties props = new Properties();
              props.put(CodeGenerationStrings.EJB3, "" + attributes.isEJB3Enabled()); //$NON-NLS-1$
              props.put(CodeGenerationStrings.JDK5, "" + attributes.isJDK5Enabled()); //$NON-NLS-1$
              Set<String> outputDirs = new HashSet<String>();
    	for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext();) {
    		ExporterFactory exFactory = iter.next();
    		exFactory.collectOutputDirectories(attributes.getOutputPath(),
    				props, outputDirs);
    	}
    	//
    	final IProcess[] processes = launch.getProcesses();
    	// codegen listener to erase build.xml file after codegen process complete
    	CodeGenerationProcessListener refresher = new CodeGenerationProcessListener(
    		processes[0], fileName, outputDirs);
    	refresher.startBackgroundRefresh();
    	return;
       }
    try {
        Set<String> outputDirectories = new HashSet<String>();
        ExporterFactory[] exporters = exporterFactories.toArray( new ExporterFactory[exporterFactories.size()] );
              ArtifactCollector collector = runExporters(attributes, exporters, outputDirectories, monitor);

              for (String path : outputDirectories) {
              	CodeGenerationUtils.refreshOutputDir(path);
    	}

    	RefreshTab.refreshResources(configuration, monitor);

    	// code formatting needs to happen *after* refresh to make sure eclipse will format the uptodate files!
              if(collector!=null) {
              	formatGeneratedCode( monitor, collector );
    	}


    } catch(Exception e) {
    	throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
    } catch(NoClassDefFoundError e) {
    	throw new CoreException(HibernateConsolePlugin.throwableToStatus(new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_received_noclassdeffounderror,e), 666));
    } finally {
    	monitor.done();
    }*/

  }