Java tutorial
// Description: Java 7 XML SAX Element Handler for AuditAction /* * CF Customer Information Managerment template model * * Copyright (c) 2010-2014 Mark Sobkow * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * *********************************************************************** * * Code manufactured by MSS Code Factory */ package net.sourceforge.msscodefactory.cfinternet.v2_0.CFInternetSaxLoader; import java.math.*; import java.sql.*; import java.text.*; import java.util.*; import net.sourceforge.msscodefactory.cflib.v1_11.CFLib.*; import org.apache.commons.codec.binary.Base64; import org.xml.sax.*; import net.sourceforge.msscodefactory.cfinternet.v2_0.CFInternet.*; import net.sourceforge.msscodefactory.cfinternet.v2_0.CFInternetObj.*; /* * CFInternetSaxLoaderAuditActionParse XML SAX Element Handler implementation * for AuditAction. */ public class CFInternetSaxLoaderAuditActionHandler extends CFLibXmlCoreElementHandler { public CFInternetSaxLoaderAuditActionHandler(CFInternetSaxLoader saxLoader) { super(saxLoader); } 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 String attrAuditActionId = null; // AuditAction Attributes String attrDescription = null; // AuditAction References // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("AuditAction"); CFInternetSaxLoader saxLoader = (CFInternetSaxLoader) getParser(); if (saxLoader == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFInternetSchemaObj schemaObj = saxLoader.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Instantiate an edit buffer for the parsed information ICFInternetAuditActionEditObj editBuff = (ICFInternetAuditActionEditObj) schemaObj .getAuditActionTableObj().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("AuditActionId")) { if (attrAuditActionId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrAuditActionId = 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 ((attrAuditActionId == null) || (attrAuditActionId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "AuditActionId"); } if (attrDescription == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Description"); } // Save named attributes to context CFLibXmlCoreContext curContext = getParser().getCurContext(); curContext.putNamedValue("Id", attrId); curContext.putNamedValue("Description", attrDescription); // Convert string attributes to native Java types // and apply the converted attributes to the editBuff. short natAuditActionId; natAuditActionId = Short.parseShort(attrAuditActionId); editBuff.getPKey().setRequiredAuditActionId(natAuditActionId); editBuff.getAuditActionBuff().setRequiredAuditActionId(natAuditActionId); String natDescription = attrDescription; editBuff.setRequiredDescription(natDescription); // Get the scope/container object CFLibXmlCoreContext parentContext = curContext.getPrevContext(); Object scopeObj; if (parentContext != null) { scopeObj = parentContext.getNamedValue("Object"); } else { scopeObj = null; } CFInternetSaxLoader.LoaderBehaviourEnum loaderBehaviour = saxLoader.getAuditActionLoaderBehaviour(); ICFInternetAuditActionEditObj editAuditAction = null; ICFInternetAuditActionObj origAuditAction = schemaObj.getAuditActionTableObj() .readAuditActionByUDescrIdx(editBuff.getRequiredDescription()); editBuff.getPKey().setRequiredAuditActionId(natAuditActionId); editBuff.getAuditActionBuff().setRequiredAuditActionId(natAuditActionId); if (origAuditAction == null) { editAuditAction = editBuff; } else { switch (loaderBehaviour) { case Insert: break; case Update: editAuditAction = (ICFInternetAuditActionEditObj) origAuditAction.beginEdit(); editAuditAction.setRequiredDescription(editBuff.getRequiredDescription()); break; case Replace: editAuditAction = (ICFInternetAuditActionEditObj) origAuditAction.beginEdit(); editAuditAction.delete(); editAuditAction.endEdit(); origAuditAction = null; editAuditAction = editBuff; break; } } if (editAuditAction != null) { if (origAuditAction != null) { editAuditAction.update(); } else { origAuditAction = (ICFInternetAuditActionObj) editAuditAction.create(); } editAuditAction.endEdit(); } curContext.putNamedValue("Object", origAuditAction); } 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 endElement(String uri, String localName, String qName) throws SAXException { } }