public int compare(ICFBamRelationObj lhs, ICFBamRelationObj rhs) {
   if (lhs == null) {
     if (rhs == null) {
       return (0);
     } else {
       return (-1);
     }
   } else if (rhs == null) {
     return (1);
   } else {
     String lhsValue = lhs.getObjQualifiedName();
     String rhsValue = rhs.getObjQualifiedName();
     if (lhsValue == null) {
       if (rhsValue == null) {
         return (0);
       } else {
         return (-1);
       }
     } else if (rhsValue == null) {
       return (1);
     } else {
       return (lhsValue.compareTo(rhsValue));
     }
   }
 }
 protected ICFBamRelationObj resolveInheritedRelation(
     ICFBamRelationTableObj relationTable, ICFBamTableObj tbl, String relName) {
   ICFBamRelationObj curRelation;
   ICFBamRelationObj superRelation;
   ICFBamRelationObj retval = null;
   ICFBamTableObj curTable = tbl;
   while ((retval == null) && (curTable != null)) {
     retval =
         relationTable.readRelationByUNameIdx(
             curTable.getRequiredTenantId(), curTable.getRequiredId(), relName);
     if (retval == null) {
       Iterator<ICFBamRelationObj> relIter = curTable.getOptionalComponentsRelation().iterator();
       superRelation = null;
       while ((superRelation == null) && relIter.hasNext()) {
         curRelation = relIter.next();
         if (curRelation.getRequiredLookupRelationType().getRequiredTag().equals("Superclass")) {
           superRelation = curRelation;
         }
       }
       if (superRelation != null) {
         curTable = superRelation.getRequiredLookupToTable();
       } else {
         curTable = null;
       }
     }
   }
   return (retval);
 }
  /**
   * The core evaluation of ColumnInOwnerLookupRelation is also to determine if an index definition
   * is in an owner relation.
   *
   * <p>WORKING: Yes, I know. This should be a business method instead of copying the code in
   * ICFBamIndexObj and MSIsaGenBindColumnInOwnerLookupRelation.
   *
   * @param genDef to be considered
   * @return True if the column participates in an owner relation.
   */
  public static Boolean isColumnInContainerOrNamedLookupRelation(ICFLibAnyObj genDef) {

    ICFLibAnyObj focusDef;
    ICFBamTableObj tableDef;
    final String S_ProcName = "isColumnInContainerOrNamedLookupRelation";

    if (genDef instanceof ICFBamAtomObj) {
      ICFBamAtomObj atomDef = (ICFBamAtomObj) genDef;
      ICFLibAnyObj atomScopeDef = atomDef.getObjScope();
      tableDef = (ICFBamTableObj) atomScopeDef;
      focusDef = genDef;
    } else if (genDef instanceof ICFBamTableColObj) {
      ICFBamTableColObj tableColDef = (ICFBamTableColObj) genDef;
      ICFLibAnyObj tableColScopeDef = tableColDef.getObjScope();
      tableDef = (ICFBamTableObj) tableColScopeDef;
      focusDef = genDef;
    } else if (genDef instanceof ICFBamIndexColObj) {
      ICFBamIndexColObj indexColDef = (ICFBamIndexColObj) genDef;
      focusDef = indexColDef.getRequiredLookupColumn();
      if (focusDef instanceof ICFBamAtomObj) {
        tableDef = (ICFBamTableObj) ((ICFBamAtomObj) focusDef).getObjScope();
      } else if (focusDef instanceof ICFBamTableColObj) {
        tableDef = (ICFBamTableObj) ((ICFBamTableColObj) focusDef).getObjScope();
      } else {
        throw CFLib.getDefaultExceptionFactory()
            .newUnsupportedClassException(
                MSSBamCFGenBindColumnInContainerOrNamedLookupRelation.class,
                S_ProcName,
                "genContext.GenDef.LookupColumn",
                genDef,
                "ICFBamAtomObj, ICFBamTableColObj");
      }
    } else if (genDef instanceof ICFBamRelationColObj) {
      ICFBamRelationColObj relColDef = (ICFBamRelationColObj) genDef;
      ICFLibAnyObj columnDef = relColDef.getRequiredLookupFromCol();
      if (columnDef instanceof ICFBamAtomObj) {
        focusDef = columnDef;
        tableDef = (ICFBamTableObj) columnDef.getObjScope();
      } else if (columnDef instanceof ICFBamTableColObj) {
        focusDef = columnDef;
        tableDef = (ICFBamTableObj) columnDef.getObjScope();
      } else {
        throw CFLib.getDefaultExceptionFactory()
            .newUnsupportedClassException(
                MSSBamCFGenBindColumnInContainerOrNamedLookupRelation.class,
                S_ProcName,
                "genContext.GenDef.FromCol",
                genDef,
                "ICFBamAtomObj, ICFBamTableColObj");
      }
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              MSSBamCFGenBindColumnInContainerOrNamedLookupRelation.class,
              S_ProcName,
              "genContext.GenDef",
              genDef,
              "ICFBamAtomObj, ICFBamTableColObj, ICFBamIndexColObj, ICFBamRelationColObj");
    }

    List<ICFBamRelationObj> containerNamedLookupRelations =
        MSSBamCFTableObj.getOwnerContainerNamedLookupChainRelations(tableDef);
    if ((containerNamedLookupRelations == null)
        || ((containerNamedLookupRelations != null)
            && (containerNamedLookupRelations.size() == 0))) {
      return (false);
    }

    ListIterator<ICFBamRelationObj> ownerEnumerator = containerNamedLookupRelations.listIterator();

    ICFBamRelationObj ownerRelation;
    ICFBamRelationColObj ownerRelationCol;
    ICFBamIndexColObj indexCol;
    Iterator<ICFBamRelationColObj> ownerRelationCols;

    while (ownerEnumerator.hasNext()) {

      ownerRelation = ownerEnumerator.next();
      ownerRelationCols = ownerRelation.getOptionalComponentsColumns().iterator();
      while (ownerRelationCols.hasNext()) {
        ownerRelationCol = ownerRelationCols.next();
        indexCol = ownerRelationCol.getRequiredLookupFromCol();
        if (indexCol.getRequiredLookupColumn() == focusDef) {
          return (true);
        }
      }
    }

    return (false);
  }
 public Object getValueAt(int row, int column) {
   if ((row < 0) || (column < -1)) {
     return (null);
   }
   if (arrayOfRelation == null) {
     return (null);
   }
   int len = arrayOfRelation.length;
   if (row >= len) {
     return (null);
   }
   ICFBamRelationObj obj = arrayOfRelation[row];
   if (obj == null) {
     return (null);
   }
   Object retval;
   switch (column) {
     case COLID_ROW_HEADER:
       retval = obj;
       break;
     case COLID_OBJQUALIFIEDNAME:
       retval = obj.getObjQualifiedName();
       break;
     case COLID_ID:
       retval = new Long(obj.getRequiredId());
       break;
     case COLID_NAME:
       retval = obj.getRequiredName();
       if (retval == null) {
         retval = "";
       }
       break;
     case COLID_SHORTNAME:
       retval = obj.getOptionalShortName();
       if (retval == null) {
         retval = "";
       }
       break;
     case COLID_LABEL:
       retval = obj.getOptionalLabel();
       if (retval == null) {
         retval = "";
       }
       break;
     case COLID_SHORTDESCRIPTION:
       retval = obj.getOptionalShortDescription();
       if (retval == null) {
         retval = "";
       }
       break;
     case COLID_DESCRIPTION:
       retval = obj.getOptionalDescription();
       if (retval == null) {
         retval = "";
       }
       break;
     case COLID_DBNAME:
       retval = obj.getOptionalDbName();
       if (retval == null) {
         retval = "";
       }
       break;
     case COLID_SUFFIX:
       retval = obj.getOptionalSuffix();
       if (retval == null) {
         retval = "";
       }
       break;
     case COLID_ISREQUIRED:
       retval = new Boolean(obj.getRequiredIsRequired());
       break;
     case COLID_ISABSTRACT:
       retval = new Boolean(obj.getRequiredIsAbstract());
       break;
     case COLID_ISXSDCONTAINER:
       retval = new Boolean(obj.getRequiredIsXsdContainer());
       break;
     case COLID_DEFAULTVISIBILITY:
       retval = new Boolean(obj.getRequiredDefaultVisibility());
       break;
     case COLID_LOOKUP_RELATIONTYPE:
       retval = obj.getRequiredLookupRelationType();
       break;
     case COLID_LOOKUP_DEFSCHEMA:
       retval = obj.getOptionalLookupDefSchema();
       break;
     case COLID_LOOKUP_FROMINDEX:
       retval = obj.getRequiredLookupFromIndex();
       break;
     case COLID_LOOKUP_TOTABLE:
       retval = obj.getRequiredLookupToTable();
       break;
     case COLID_LOOKUP_TOINDEX:
       retval = obj.getRequiredLookupToIndex();
       break;
     case COLID_LOOKUP_NARROWED:
       retval = obj.getOptionalLookupNarrowed();
       break;
     default:
       retval = null;
       break;
   }
   return (retval);
 }
  public void startElement(String uri, String localName, String qName, Attributes attrs)
      throws SAXException {
    try {
      // Common XML Attributes
      String attrId = null;
      // ClearDep Attributes
      String attrName = null;
      String attrClearDepChain = null;
      // Attribute Extraction
      String attrLocalName;
      int numAttrs;
      int idxAttr;
      final String S_ProcName = "startElement";
      final String S_LocalName = "LocalName";

      assert qName.equals("ClearDep");

      CFBamXmlLoader saxLoader = (CFBamXmlLoader) getParser();
      if (saxLoader == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "getParser()");
      }

      ICFBamSchemaObj schemaObj = saxLoader.getSchemaObj();
      if (schemaObj == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()");
      }

      // Extract Attributes
      numAttrs = attrs.getLength();
      for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
        attrLocalName = attrs.getLocalName(idxAttr);
        if (attrLocalName.equals("Id")) {
          if (attrId != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrId = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("Name")) {
          if (attrName != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrName = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("ClearDepChain")) {
          if (attrClearDepChain != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrClearDepChain = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("schemaLocation")) {
          // ignored
        } else {
          throw CFLib.getDefaultExceptionFactory()
              .newUnrecognizedAttributeException(
                  getClass(), S_ProcName, saxLoader.getLocationInfo(), attrLocalName);
        }
      }

      // Ensure that required attributes have values
      if ((attrName == null) || (attrName.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "Name");
      }

      if ((attrClearDepChain == null) || (attrClearDepChain.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "ClearDepChain");
      }

      // Save named attributes to context
      CFLibXmlCoreContext curContext = saxLoader.getCurContext();
      if (!CFBamXmlLoader.getProcessSchema(curContext)) {
        return;
      }

      curContext.putNamedValue("Id", attrId);
      curContext.putNamedValue("Name", attrName);
      curContext.putNamedValue("ClearDepChain", attrClearDepChain);

      if (!CFBamXmlLoader.getProcessSchema(curContext)) {
        return;
      }

      CFLibXmlCoreContext parentContext = curContext.getPrevContext();
      ICFBamTableObj fromTable;
      if (parentContext != null) {
        fromTable = (ICFBamTableObj) parentContext.getNamedValue("Object");
      } else {
        fromTable = null;
      }
      if (fromTable == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newRuntimeException(
                getClass(),
                S_ProcName,
                saxLoader.getLocationInfo() + " PrevContext.Object is null, Table is required");
      }

      ICFBamRelationTableObj relationTable = schemaObj.getRelationTableObj();

      int firstDot;

      ICFBamTableObj curTable = fromTable;
      firstDot = attrClearDepChain.indexOf('.');
      String nextRelationName;
      String remainder;
      if (firstDot > 0) {
        nextRelationName = attrClearDepChain.substring(0, firstDot);
        remainder = attrClearDepChain.substring(firstDot + 1);
      } else {
        nextRelationName = attrClearDepChain;
        remainder = null;
      }
      ICFBamRelationObj resolvedRelation =
          resolveInheritedRelation(relationTable, curTable, nextRelationName);
      if (resolvedRelation == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newRuntimeException(
                getClass(),
                S_ProcName,
                saxLoader.getLocationInfo()
                    + "Relation \""
                    + nextRelationName
                    + "\" not found for table \""
                    + curTable.getRequiredContainerSchemaDef().getRequiredName()
                    + "."
                    + curTable.getRequiredName()
                    + "\"");
      }
      ICFBamClearTopDepObj origTopDep = schemaObj.getClearTopDepTableObj().newInstance();
      ICFBamClearTopDepEditObj editTopDep = (ICFBamClearTopDepEditObj) origTopDep.beginEdit();
      editTopDep.setRequiredOwnerTenant(fromTable.getRequiredOwnerTenant());
      editTopDep.setRequiredContainerContTable(fromTable);
      editTopDep.setRequiredName(attrName);
      editTopDep.setRequiredLookupRelation(resolvedRelation);
      origTopDep = (ICFBamClearTopDepObj) editTopDep.create();

      curContext.putNamedValue("Object", origTopDep);

      if (remainder != null) {
        curTable = origTopDep.getRequiredLookupRelation().getRequiredLookupToTable();
        firstDot = remainder.indexOf('.');
        if (firstDot > 0) {
          nextRelationName = remainder.substring(0, firstDot);
          remainder = remainder.substring(firstDot + 1);
        } else {
          nextRelationName = remainder;
          remainder = null;
        }
        resolvedRelation = resolveInheritedRelation(relationTable, curTable, nextRelationName);
        if (resolvedRelation == null) {
          throw CFLib.getDefaultExceptionFactory()
              .newRuntimeException(
                  getClass(),
                  S_ProcName,
                  saxLoader.getLocationInfo()
                      + "Relation \""
                      + nextRelationName
                      + "\" not found for table \""
                      + curTable.getRequiredContainerSchemaDef().getRequiredName()
                      + "."
                      + curTable.getRequiredName()
                      + "\"");
        }
        ICFBamClearSubDep1Obj origSubDep1 = schemaObj.getClearSubDep1TableObj().newInstance();
        ICFBamClearSubDep1EditObj editSubDep1 = (ICFBamClearSubDep1EditObj) origSubDep1.beginEdit();
        editSubDep1.setRequiredOwnerTenant(fromTable.getRequiredOwnerTenant());
        editSubDep1.setRequiredContainerContClearTopDep(origTopDep);
        editSubDep1.setRequiredName(resolvedRelation.getRequiredName());
        editSubDep1.setRequiredLookupRelation(resolvedRelation);
        origSubDep1 = (ICFBamClearSubDep1Obj) editSubDep1.create();

        if (remainder != null) {
          curTable = origSubDep1.getRequiredLookupRelation().getRequiredLookupToTable();
          firstDot = remainder.indexOf('.');
          if (firstDot > 0) {
            nextRelationName = remainder.substring(0, firstDot);
            remainder = remainder.substring(firstDot + 1);
          } else {
            nextRelationName = remainder;
            remainder = null;
          }
          resolvedRelation = resolveInheritedRelation(relationTable, curTable, nextRelationName);
          if (resolvedRelation == null) {
            throw CFLib.getDefaultExceptionFactory()
                .newRuntimeException(
                    getClass(),
                    S_ProcName,
                    saxLoader.getLocationInfo()
                        + "Relation \""
                        + nextRelationName
                        + "\" not found for table \""
                        + curTable.getRequiredContainerSchemaDef().getRequiredName()
                        + "."
                        + curTable.getRequiredName()
                        + "\"");
          }
          ICFBamClearSubDep2Obj origSubDep2 = schemaObj.getClearSubDep2TableObj().newInstance();
          ICFBamClearSubDep2EditObj editSubDep2 =
              (ICFBamClearSubDep2EditObj) origSubDep2.beginEdit();
          editSubDep2.setRequiredOwnerTenant(fromTable.getRequiredOwnerTenant());
          editSubDep2.setRequiredContainerContClearSubDep1(origSubDep1);
          editSubDep2.setRequiredName(resolvedRelation.getRequiredName());
          editSubDep2.setRequiredLookupRelation(resolvedRelation);
          origSubDep2 = (ICFBamClearSubDep2Obj) editSubDep2.create();

          if (remainder != null) {
            curTable = origSubDep2.getRequiredLookupRelation().getRequiredLookupToTable();
            firstDot = remainder.indexOf('.');
            if (firstDot > 0) {
              throw CFLib.getDefaultExceptionFactory()
                  .newRuntimeException(
                      getClass(),
                      S_ProcName,
                      saxLoader.getLocationInfo()
                          + "Relation ClearDepChain is invalid -- only 4 levels of indirection are supported");
            } else {
              nextRelationName = remainder;
              remainder = null;
            }
            resolvedRelation = resolveInheritedRelation(relationTable, curTable, nextRelationName);
            if (resolvedRelation == null) {
              throw CFLib.getDefaultExceptionFactory()
                  .newRuntimeException(
                      getClass(),
                      S_ProcName,
                      saxLoader.getLocationInfo()
                          + "Relation \""
                          + nextRelationName
                          + "\" not found for table \""
                          + curTable.getRequiredContainerSchemaDef().getRequiredName()
                          + "."
                          + curTable.getRequiredName()
                          + "\"");
            }
            ICFBamClearSubDep3Obj origSubDep3 = schemaObj.getClearSubDep3TableObj().newInstance();
            ICFBamClearSubDep3EditObj editSubDep3 =
                (ICFBamClearSubDep3EditObj) origSubDep3.beginEdit();
            editSubDep3.setRequiredOwnerTenant(fromTable.getRequiredOwnerTenant());
            editSubDep3.setRequiredContainerContClearSubDep2(origSubDep2);
            editSubDep3.setRequiredName(resolvedRelation.getRequiredName());
            editSubDep3.setRequiredLookupRelation(resolvedRelation);
            origSubDep3 = (ICFBamClearSubDep3Obj) editSubDep3.create();
          }
        }
      }
    } catch (RuntimeException e) {
      throw new RuntimeException(
          "Near "
              + getParser().getLocationInfo()
              + ": Caught and rethrew "
              + e.getClass().getName()
              + " - "
              + e.getMessage(),
          e);
    } catch (Error e) {
      throw new Error(
          "Near "
              + getParser().getLocationInfo()
              + ": Caught and rethrew "
              + e.getClass().getName()
              + " - "
              + e.getMessage(),
          e);
    }
  }