Пример #1
0
  public static Ooaofooa getInstance(String id, boolean forceLoad) {
    Ooaofooa modelRoot = Ooaofooa.getInstance(id);

    if (forceLoad && isFileBasedID(id) && !modelRoot.isLoaded()) {
      String projectName = getProjectNameFromModelRootId(id);
      String fileName = getDomainFileNameFromModelRootId(id);
      IProject[] project_set = CorePlugin.getWorkspace().getRoot().getProjects();
      IFile content = null;
      for (int i = 0; i < project_set.length; ++i) {
        if (XtUMLNature.hasNature(project_set[i])) {
          if (project_set[i].getName().equals(projectName)) {
            IResource mdl_folder = project_set[i].findMember(MODELS_DIRNAME);
            IResource[] mdl_content = null;
            try {
              mdl_content = ((IFolder) mdl_folder).members();
            } catch (Exception e) {
              CorePlugin.logError("Problem accessing workspace ", e);
            }
            if (mdl_content != null) {
              for (int j = 0; j < mdl_content.length; ++j) {
                if (mdl_content[j] instanceof IFile) {
                  IFile selected = (IFile) mdl_content[j];
                  if (selected.getName().equals(fileName)) {
                    content = selected;
                    break;
                  }
                }
              }
            }
          }
        }
      }
      if (content != null) {
        modelRoot = getInstance(content, true);
        if (!modelRoot.loadedOk()) {
          modelRoot.delete();
          modelRoot = null;
        }
      }
    }

    return modelRoot;
  }
Пример #2
0
  /** Returns the model-root associated with the content of the given file. */
  public static Ooaofooa getInstance(IFile file, boolean forceLoad) {
    boolean addExtension = false;
    String domainName = file.getName();
    IPath filePath = file.getFullPath();
    if (filePath.segmentCount() > 5) {
      domainName = filePath.removeLastSegments(filePath.segmentCount() - 4).lastSegment();
      addExtension = true;
    }

    final String id = createModelRootId(file.getProject(), domainName, addExtension);
    Ooaofooa modelRoot = (Ooaofooa) rootInstanceMap.get(id);
    if (modelRoot == null) {
      modelRoot = getInstance(id, false);
    }

    if (forceLoad && !modelRoot.isLoaded()) {
      modelRoot = loadInstanceFromFile(file);
    }
    return modelRoot;
  }