private Map<Byte, DbJVPrimitiveType> getJavaTypes() throws DbException {

    // if first call, build the map
    if (m_javaTypes == null) {
      m_javaTypes = new HashMap<Byte, DbJVPrimitiveType>();
      DbRelationN relN = m_project.getComponents();
      DbEnumeration enu = relN.elements(DbSMSBuiltInTypeNode.metaClass);
      while (enu.hasMoreElements()) {
        DbSMSBuiltInTypeNode typeNode = (DbSMSBuiltInTypeNode) enu.nextElement();
        DbRelationN relN2 = typeNode.getComponents();
        DbEnumeration enu2 = relN2.elements(DbSMSBuiltInTypePackage.metaClass);
        while (enu2.hasMoreElements()) {
          DbSMSBuiltInTypePackage pack = (DbSMSBuiltInTypePackage) enu2.nextElement();
          DbSMSTargetSystem ts = pack.getTargetSystem();
          if ("Java".equals(ts.getName())) {
            DbRelationN relN3 = pack.getComponents();
            DbEnumeration enu3 = relN3.elements(DbJVPrimitiveType.metaClass);
            while (enu3.hasMoreElements()) {
              DbJVPrimitiveType type = (DbJVPrimitiveType) enu3.nextElement();
              String name = type.getName();
              if ("boolean".equals(name)) {
                m_javaTypes.put(Constants.T_BOOLEAN, type);
              } else if ("byte".equals(name)) {
                m_javaTypes.put(Constants.T_BYTE, type);
              } else if ("short".equals(name)) {
                m_javaTypes.put(Constants.T_SHORT, type);
              } else if ("char".equals(name)) {
                m_javaTypes.put(Constants.T_CHAR, type);
              } else if ("int".equals(name)) {
                m_javaTypes.put(Constants.T_INT, type);
              } else if ("long".equals(name)) {
                m_javaTypes.put(Constants.T_LONG, type);
              } else if ("double".equals(name)) {
                m_javaTypes.put(Constants.T_DOUBLE, type);
              } else if ("float".equals(name)) {
                m_javaTypes.put(Constants.T_FLOAT, type);
              } // end if
            } // end while
            enu3.close();
          } // end if
          pack.getAlias();
        } // end while
        enu2.close();
      } // end while
      enu.close();
    } // end if

    return m_javaTypes;
  }
  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 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()
Пример #4
0
  // add childrenMetaClass to filter only children of that class
  // if null, scan each child
  protected boolean expandMetaRelationN(
      Writer output,
      DbObject object,
      MetaRelationship metaRelation,
      boolean state[],
      MetaClass childrenMetaClass,
      RuleOptions options)
      throws DbException, IOException, RuleException {

    boolean expanded = false;
    DbEnumeration dbEnumChildren = null;
    DbRelationN relationN = (DbRelationN) object.get(metaRelation);
    if (childrenMetaClass == null) {
      dbEnumChildren = relationN.elements();
    } else {
      dbEnumChildren = relationN.elements(childrenMetaClass);
    }

    // a first pass to find out the number of children
    int nbChildren = 0;
    try {
      while (dbEnumChildren.hasMoreElements()) {
        dbEnumChildren.nextElement();
        nbChildren++;

        // Cancel everything if the user has decided to stop the
        // operation
        if (options != null) {
          Controller controller = options.m_controller;
          if (controller != null) {
            boolean can_continue = controller.checkPoint();
            if (!can_continue) {
              throw new RuleException(controller.getAbortedString());
            }
          }
        } // end if
      } // end while
    } finally {
      dbEnumChildren.close();
    }

    // cannot rollback to the first element, so recreate the enumeration
    if (childrenMetaClass == null) {
      dbEnumChildren = relationN.elements();
    } else {
      dbEnumChildren = relationN.elements(childrenMetaClass);
    }

    try {
      while (dbEnumChildren.hasMoreElements()) {
        DbObject child = (DbObject) dbEnumChildren.nextElement();
        MetaClass metaClass = child.getMetaClass();
        String className = metaClass.getGUIName();
        boolean excluded = false;

        // check if child's class is excluded
        if (options != null) {
          excluded = options.isExcluded(className);

          // if not, check if parent's connection is excluded
          if (!excluded) {
            metaClass = object.getMetaClass();
            String parentClassName = metaClass.getGUIName();
            String connectionName = parentClassName + "." + metaRelation.getGUIName();
            excluded = options.isExcluded(connectionName);
          } // end if
        } // end if

        if (!excluded) {
          expanded |= expandChild(output, object, child, nbChildren, state, options);
        } // end if
      } // end while
    } finally {
      dbEnumChildren.close();
    }

    boolean atLeastOneChildPrinted = state[1];

    if ((atLeastOneChildPrinted) && (suffixModifier != null)) {
      expanded |= suffixModifier.expand(output, object, options);
    } else if ((!atLeastOneChildPrinted) && (nullModifier != null)) {
      expanded |= nullModifier.expand(output, object, options);
    }

    return expanded;
  } // end expandMetaRelationN