Пример #1
0
  @NotNull
  @Override
  public SModel load(@NotNull DataSource dataSource, @NotNull Map<String, String> options)
      throws IOException {
    if (!(dataSource instanceof StreamDataSource)) {
      throw new UnsupportedDataSourceException(dataSource);
    }

    StreamDataSource source = (StreamDataSource) dataSource;
    SModelHeader binaryModelHeader;
    try {
      binaryModelHeader = BinaryPersistence.readHeader(source);
    } catch (ModelReadException e) {
      if (e.getCause() instanceof IOException) {
        throw (IOException) e.getCause();
      }
      throw new IOException(e.getMessageEx(), e);
    }
    if (Boolean.parseBoolean(options.get(MetaModelInfoProvider.OPTION_KEEP_READ_METAINFO))) {
      binaryModelHeader.setMetaInfoProvider(
          new StuffedMetaModelInfo(
              new RegularMetaModelInfo(binaryModelHeader.getModelReference())));
    }
    return new DefaultSModelDescriptor(new PersistenceFacility(this, source), binaryModelHeader);
  }
Пример #2
0
  @Override
  protected ModelLoadResult loadSModel(ModelLoadingState state) {
    DataSource source = getSource();
    if (!source.isReadOnly() && source.getTimestamp() == -1) {
      // no file on disk
      DefaultSModel model = new DefaultSModel(getReference(), myHeader);
      return new ModelLoadResult((SModel) model, ModelLoadingState.FULLY_LOADED);
    }

    ModelLoadResult result;
    try {
      result = myPersistence.readModel(myHeader, state);
    } catch (ModelReadException e) {
      LOG.warning(
          String.format("Failed to load model %s: %s", getSource().getLocation(), e.toString()));
      SuspiciousModelHandler.getHandler().handleSuspiciousModel(this, false);
      InvalidDefaultSModel newModel = new InvalidDefaultSModel(getReference(), e);
      return new ModelLoadResult((SModel) newModel, ModelLoadingState.NOT_LOADED);
    }

    jetbrains.mps.smodel.SModel model = result.getModel();
    if (result.getState() == ModelLoadingState.FULLY_LOADED) {
      boolean needToSave = model.updateSModelReferences() || model.updateModuleReferences();

      if (needToSave && !source.isReadOnly()) {
        setChanged(true);
      }
    }

    LOG.assertLog(
        model.getReference().equals(getReference()),
        "\nError loading model from: \""
            + source.getLocation()
            + "\"\n"
            + "expected model UID     : \""
            + getReference()
            + "\"\n"
            + "but was UID            : \""
            + model.getReference()
            + "\"\n"
            + "the model will not be available.\n"
            + "Make sure that all project's roots and/or the model namespace is correct");
    return result;
  }
Пример #3
0
 @NotNull
 @Override
 public Iterable<Problem> getProblems() {
   return Collections.<Problem>singleton(
       new PersistenceProblem(
           Kind.Load,
           myCause == null ? "Couldn't read model." : myCause.getMessageEx(),
           null,
           true));
 }