Example #1
0
  /**
   * Execute the given provider
   *
   * @param provider the I/O provider
   * @param defaultReporter the default reporter that is used if the provider doesn't supply a
   *     report
   * @return the execution report, if null it will not give feedback to the user and the advisor's
   *     handleResult method won't be called either
   */
  protected IOReport execute(final IOProvider provider, final IOReporter defaultReporter) {
    // execute provider
    final AtomicReference<IOReport> report = new AtomicReference<IOReport>(defaultReporter);
    defaultReporter.setSuccess(false);
    try {
      getContainer()
          .run(
              true,
              provider.isCancelable(),
              new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                  ATransaction trans = log.begin(defaultReporter.getTaskName());
                  try {
                    IOReport result = provider.execute(new ProgressMonitorIndicator(monitor));
                    if (result != null) {
                      report.set(result);
                    } else {
                      defaultReporter.setSuccess(true);
                    }
                  } catch (Throwable e) {
                    defaultReporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
                  } finally {
                    trans.end();
                  }
                }
              });
    } catch (Throwable e) {
      defaultReporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
    }

    return report.get();
  }
Example #2
0
  @Override
  protected IOReport execute(ProgressIndicator progress, IOReporter reporter)
      throws IOProviderConfigurationException, IOException {
    progress.begin("Load schema", ProgressIndicator.UNKNOWN);
    try (InputStream in = getSource().getInput();
        Reader reader = new InputStreamReader(in, getCharset())) {
      schema = XmlToSchema.parseSchema(reader, new OsgiClassResolver(), reporter);

      reporter.setSuccess(true);
    } catch (Exception e) {
      reporter.error(new IOMessageImpl(e.getMessage(), e));
      reporter.setSuccess(false);
    } finally {
      progress.end();
    }
    return reporter;
  }