예제 #1
0
  public boolean expand(Writer output, Serializable object, RuleOptions options)
      throws IOException, RuleException {
    boolean expanded = false;
    boolean prefixPrinted = false;
    boolean atLeastOneChildPrinted = false;

    if (object == null) {
      if (Debug.isDebug()) {
        throw new NullPointerException(); // disclose programming error
        // in debug..
      } else {
        return false;
      }
    } // end if

    if (!(object instanceof DbObject)) {
      return false;
    } // end if

    DbObject dbObject = (DbObject) object;
    MetaRelationship metaRelation = getMetaRelation(dbObject);
    MetaClass childrenMetaClass = getChildrenMetaClass();

    try {
      // get metaRelation from its string representation
      if (metaRelation == null)
        metaRelation = (MetaRelationship) getMetaField(dbObject, sConnector);

      boolean state[] = {prefixPrinted, atLeastOneChildPrinted};

      if (metaRelation instanceof MetaRelation1) {
        MetaRelation1 metaRelation1 = (MetaRelation1) metaRelation;
        expanded |=
            expandMetaRelation1(output, dbObject, metaRelation1, state, childrenMetaClass, options);
      } else if (metaRelation instanceof MetaRelationN) {
        expanded |=
            expandMetaRelationN(output, dbObject, metaRelation, state, childrenMetaClass, options);
      } else if (metaRelation instanceof MetaChoice) {
        MetaChoice choice = (MetaChoice) metaRelation;
        expanded |= expandMetaChoice(output, dbObject, choice, state, childrenMetaClass, options);
      } else {
        // TODO: throw 'meta-relationship not supported'
      }

      super.terminate(output, options);
    } catch (DbException ex) {
      String msg = ex.getMessage();
      throw new RuleException(msg);
    } catch (RuntimeException ex) {
      String conn = m_connector.getGUIName();
      String objectKind = dbObject.getMetaClass().getGUIName();
      String msg = InvalidConnectorRuleException.buildMessage(m_ruleName, conn, objectKind);
      throw new InvalidConnectorRuleException(msg);
    }

    return expanded;
  }
  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()
예제 #3
0
파일: HeapFile.java 프로젝트: ntgsx92/cs143
 // see DbFile.java for javadocs
 public DbFileIterator iterator(TransactionId tid) {
   try {
     return new HeapFileIterator(tid, this);
   } catch (DbException dbe) {
     dbe.printStackTrace();
   } catch (TransactionAbortedException transe) {
     transe.printStackTrace();
   } catch (NoSuchElementException nosuche) {
     nosuche.printStackTrace();
   }
   return null;
 }
  @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()