public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try { // Common XML Attributes String attrId = null; // Primary Key Attributes for Constant Enum support // ISOLanguage Attributes String attrISOCode = null; String attrBaseLanguageCode = null; String attrISOCountryId = null; // ISOLanguage References // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("ISOLanguage"); CFDbTestSaxLoader saxLoader = (CFDbTestSaxLoader) getParser(); if (saxLoader == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFDbTestSchemaObj schemaObj = saxLoader.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Instantiate an edit buffer for the parsed information ICFDbTestISOLanguageEditObj editBuff = (ICFDbTestISOLanguageEditObj) schemaObj.getISOLanguageTableObj().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("ISOCode")) { if (attrISOCode != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrISOCode = attrs.getValue(idxAttr); } else if (attrLocalName.equals("BaseLanguageCode")) { if (attrBaseLanguageCode != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrBaseLanguageCode = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ISOCountryId")) { if (attrISOCountryId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrISOCountryId = 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 (attrISOCode == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "ISOCode"); } if (attrBaseLanguageCode == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "BaseLanguageCode"); } // Save named attributes to context CFLibXmlCoreContext curContext = getParser().getCurContext(); curContext.putNamedValue("Id", attrId); curContext.putNamedValue("ISOCode", attrISOCode); curContext.putNamedValue("BaseLanguageCode", attrBaseLanguageCode); curContext.putNamedValue("ISOCountryId", attrISOCountryId); // Convert string attributes to native Java types // and apply the converted attributes to the editBuff. short natId; natId = Short.parseShort(attrId); editBuff.getPKey().setRequiredId(natId); editBuff.getISOLanguageBuff().setRequiredId(natId); String natISOCode = attrISOCode; editBuff.setRequiredISOCode(natISOCode); String natBaseLanguageCode = attrBaseLanguageCode; editBuff.setRequiredBaseLanguageCode(natBaseLanguageCode); Short natISOCountryId; if ((attrISOCountryId == null) || (attrISOCountryId.length() <= 0)) { natISOCountryId = null; } else { natISOCountryId = new Short(Short.parseShort(attrISOCountryId)); } editBuff.setOptionalISOCountryId(natISOCountryId); // Get the scope/container object CFLibXmlCoreContext parentContext = curContext.getPrevContext(); Object scopeObj; if (parentContext != null) { scopeObj = parentContext.getNamedValue("Object"); } else { scopeObj = null; } CFDbTestSaxLoader.LoaderBehaviourEnum loaderBehaviour = saxLoader.getISOLanguageLoaderBehaviour(); ICFDbTestISOLanguageEditObj editISOLanguage = null; ICFDbTestISOLanguageObj origISOLanguage = (ICFDbTestISOLanguageObj) schemaObj .getISOLanguageTableObj() .readISOLanguageByCodeIdx(editBuff.getRequiredISOCode()); editBuff.getPKey().setRequiredId(natId); editBuff.getISOLanguageBuff().setRequiredId(natId); if (origISOLanguage == null) { editISOLanguage = editBuff; } else { switch (loaderBehaviour) { case Insert: break; case Update: editISOLanguage = (ICFDbTestISOLanguageEditObj) origISOLanguage.beginEdit(); editISOLanguage.setRequiredISOCode(editBuff.getRequiredISOCode()); editISOLanguage.setRequiredBaseLanguageCode(editBuff.getRequiredBaseLanguageCode()); editISOLanguage.setOptionalISOCountryId(editBuff.getOptionalISOCountryId()); break; case Replace: editISOLanguage = (ICFDbTestISOLanguageEditObj) origISOLanguage.beginEdit(); editISOLanguage.delete(); editISOLanguage.endEdit(); origISOLanguage = null; editISOLanguage = editBuff; break; } } if (editISOLanguage != null) { if (origISOLanguage != null) { editISOLanguage.update(); } else { origISOLanguage = (ICFDbTestISOLanguageObj) editISOLanguage.create(); } editISOLanguage.endEdit(); } curContext.putNamedValue("Object", origISOLanguage); } 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; // Primary Key Attributes for Constant Enum support String attrISOCountryId = null; String attrISOLanguageId = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RqstISOCountryLanguageLock"); 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 CFSecurityISOCountryLanguagePKey pkey = ((ICFDbTestSchema) schemaObj.getBackingStore()).getFactoryISOCountryLanguage().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("ISOCountryId")) { if (attrISOCountryId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrISOCountryId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ISOLanguageId")) { if (attrISOLanguageId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrISOLanguageId = 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 ((attrISOCountryId == null) || (attrISOCountryId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "ISOCountryId"); } if ((attrISOLanguageId == null) || (attrISOLanguageId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "ISOLanguageId"); } // Get current context CFLibXmlCoreContext curContext = getParser().getCurContext(); // Convert string attributes to native Java types // and apply the converted attributes to the editBuff. short natISOCountryId; natISOCountryId = Short.parseShort(attrISOCountryId); pkey.setRequiredISOCountryId(natISOCountryId); pkey.setRequiredISOCountryId(natISOCountryId); short natISOLanguageId; natISOLanguageId = Short.parseShort(attrISOLanguageId); pkey.setRequiredISOLanguageId(natISOLanguageId); pkey.setRequiredISOLanguageId(natISOLanguageId); // Lock the object ICFDbTestISOCountryLanguageObj locked = ((ICFDbTestISOCountryLanguageObj) schemaObj.getISOCountryLanguageTableObj().lockISOCountryLanguage(pkey)); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFDbTestXMsgISOCountryLanguageMessageFormatter.formatISOCountryLanguageRspnLocked( "\n\t\t\t", locked.getISOCountryLanguageBuff()) + "\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); } }