Exemplo n.º 1
0
  /**
   * Reads a XML schema
   *
   * @param input the input supplier
   * @return the schema
   * @throws IOProviderConfigurationException if the configuration of the reader is invalid
   * @throws IOException if reading the schema fails
   */
  private static Schema readXMLSchema(LocatableInputSupplier<? extends InputStream> input)
      throws IOProviderConfigurationException, IOException {
    XmlSchemaReader reader = new XmlSchemaReader();
    reader.setSharedTypes(new DefaultTypeIndex());
    reader.setSource(input);

    reader.validate();
    IOReport report = reader.execute(null);

    assertTrue(report.isSuccess());
    assertTrue("Errors are contained in the report", report.getErrors().isEmpty());

    return reader.getSchema();
  }
Exemplo n.º 2
0
  private static Alignment loadAlignment(
      URI sourceSchemaLocation, URI targetSchemaLocation, final URI alignmentLocation)
      throws IOProviderConfigurationException, IOException {

    // load source schema
    Schema source = readXMLSchema(new DefaultInputSupplier(sourceSchemaLocation));

    // load target schema
    Schema target = readXMLSchema(new DefaultInputSupplier(targetSchemaLocation));

    OmlReader reader = new OmlReader();

    reader.setSourceSchema(source);
    reader.setTargetSchema(target);
    reader.setSource(new DefaultInputSupplier(alignmentLocation));

    reader.validate();

    IOReport report = reader.execute(null);

    assertTrue(report.isSuccess());

    return reader.getAlignment();
  }
Exemplo n.º 3
0
  /**
   * @see Wizard#performFinish()
   * @return <code>true</code> if executing the I/O provider was successful
   */
  @Override
  public boolean performFinish() {
    if (getProvider() == null) {
      return false;
    }

    if (!applyConfiguration()) {
      return false;
    }

    // create default report
    IOReporter defReport = provider.createReporter();

    // validate and execute provider
    try {
      // validate configuration
      provider.validate();

      ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
      URI projectLoc = ps.getLoadLocation() == null ? null : ps.getLoadLocation();
      boolean isProjectResource = false;
      if (actionId != null) {
        // XXX instead move project resource to action?
        ActionUI factory = ActionUIExtension.getInstance().findActionUI(actionId);
        isProjectResource = factory.isProjectResource();
      }

      // prevent loading of duplicate resources
      if (isProjectResource && provider instanceof ImportProvider) {
        String currentResource = ((ImportProvider) provider).getSource().getLocation().toString();
        URI currentAbsolute = URI.create(currentResource);
        if (projectLoc != null && !currentAbsolute.isAbsolute())
          currentAbsolute = projectLoc.resolve(currentAbsolute);

        for (IOConfiguration conf : ((Project) ps.getProjectInfo()).getResources()) {
          Value otherResourceValue =
              conf.getProviderConfiguration().get(ImportProvider.PARAM_SOURCE);
          if (otherResourceValue == null) continue;

          String otherResource = otherResourceValue.as(String.class);
          URI otherAbsolute = URI.create(otherResource);
          if (projectLoc != null && !otherAbsolute.isAbsolute())
            otherAbsolute = projectLoc.resolve(otherAbsolute);
          String action = conf.getActionId();
          // resource is already loaded into the project
          if (currentAbsolute.equals(otherAbsolute) && Objects.equal(actionId, action)) {
            log.userError("Resource is already loaded. Loading duplicate resources is aborted!");
            return false;
          }
        }
      }

      // enable provider internal caching
      if (isProjectResource && provider instanceof CachingImportProvider) {
        ((CachingImportProvider) provider).setProvideCache();
      }

      IOReport report = execute(provider, defReport);

      if (report != null) {
        // add report to report server
        ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
        repService.addReport(report);

        // show message to user
        if (report.isSuccess()) {
          // no message, we rely on the report being shown/processed

          // let advisor handle results
          try {
            getContainer()
                .run(
                    true,
                    false,
                    new IRunnableWithProgress() {

                      @Override
                      public void run(IProgressMonitor monitor)
                          throws InvocationTargetException, InterruptedException {
                        monitor.beginTask("Completing operation...", IProgressMonitor.UNKNOWN);
                        try {
                          advisor.handleResults(getProvider());
                        } finally {
                          monitor.done();
                        }
                      }
                    });
          } catch (InvocationTargetException e) {
            log.userError(
                "Error processing results:\n" + e.getCause().getLocalizedMessage(), e.getCause());
            return false;
          } catch (Exception e) {
            log.userError("Error processing results:\n" + e.getLocalizedMessage(), e);
            return false;
          }

          // add to project service if necessary
          if (isProjectResource)
            ps.rememberIO(actionId, getProviderFactory().getIdentifier(), provider);

          return true;
        } else {
          // error message
          log.userError(report.getSummary() + "\nPlease see the report for details.");
          return false;
        }
      } else return true;
    } catch (IOProviderConfigurationException e) {
      // user feedback
      log.userError(
          "Validation of the provider configuration failed:\n" + e.getLocalizedMessage(), e);
      return false;
    }
  }