コード例 #1
0
  private DbJVPackage importFiles(Controller controller, int startJobDone, int endJobDone)
      throws IOException, DbException {
    controller.checkPoint(startJobDone);
    DbJVPackage topMostPackage = null;

    List<File> filesToImport = m_params.getFilesToImport();
    List<ErrorReport> errorLog = new ArrayList<ErrorReport>();

    int i = 0, nb = filesToImport.size();

    String pattern = LocaleMgr.misc.getString("ThereAreNbFilesToImport");
    String msg = MessageFormat.format(pattern, nb);
    controller.println(msg);
    int span = endJobDone - startJobDone;

    for (File file : filesToImport) {
      String filename = file.toString();
      int idx = filename.lastIndexOf('.');
      String ext = (idx == -1) ? null : filename.substring(idx + 1);
      int jobDone = startJobDone + (i * span) / nb;

      try {
        if ("class".equals(ext)) {
          DbJVClass claz = importClassFile(filename, controller);
          if (claz != null) {
            DbJVPackage pack = (DbJVPackage) claz.getCompositeOfType(DbJVPackage.metaClass);
            topMostPackage = findTopMostPackage(topMostPackage, pack);
            addToImportedPackage(pack);
          } // end if
        } else if ("jar".equals(ext)) {
          int nextJobDone = startJobDone + ((i + 1) * span) / nb;
          topMostPackage = importJarFile(file, topMostPackage, controller, jobDone, nextJobDone);
        } // end if
      } catch (Throwable th) {
        ErrorReport report = new ErrorReport(file, th);
        errorLog.add(report);
        controller.incrementErrorsCounter();
      } // end try

      // check job done
      i++;
      controller.checkPoint(jobDone);

      // stop to reverse engineer if user has cancelled
      boolean finished = controller.isFinalState();
      if (finished) {
        break;
      }
    } // end for

    if (!errorLog.isEmpty()) {
      reportErrors(errorLog, controller);
    } // end if

    controller.checkPoint(endJobDone);
    return topMostPackage;
  } // end importFiles()
コード例 #2
0
  private DbJVPackage importJarFile(
      File jarFile,
      DbJVPackage topMostPackage,
      Controller controller,
      int startJobDone,
      int endJobDone)
      throws DbException {
    DbJVClass dbClass;
    String filename = jarFile.getName();

    try {
      ZipFile zip = new ZipFile(jarFile);
      int i = 0, nb = zip.size();
      int span = endJobDone - startJobDone;

      for (Enumeration<?> e = zip.entries(); e.hasMoreElements(); ) {
        int jobDone = startJobDone + (i * span) / nb;

        ZipEntry entry = (ZipEntry) e.nextElement();
        String entryName = entry.getName();
        int idx = entryName.lastIndexOf('.');
        String ext = (idx == -1) ? null : entryName.substring(idx + 1);
        if ("class".equals(ext)) {
          InputStream is = zip.getInputStream(entry);

          ClassParser parser = new ClassParser(is, filename);
          JavaClass claz = parser.parse();
          dbClass = importClass(claz, controller);

          if (dbClass != null) {
            DbJVPackage pack = (DbJVPackage) dbClass.getCompositeOfType(DbJVPackage.metaClass);
            topMostPackage = findTopMostPackage(topMostPackage, pack);
            addToImportedPackage(pack);
          } // end if
        } // end if

        // check job done
        controller.checkPoint(jobDone);
        i++;

        // stop to reverse engineer if user has cancelled
        boolean finished = controller.isFinalState();
        if (finished) {
          break;
        }
      } // end for

      zip.close();

    } catch (IOException ex) {
      controller.println(ex.toString());
      dbClass = null;
    }

    return topMostPackage;
  } // end importClassFile()
コード例 #3
0
  private void importInheritance(DbJVClass dbClaz, String qualifiedName, boolean assumeInterface)
      throws DbException {
    DbOOAdt adt = findClassByName(qualifiedName);

    if (adt instanceof DbJVClass) {
      DbJVClass superType = (DbJVClass) adt;
      JVClassCategory categ =
          assumeInterface
              ? JVClassCategory.getInstance(JVClassCategory.INTERFACE)
              : JVClassCategory.getInstance(JVClassCategory.CLASS);
      superType.setStereotype(categ);
      new DbJVInheritance(dbClaz, superType);
    } // end if
  } // end findClassByName()
コード例 #4
0
  private DbJVClass importClass(JavaClass claz, Controller controller) throws DbException {

    String packName = claz.getPackageName();
    String qualifiedName = claz.getClassName();
    int idx = qualifiedName.lastIndexOf('.');
    String classname = qualifiedName.substring(idx + 1);
    DbJVClass dbClaz = null;

    try {
      if (m_classModel != null) {
        DbJVPackage pack = findPackageByName(packName);

        // create class or interface
        int value = claz.isInterface() ? JVClassCategory.INTERFACE : JVClassCategory.CLASS;
        JVClassCategory catg = JVClassCategory.getInstance(value);
        dbClaz =
            (pack == null) ? new DbJVClass(this.m_classModel, catg) : new DbJVClass(pack, catg);
        dbClaz.setName(classname);

        // set class modifiers
        dbClaz.setAbstract(claz.isAbstract());
        dbClaz.setFinal(claz.isFinal());
        dbClaz.setStatic(claz.isStatic());
        dbClaz.setStrictfp(claz.isStrictfp());
        dbClaz.setVisibility(toVisibility(claz));

        // create inheritances
        importInheritances(dbClaz, claz);

        // create fields
        if (m_params.createFields) {
          Field[] fields = claz.getFields();
          for (Field field : fields) {
            importField(dbClaz, field);
          }
        }

        // create methods
        if (m_params.createMethods) {
          Method[] methods = claz.getMethods();
          for (Method method : methods) {
            importMethod(dbClaz, method);
          }
        }

        // keep user informed of progression
        String pattern = LocaleMgr.misc.getString("0SuccessfullyCreated");
        String msg = MessageFormat.format(pattern, qualifiedName);
        controller.println(msg);
      } // end if
    } catch (DbException ex) {
      controller.println(ex.toString());
    } // end try

    return dbClaz;
  } // end importClass()
コード例 #5
0
  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()