private void createAndRevealDiagram(
      DefaultMainFrame mainFrame,
      DbJVPackage topMostPackage,
      Controller controller,
      int startJobDone,
      int endJobDone)
      throws DbException {

    controller.checkPoint(startJobDone);
    DbOODiagram topMostDiagram = null;

    // create a diagram for each imported package
    int i = 0, nb = m_importedPackages.size();
    int span = endJobDone - startJobDone;
    for (DbJVPackage pack : m_importedPackages) {
      DbOODiagram diagram = new DbOODiagram(pack);
      CreateMissingGraphicsAction.createOOGraphics(diagram, (Point) null);
      new JVDiagramLayout(diagram, (GraphicComponent[]) null);

      if (pack.equals(topMostPackage)) {
        topMostDiagram = diagram;
      }

      int jobDone = startJobDone + (i * span) / nb;
      controller.checkPoint(jobDone);
      i++;
    } // end for

    if (topMostDiagram != null) {
      mainFrame.addDiagramInternalFrame(topMostDiagram);
      mainFrame.findInExplorer(topMostDiagram);
    }

    controller.checkPoint(endJobDone);
  } // end createAndRevealDiagram()
  private DbJVPackage findTopMostPackage(DbJVPackage pack1, DbJVPackage pack2) throws DbException {
    DbJVPackage topMostPackage;

    if (pack1 == null) {
      topMostPackage = pack2;
    } else if (pack2 == null) {
      topMostPackage = pack1;
    } else {
      String s1 = pack1.buildFullNameString();
      String s2 = pack2.buildFullNameString();
      int p1 = count(s1, '.');
      int p2 = count(s2, '.');
      topMostPackage = (p1 <= p2) ? pack1 : pack2;
    } // end if

    return topMostPackage;
  }
  private DbJVPackage findPackageByName(DbOOAbsPackage parent, String packageName)
      throws DbException {
    DbJVPackage foundPackage = null;

    DbRelationN relN = parent.getComponents();
    DbEnumeration enu = relN.elements(DbJVPackage.metaClass);
    while (enu.hasMoreElements()) {
      DbJVPackage pack = (DbJVPackage) enu.nextElement();
      String name = pack.getName();
      if (packageName.equals(name)) {
        foundPackage = pack;
        break;
      }
    } // end while
    enu.close();

    return foundPackage;
  }
  private DbJVPackage findPackageByName(String qualifiedPackageName) throws DbException {
    DbJVPackage pack = packages.get(qualifiedPackageName);

    if (pack == null) {
      DbOOAbsPackage parent = m_classModel;
      StringTokenizer st = new StringTokenizer(qualifiedPackageName, ".");

      while (st.hasMoreElements()) {
        String token = st.nextToken();
        pack = findPackageByName(parent, token);
        if (pack == null) {
          pack = new DbJVPackage(parent);
          pack.setName(token);
        } // end if
        parent = pack;
      } // end while

      packages.put(qualifiedPackageName, pack);
    } // end if

    return pack;
  }
  private DbOOAdt findClassByName(DbJVPackage pack, String classname) throws DbException {
    DbJVClass foundClass = null;

    DbRelationN relN = (pack == null) ? m_classModel.getComponents() : pack.getComponents();
    DbEnumeration enu = relN.elements(DbJVClass.metaClass);
    while (enu.hasMoreElements()) {
      DbJVClass claz = (DbJVClass) enu.nextElement();
      String name = claz.getName();
      if (classname.equals(name)) {
        foundClass = claz;
        break;
      }
    } // end while
    enu.close();

    if (foundClass == null) {
      JVClassCategory catg = JVClassCategory.getInstance(JVClassCategory.CLASS);
      foundClass = (pack == null) ? new DbJVClass(m_classModel, catg) : new DbJVClass(pack, catg);
      foundClass.setName(classname);
      types.put(classname, foundClass);
    }

    return foundClass;
  } // end findClassByName()