public ICFSecuritySecDeviceObj lockSecDevice(CFSecuritySecDevicePKey pkey) {
   ICFSecuritySecDeviceObj locked = null;
   CFSecuritySecDeviceBuff lockBuff =
       ((ICFSecuritySchema) schema.getBackingStore())
           .getTableSecDevice()
           .lockDerived(schema.getAuthorization(), pkey);
   if (lockBuff != null) {
     locked = schema.getSecDeviceTableObj().newInstance();
     locked.setPKey(
         ((ICFSecuritySchema) schema.getBackingStore()).getFactorySecDevice().newPKey());
     locked.setBuff(lockBuff);
     locked = (ICFSecuritySecDeviceObj) locked.realize();
   } else {
     throw CFLib.getDefaultExceptionFactory()
         .newCollisionDetectedException(getClass(), "lockSecDevice", pkey);
   }
   return (locked);
 }
 public ICFSecuritySecDeviceObj readSecDevice(CFSecuritySecDevicePKey pkey, boolean forceRead) {
   ICFSecuritySecDeviceObj obj = null;
   if ((!forceRead) && members.containsKey(pkey)) {
     obj = members.get(pkey);
   } else {
     CFSecuritySecDeviceBuff readBuff =
         ((ICFSecuritySchema) schema.getBackingStore())
             .getTableSecDevice()
             .readDerivedByIdIdx(
                 schema.getAuthorization(),
                 pkey.getRequiredSecUserId(),
                 pkey.getRequiredDevName());
     if (readBuff != null) {
       obj = schema.getSecDeviceTableObj().newInstance();
       obj.setPKey(((ICFSecuritySchema) schema.getBackingStore()).getFactorySecDevice().newPKey());
       obj.setBuff(readBuff);
       obj = (ICFSecuritySecDeviceObj) obj.realize();
     } else if (schema.getCacheMisses()) {
       members.put(pkey, null);
     }
   }
   return (obj);
 }
 public List<ICFSecuritySecDeviceObj> readSecDeviceByUserIdx(UUID SecUserId, boolean forceRead) {
   final String S_ProcName = "readSecDeviceByUserIdx";
   CFSecuritySecDeviceByUserIdxKey key =
       ((ICFSecuritySchema) schema.getBackingStore()).getFactorySecDevice().newUserIdxKey();
   key.setRequiredSecUserId(SecUserId);
   Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj> dict;
   if (indexByUserIdx == null) {
     indexByUserIdx =
         new HashMap<
             CFSecuritySecDeviceByUserIdxKey,
             Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj>>();
   }
   if ((!forceRead) && indexByUserIdx.containsKey(key)) {
     dict = indexByUserIdx.get(key);
   } else {
     dict = new HashMap<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj>();
     // Allow other threads to dirty-read while we're loading
     indexByUserIdx.put(key, dict);
     ICFSecuritySecDeviceObj obj;
     CFSecuritySecDeviceBuff[] buffList =
         ((ICFSecuritySchema) schema.getBackingStore())
             .getTableSecDevice()
             .readDerivedByUserIdx(schema.getAuthorization(), SecUserId);
     CFSecuritySecDeviceBuff buff;
     for (int idx = 0; idx < buffList.length; idx++) {
       buff = buffList[idx];
       obj = schema.getSecDeviceTableObj().newInstance();
       obj.setPKey(((ICFSecuritySchema) schema.getBackingStore()).getFactorySecDevice().newPKey());
       obj.setBuff(buff);
       ICFSecuritySecDeviceObj realized = (ICFSecuritySecDeviceObj) obj.realize();
     }
   }
   Comparator<ICFSecuritySecDeviceObj> cmp =
       new Comparator<ICFSecuritySecDeviceObj>() {
         public int compare(ICFSecuritySecDeviceObj lhs, ICFSecuritySecDeviceObj rhs) {
           if (lhs == null) {
             if (rhs == null) {
               return (0);
             } else {
               return (-1);
             }
           } else if (rhs == null) {
             return (1);
           } else {
             CFSecuritySecDevicePKey lhsPKey = lhs.getPKey();
             CFSecuritySecDevicePKey rhsPKey = rhs.getPKey();
             int ret = lhsPKey.compareTo(rhsPKey);
             return (ret);
           }
         }
       };
   int len = dict.size();
   ICFSecuritySecDeviceObj arr[] = new ICFSecuritySecDeviceObj[len];
   Iterator<ICFSecuritySecDeviceObj> valIter = dict.values().iterator();
   int idx = 0;
   while ((idx < len) && valIter.hasNext()) {
     arr[idx++] = valIter.next();
   }
   if (idx < len) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentUnderflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   } else if (valIter.hasNext()) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentOverflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   }
   Arrays.sort(arr, cmp);
   ArrayList<ICFSecuritySecDeviceObj> arrayList = new ArrayList<ICFSecuritySecDeviceObj>(len);
   for (idx = 0; idx < len; idx++) {
     arrayList.add(arr[idx]);
   }
   List<ICFSecuritySecDeviceObj> sortedList = arrayList;
   return (sortedList);
 }
  public void startElement(String uri, String localName, String qName, Attributes attrs)
      throws SAXException {
    try {
      // Common XML Attributes
      String attrId = null;
      // SecUser Attributes
      String attrLoginId = null;
      String attrEMailAddress = null;
      String attrEMailConfirmationUuid = null;
      String attrPasswordHash = null;
      String attrPasswordResetUuid = null;
      String attrDefDev = null;
      // SecUser References
      ICFSecuritySecDeviceObj refDefDev = null;
      // Attribute Extraction
      String attrLocalName;
      int numAttrs;
      int idxAttr;
      final String S_ProcName = "startElement";
      final String S_LocalName = "LocalName";

      assert qName.equals("SecUser");

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

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

      // Instantiate an edit buffer for the parsed information
      ICFSecuritySecUserEditObj editBuff =
          (ICFSecuritySecUserEditObj) schemaObj.getSecUserTableObj().newInstance().beginEdit();

      // 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("LoginId")) {
          if (attrLoginId != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrLoginId = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("EMailAddress")) {
          if (attrEMailAddress != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrEMailAddress = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("EMailConfirmationUuid")) {
          if (attrEMailConfirmationUuid != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrEMailConfirmationUuid = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("PasswordHash")) {
          if (attrPasswordHash != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrPasswordHash = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("PasswordResetUuid")) {
          if (attrPasswordResetUuid != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrPasswordResetUuid = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("DefDev")) {
          if (attrDefDev != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrDefDev = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("schemaLocation")) {
          // ignored
        } else {
          throw CFLib.getDefaultExceptionFactory()
              .newUnrecognizedAttributeException(
                  getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName);
        }
      }

      // Ensure that required attributes have values
      if (attrLoginId == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "LoginId");
      }
      if (attrEMailAddress == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "EMailAddress");
      }
      if (attrPasswordHash == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "PasswordHash");
      }

      // Save named attributes to context
      CFLibXmlCoreContext curContext = getParser().getCurContext();
      curContext.putNamedValue("Id", attrId);
      curContext.putNamedValue("LoginId", attrLoginId);
      curContext.putNamedValue("EMailAddress", attrEMailAddress);
      curContext.putNamedValue("EMailConfirmationUuid", attrEMailConfirmationUuid);
      curContext.putNamedValue("PasswordHash", attrPasswordHash);
      curContext.putNamedValue("PasswordResetUuid", attrPasswordResetUuid);
      curContext.putNamedValue("DefDev", attrDefDev);

      // Convert string attributes to native Java types
      // and apply the converted attributes to the editBuff.

      Integer natId;
      if ((attrId != null) && (attrId.length() > 0)) {
        natId = new Integer(Integer.parseInt(attrId));
      } else {
        natId = null;
      }
      String natLoginId = attrLoginId;
      editBuff.setRequiredLoginId(natLoginId);

      String natEMailAddress = attrEMailAddress;
      editBuff.setRequiredEMailAddress(natEMailAddress);

      UUID natEMailConfirmationUuid;
      if ((attrEMailConfirmationUuid == null) || (attrEMailConfirmationUuid.length() <= 0)) {
        natEMailConfirmationUuid = null;
      } else {
        natEMailConfirmationUuid = UUID.fromString(attrEMailConfirmationUuid);
      }
      editBuff.setOptionalEMailConfirmationUuid(natEMailConfirmationUuid);

      String natPasswordHash = attrPasswordHash;
      editBuff.setRequiredPasswordHash(natPasswordHash);

      UUID natPasswordResetUuid;
      if ((attrPasswordResetUuid == null) || (attrPasswordResetUuid.length() <= 0)) {
        natPasswordResetUuid = null;
      } else {
        natPasswordResetUuid = UUID.fromString(attrPasswordResetUuid);
      }
      editBuff.setOptionalPasswordResetUuid(natPasswordResetUuid);

      // Get the scope/container object

      CFLibXmlCoreContext parentContext = curContext.getPrevContext();
      Object scopeObj;
      if (parentContext != null) {
        scopeObj = parentContext.getNamedValue("Object");
      } else {
        scopeObj = null;
      }

      // Lookup refDefDev by key name value attr
      if ((attrDefDev != null) && (attrDefDev.length() > 0)) {
        refDefDev =
            (ICFSecuritySecDeviceObj)
                schemaObj
                    .getSecDeviceTableObj()
                    .readSecDeviceByIdIdx(editBuff.getOptionalDefaultDevSecUserId(), attrDefDev);
        if (refDefDev == null) {
          throw CFLib.getDefaultExceptionFactory()
              .newNullArgumentException(
                  getClass(),
                  S_ProcName,
                  0,
                  "Resolve DefDev reference named \"" + attrDefDev + "\" to table SecDevice");
        }
      } else {
        refDefDev = null;
      }
      editBuff.setOptionalLookupDefDev(refDefDev);

      CFSecuritySaxLoader.LoaderBehaviourEnum loaderBehaviour =
          saxLoader.getSecUserLoaderBehaviour();
      ICFSecuritySecUserEditObj editSecUser = null;
      ICFSecuritySecUserObj origSecUser =
          (ICFSecuritySecUserObj)
              schemaObj.getSecUserTableObj().readSecUserByULoginIdx(editBuff.getRequiredLoginId());
      if (origSecUser == null) {
        editSecUser = editBuff;
      } else {
        switch (loaderBehaviour) {
          case Insert:
            break;
          case Update:
            editSecUser = (ICFSecuritySecUserEditObj) origSecUser.beginEdit();
            editSecUser.setRequiredLoginId(editBuff.getRequiredLoginId());
            editSecUser.setRequiredEMailAddress(editBuff.getRequiredEMailAddress());
            editSecUser.setOptionalEMailConfirmationUuid(
                editBuff.getOptionalEMailConfirmationUuid());
            editSecUser.setRequiredPasswordHash(editBuff.getRequiredPasswordHash());
            editSecUser.setOptionalPasswordResetUuid(editBuff.getOptionalPasswordResetUuid());
            editSecUser.setOptionalLookupDefDev(editBuff.getOptionalLookupDefDev());
            break;
          case Replace:
            editSecUser = (ICFSecuritySecUserEditObj) origSecUser.beginEdit();
            editSecUser.delete();
            editSecUser.endEdit();
            origSecUser = null;
            editSecUser = editBuff;
            break;
        }
      }

      if (editSecUser != null) {
        if (origSecUser != null) {
          editSecUser.update();
        } else {
          origSecUser = (ICFSecuritySecUserObj) editSecUser.create();
        }
        editSecUser.endEdit();
      }

      curContext.putNamedValue("Object", origSecUser);
    } 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);
    }
  }
  public void startElement(String uri, String localName, String qName, Attributes attrs)
      throws SAXException {
    try {
      // Common XML Attributes
      String attrId = null;
      String attrRevision = null;
      // SecDevice Attributes
      String attrSecUserId = null;
      String attrDevName = null;
      String attrPubKey = null;
      String attrCreatedAt = null;
      String attrCreatedBy = null;
      String attrUpdatedAt = null;
      String attrUpdatedBy = null;
      // Attribute Extraction
      String attrLocalName;
      int numAttrs;
      int idxAttr;
      final String S_ProcName = "startElement";
      final String S_LocalName = "LocalName";

      assert qName.equals("RspnSecDeviceCreated");

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

      ICFSecuritySchemaObj schemaObj = xmsgRspnHandler.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("Revision")) {
          if (attrRevision != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrRevision = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("CreatedAt")) {
          if (attrCreatedAt != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrCreatedAt = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("CreatedBy")) {
          if (attrCreatedBy != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrCreatedBy = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("UpdatedAt")) {
          if (attrUpdatedAt != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrUpdatedAt = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("UpdatedBy")) {
          if (attrUpdatedBy != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrUpdatedBy = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("SecUserId")) {
          if (attrSecUserId != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrSecUserId = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("DevName")) {
          if (attrDevName != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrDevName = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("PubKey")) {
          if (attrPubKey != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrPubKey = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("schemaLocation")) {
          // ignored
        } else {
          throw CFLib.getDefaultExceptionFactory()
              .newUnrecognizedAttributeException(
                  getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName);
        }
      }

      // Ensure that required attributes have values
      if ((attrSecUserId == null) || (attrSecUserId.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "SecUserId");
      }
      if (attrDevName == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "DevName");
      }
      if ((attrRevision == null) || (attrRevision.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "Revision");
      }

      // Save named attributes to context
      CFLibXmlCoreContext curContext = getParser().getCurContext();

      // Convert string attributes to native Java types

      UUID natSecUserId = UUID.fromString(attrSecUserId);

      String natDevName = attrDevName;

      String natPubKey = attrPubKey;

      int natRevision = Integer.parseInt(attrRevision);
      UUID createdBy = null;
      if (attrCreatedBy != null) {
        createdBy = UUID.fromString(attrCreatedBy);
      }
      Calendar createdAt = null;
      if (attrCreatedAt != null) {
        createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt);
      }
      UUID updatedBy = null;
      if (attrUpdatedBy != null) {
        updatedBy = UUID.fromString(attrUpdatedBy);
      }
      Calendar updatedAt = null;
      if (attrUpdatedAt != null) {
        updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt);
      }
      // Instantiate a buffer for the parsed information
      ICFSecuritySecDeviceObj obj =
          (ICFSecuritySecDeviceObj) schemaObj.getSecDeviceTableObj().newInstance();
      CFSecuritySecDeviceBuff dataBuff = obj.getSecDeviceBuff();
      dataBuff.setRequiredSecUserId(natSecUserId);
      dataBuff.setRequiredDevName(natDevName);
      dataBuff.setOptionalPubKey(natPubKey);
      dataBuff.setRequiredRevision(natRevision);
      if (createdBy != null) {
        dataBuff.setCreatedByUserId(createdBy);
      }
      if (createdAt != null) {
        dataBuff.setCreatedAt(createdAt);
      }
      if (updatedBy != null) {
        dataBuff.setUpdatedByUserId(updatedBy);
      }
      if (updatedAt != null) {
        dataBuff.setUpdatedAt(updatedAt);
      }
      obj.copyBuffToPKey();
      ICFSecuritySecDeviceObj realized = (ICFSecuritySecDeviceObj) obj.realize();
      xmsgRspnHandler.setLastObjectProcessed(realized);
    } 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);
    }
  }