示例#1
0
 public static void addInstance(ModelRoot modelRoot) {
   rootInstanceMap.put(modelRoot.getId(), (OoaofooaBase) modelRoot);
 }
示例#2
0
  /**
   * Loads (and returns) the instance of this class from the given file to which it previously had
   * been persisted.
   */
  private static Ooaofooa loadInstanceFromFile(IFile file) {
    // find the system-model that corresponds to the project
    // containing the given file
    final String projectName = file.getProject().getName();
    final SystemModel_c system =
        SystemModel_c.SystemModelInstances(
            Ooaofooa.getDefaultInstance(),
            new ClassQueryInterface_c() {
              public boolean evaluate(Object candidate) {
                SystemModel_c selected = (SystemModel_c) candidate;
                return selected.getName().equals(projectName);
              }
            })[0];

    // open an input-stream on the given file
    InputStream inStream = null;
    try {
      inStream = new FileInputStream(file.getLocation().toString());
    } catch (FileNotFoundException e) {
      CorePlugin.logError(
          "Internal error: failed to open " + file.getLocation().toString(), e); // $$NON-NLS-1$$
      return null;
    }

    // detm the instance's ID from the file's path
    final String id = createModelRootId(file.getProject(), file.getName(), false);

    // the enclosed could take a bit of time, so put up a busy indicator
    final InputStream finalInStream = inStream;
    BusyIndicator.showWhile(
        Display.getCurrent(),
        new Runnable() {
          public void run() {
            // load the instance from the stream and have it be associated
            // with the system-model found above
            String result =
                CorePlugin.getDefault()
                    .doLoad(system, id, finalInStream, new NullProgressMonitor(), false, false);
            if (!result.equals("")) {
              Ooaofooa modelRoot = getInstance(id, false);
              modelRoot.loadErrorMessage = result;
            }
          }
        });

    // close the input-stream from which the model was loaded
    try {
      inStream.close();
    } catch (IOException e) {
      CorePlugin.logError("Error closing stream after import", e);
    }

    // make sure the domain and file name are in sync
    Ooaofooa modelRoot = getInstance(id, false);
    if (modelRoot.loadedOk()) {
      Domain_c dom = Domain_c.DomainInstance(modelRoot);
      String fn = file.getName();
      String domName = fn.substring(0, fn.length() - MODELS_EXT.length() - 1);

      ModelRoot.disableChangeNotification();
      try {
        dom.setName(domName);
      } finally {
        ModelRoot.enableChangeNotification();
      }
    }

    // return the loaded instance
    return modelRoot;
  }