public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { CFBamXMsgSchemaMessageFormatter schemaFormatter = null; try { // Common XML Attributes String attrId = null; String attrRevision = null; // Scope Attributes String attrTenantId = null; String attrCreatedAt = null; String attrCreatedBy = null; String attrUpdatedAt = null; String attrUpdatedBy = null; // ClearDep Attributes String attrRelationId = null; // ClearSubDep3 Attributes String attrContClearDep2TenantId = null; String attrContClearDep2Id = null; String attrName = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RqstClearSubDep3Update"); CFBamXMsgRqstHandler xmsgRqstHandler = (CFBamXMsgRqstHandler) getParser(); if (xmsgRqstHandler == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter(); ICFBamSchemaObj schemaObj = xmsgRqstHandler.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("TenantId")) { if (attrTenantId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTenantId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("RelationId")) { if (attrRelationId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRelationId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ContClearDep2TenantId")) { if (attrContClearDep2TenantId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrContClearDep2TenantId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ContClearDep2Id")) { if (attrContClearDep2Id != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrContClearDep2Id = 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("schemaLocation")) { // ignored } else { throw CFLib.getDefaultExceptionFactory() .newUnrecognizedAttributeException( getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName); } } // Ensure that required attributes have values if ((attrTenantId == null) || (attrTenantId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "TenantId"); } if ((attrId == null) || (attrId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "Id"); } if ((attrRevision == null) || (attrRevision.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "Revision"); } if ((attrCreatedAt == null) || (attrCreatedAt.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "CreatedAt"); } if ((attrCreatedBy == null) || (attrCreatedBy.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "CreatedBy"); } if ((attrUpdatedAt == null) || (attrUpdatedAt.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "UpdatedAt"); } if ((attrUpdatedBy == null) || (attrUpdatedBy.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "UpdatedBy"); } if ((attrRelationId == null) || (attrRelationId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "RelationId"); } if ((attrContClearDep2TenantId == null) || (attrContClearDep2TenantId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "ContClearDep2TenantId"); } if ((attrContClearDep2Id == null) || (attrContClearDep2Id.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "ContClearDep2Id"); } if (attrName == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "Name"); } // Save named attributes to context CFLibXmlCoreContext curContext = getParser().getCurContext(); // Instantiate a PKey buffer for the parsed information CFBamScopePKey pkey = ((ICFBamSchema) schemaObj.getBackingStore()).getFactoryScope().newPKey(); long natTenantId; natTenantId = Long.parseLong(attrTenantId); pkey.setRequiredTenantId(natTenantId); long natId; natId = Long.parseLong(attrId); pkey.setRequiredId(natId); // Read the instance ICFBamClearSubDep3Obj origBuff = ((ICFBamClearSubDep3Obj) schemaObj.getClearSubDep3TableObj().readClearSubDep3(pkey)); if (origBuff == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException( getClass(), S_ProcName, 0, "getClearSubDep3TableObj().readClearSubDep3()"); } else { // Edit the instance ICFBamClearSubDep3EditObj editBuff = (ICFBamClearSubDep3EditObj) origBuff.beginEdit(); CFBamClearSubDep3Buff dataBuff = editBuff.getClearSubDep3Buff(); // Convert string attributes to native Java types // and apply the converted attributes to the editBuff. int natRevision = Integer.parseInt(attrRevision); dataBuff.setRequiredRevision(natRevision); 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); } if (createdBy != null) { dataBuff.setCreatedByUserId(createdBy); } if (createdAt != null) { dataBuff.setCreatedAt(createdAt); } if (updatedBy != null) { dataBuff.setUpdatedByUserId(updatedBy); } if (updatedAt != null) { dataBuff.setUpdatedAt(updatedAt); } long natRelationId = Long.parseLong(attrRelationId); dataBuff.setRequiredRelationId(natRelationId); long natContClearDep2TenantId = Long.parseLong(attrContClearDep2TenantId); dataBuff.setRequiredContClearDep2TenantId(natContClearDep2TenantId); long natContClearDep2Id = Long.parseLong(attrContClearDep2Id); dataBuff.setRequiredContClearDep2Id(natContClearDep2Id); String natName = attrName; dataBuff.setRequiredName(natName); // Attempt the update editBuff.update(); editBuff.endEdit(); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFBamXMsgClearSubDep3MessageFormatter.formatClearSubDep3RspnUpdated( "\n\t\t\t", origBuff.getClearSubDep3Buff()) + "\n" + schemaFormatter.formatRspnXmlPostamble(); ((CFBamXMsgRqstHandler) getParser()).appendResponse(response); } } catch (RuntimeException e) { CFBamXMsgRqstHandler xmsgRqstHandler = ((CFBamXMsgRqstHandler) getParser()); schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter(); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFBamXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + schemaFormatter.formatRspnXmlPostamble(); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } catch (Error e) { CFBamXMsgRqstHandler xmsgRqstHandler = ((CFBamXMsgRqstHandler) getParser()); schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter(); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFBamXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + schemaFormatter.formatRspnXmlPostamble(); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } }
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); } }