public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try { // Common XML Attributes String attrId = null; String attrRevision = null; // Cluster Attributes String attrFullDomainName = null; String attrDescription = 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("Cluster"); CFDbTestXMsgRspnHandler xmsgRspnHandler = (CFDbTestXMsgRspnHandler) getParser(); if (xmsgRspnHandler == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFDbTestSchemaObj 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("FullDomainName")) { if (attrFullDomainName != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrFullDomainName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Description")) { if (attrDescription != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDescription = 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 ((attrId == null) || (attrId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "Id"); } if (attrFullDomainName == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "FullDomainName"); } if (attrDescription == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "Description"); } // Save named attributes to context CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext(); // Convert string attributes to native Java types long natId = Long.parseLong(attrId); String natFullDomainName = attrFullDomainName; String natDescription = attrDescription; 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); } // Get the parent context CFLibXmlCoreContext parentContext = curContext.getPrevContext(); // Instantiate a buffer for the parsed information ICFDbTestClusterObj obj = (ICFDbTestClusterObj) (schemaObj.getClusterTableObj().newInstance()); CFSecurityClusterBuff dataBuff = obj.getClusterBuff(); dataBuff.setRequiredId(natId); dataBuff.setRequiredFullDomainName(natFullDomainName); dataBuff.setRequiredDescription(natDescription); 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(); @SuppressWarnings("unchecked") List<ICFSecurityClusterObj> list = (List<ICFSecurityClusterObj>) xmsgRspnHandler.getListOfObjects(); ICFSecurityClusterObj realized = (ICFSecurityClusterObj) obj.realize(); xmsgRspnHandler.setLastObjectProcessed(realized); if (list != null) { list.add(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); } }
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { CFDbTestXMsgSchemaMessageFormatter schemaFormatter = null; try { // Common XML Attributes String attrId = null; String attrRevision = null; // Primary Key Attributes for Constant Enum support // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RqstClusterDelete"); CFDbTestXMsgRqstHandler xmsgRqstHandler = (CFDbTestXMsgRqstHandler) getParser(); if (xmsgRqstHandler == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter(); ICFDbTestSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Instantiate a PKey buffer for the parsed information CFSecurityClusterPKey pkey = ((ICFDbTestSchema) schemaObj.getBackingStore()).getFactoryCluster().newPKey(); // 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("schemaLocation")) { // ignored } else { throw CFLib.getDefaultExceptionFactory() .newUnrecognizedAttributeException( getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName); } } // Ensure that required attributes have values 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"); } // Get current context CFLibXmlCoreContext curContext = getParser().getCurContext(); // Convert string attributes to native Java types // and apply the converted attributes to the editBuff. long natId; natId = Long.parseLong(attrId); pkey.setRequiredId(natId); pkey.setRequiredId(natId); int natRevision = Integer.parseInt(attrRevision); // Delete the object ICFDbTestClusterObj read = ((ICFDbTestClusterObj) schemaObj.getClusterTableObj().readCluster(pkey)); if (read != null) { if (read.getClusterBuff().getRequiredRevision() > natRevision) { throw CFLib.getDefaultExceptionFactory() .newCollisionDetectedException( getClass(), S_ProcName, "Collision detected preparing to delete Cluster"); } else { ICFDbTestClusterEditObj editBuff = (ICFDbTestClusterEditObj) read.beginEdit(); if (editBuff != null) { editBuff.delete(); editBuff.endEdit(); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFDbTestXMsgClusterMessageFormatter.formatClusterRspnDeleted() + "\n" + schemaFormatter.formatRspnXmlPostamble(); ((CFDbTestXMsgRqstHandler) getParser()).appendResponse(response); } else { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "read.beginEdit()"); } } } else { String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFDbTestXMsgSchemaMessageFormatter.formatRspnNoDataFound() + "\n" + schemaFormatter.formatRspnXmlPostamble(); ((CFDbTestXMsgRqstHandler) getParser()).appendResponse(response); } } catch (RuntimeException e) { CFDbTestXMsgRqstHandler xmsgRqstHandler = ((CFDbTestXMsgRqstHandler) getParser()); schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter(); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFDbTestXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + schemaFormatter.formatRspnXmlPostamble(); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } catch (Error e) { CFDbTestXMsgRqstHandler xmsgRqstHandler = ((CFDbTestXMsgRqstHandler) getParser()); schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter(); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFDbTestXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + schemaFormatter.formatRspnXmlPostamble(); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } }