コード例 #1
0
  /** @param args */
  public static void main(String[] args) {
    try {
      File root =
          new File(
              "C:/development5/Javaforge Repositories/OpenModelSphere_905/trunk/workspace/org.modelsphere.jack/bin/org/modelsphere/jack/io");
      boolean exists = root.exists();

      if (exists) {
        Controller controller = new TextController();
        ReverseJavaBytecodeParameters params = new ReverseJavaBytecodeParameters();
        params.setSelectedFolder(root);
        Worker worker = new ReverseJavaBytecodeWorker(params);
        controller.start(worker);
      } // end if
    } catch (Exception ex) {
      ex.toString();
    }
  } // end main()
コード例 #2
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()
コード例 #3
0
  @Override
  protected void runJob() throws Exception {

    Controller controller = getController();

    // is invoked head less?
    DefaultMainFrame mainFrame = ApplicationContext.getDefaultMainFrame();
    boolean headless = (mainFrame == null);
    Db db = null;

    try {
      if (!headless) {
        // create new project, if it was not specific by the user
        m_project = m_params.getOutputProject();
        if (m_project == null) {
          m_project = (DbSMSProject) mainFrame.createDefaultProject(db);
        }

        db = m_project.getDb();
        db.beginWriteTrans(LocaleMgr.misc.getString("ImportJavaBytecode"));

        // create class model
        m_classModel = new DbJVClassModel(m_project);
      }

      // import Java classes files (jobDone 0% to 80%)
      DbJVPackage topMostPackage = importFiles(controller, 0, 80);

      // show success/failure message
      if (controller.getErrorsCount() == 0) {
        controller.println(LocaleMgr.misc.getString("Success"));
      } else {
        controller.println(LocaleMgr.misc.getString("Failed"));
      } // end if

      // create and reveal diagram ((jobDone 80% to 100%)
      if (!headless) {
        if ((topMostPackage != null) && (m_params.createDiagrams)) {
          createAndRevealDiagram(mainFrame, topMostPackage, controller, 80, 100);
        }

        db.commitTrans();
      } // end if

      controller.checkPoint(100);

    } catch (DbException ex) {
      controller.println(ex.toString());
      controller.cancel();
    } // end try
  } // end runJob()