net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRspnHandler.CFAccXMsgRspnAddressLockedHandler.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRspnHandler.CFAccXMsgRspnAddressLockedHandler.java

Source

// Description: Java 7 XML Message SAX Response Record Element Handler for Address

/*
 *   MSS Code Factory Accounting Business Application Model
 *
 *   Copyright (c) 2014 Mark Sobkow
 *   
 *   This program is available as free software under the GNU GPL v3, or
 *   under a commercial license from Mark Sobkow.  For commercial licensing
 *   details, please contact msobkow@sasktel.net.
 *   
 *   Under the terms of the GPL:
 *   
 *      This program is free software: you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation, either version 3 of the License, or
 *      (at your option) any later version.
 *     
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *     
 *      You should have received a copy of the GNU General Public License
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *   
 *      This source code incorporates modified modules originally licensed
 *      under the Apache 2.0 license by MSS Code Factory including CFSecurity
 *      (net-sourceforge-msscodefactory-2.0-cfsecurity.xml),
 *      CFInternet (net-sourceforge-msscodefactory-2.0-cfinternet.xml), and
 *      CFCrm 2.0 (net-sourceforge-msscodefactory-2.0-cfcrm.xml), with all of the
 *      required models being available as part of the MSS Code Factory 1.11
 *      distribution source and install zips.
 *   
 *      You can download installations of MSS Code Factory 1.11 from
 *      http://msscodefactory.sourceforge.net/
 *   
 * ***********************************************************************
 *
 *   Code manufactured by MSS Code Factory
 */

package net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRspnHandler;

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.cfacc.v2_0.CFAcc.*;
import net.sourceforge.msscodefactory.cfacc.v2_0.CFAccObj.*;

/*
 *   CFAccXMsgRspnAddressLockedHandler XML SAX Element Handler implementation
 *   for Address.
 */
public class CFAccXMsgRspnAddressLockedHandler extends CFLibXmlCoreElementHandler {
    public CFAccXMsgRspnAddressLockedHandler(CFAccXMsgRspnHandler xmsgRspnHandler) {
        super(xmsgRspnHandler);
    }

    public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
        try {
            // Common XML Attributes
            String attrId = null;
            String attrRevision = null;
            // Address Attributes
            String attrTenantId = null;
            String attrAddressId = null;
            String attrContactId = null;
            String attrDescription = null;
            String attrAddrLine1 = null;
            String attrAddrLine2 = null;
            String attrCity = null;
            String attrState = null;
            String attrCountryId = null;
            String attrZip = 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("RspnAddressLocked");

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

            ICFAccSchemaObj 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("TenantId")) {
                    if (attrTenantId != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrTenantId = attrs.getValue(idxAttr);
                } else if (attrLocalName.equals("AddressId")) {
                    if (attrAddressId != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrAddressId = attrs.getValue(idxAttr);
                } else if (attrLocalName.equals("ContactId")) {
                    if (attrContactId != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrContactId = 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("AddrLine1")) {
                    if (attrAddrLine1 != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrAddrLine1 = attrs.getValue(idxAttr);
                } else if (attrLocalName.equals("AddrLine2")) {
                    if (attrAddrLine2 != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrAddrLine2 = attrs.getValue(idxAttr);
                } else if (attrLocalName.equals("City")) {
                    if (attrCity != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrCity = attrs.getValue(idxAttr);
                } else if (attrLocalName.equals("State")) {
                    if (attrState != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrState = attrs.getValue(idxAttr);
                } else if (attrLocalName.equals("CountryId")) {
                    if (attrCountryId != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrCountryId = attrs.getValue(idxAttr);
                } else if (attrLocalName.equals("Zip")) {
                    if (attrZip != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrZip = 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 ((attrAddressId == null) || (attrAddressId.length() <= 0)) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "AddressId");
            }
            if ((attrContactId == null) || (attrContactId.length() <= 0)) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "ContactId");
            }
            if (attrDescription == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "Description");
            }
            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

            long natTenantId = Long.parseLong(attrTenantId);

            long natAddressId = Long.parseLong(attrAddressId);

            long natContactId = Long.parseLong(attrContactId);

            String natDescription = attrDescription;

            String natAddrLine1 = attrAddrLine1;

            String natAddrLine2 = attrAddrLine2;

            String natCity = attrCity;

            String natState = attrState;

            Short natCountryId;
            if ((attrCountryId == null) || (attrCountryId.length() <= 0)) {
                natCountryId = null;
            } else {
                natCountryId = new Short(Short.parseShort(attrCountryId));
            }

            String natZip = attrZip;

            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
            ICFAccAddressObj obj = schemaObj.getAddressTableObj().newInstance();
            CFAccAddressBuff dataBuff = obj.getAddressBuff();
            dataBuff.setRequiredTenantId(natTenantId);
            dataBuff.setRequiredAddressId(natAddressId);
            dataBuff.setRequiredContactId(natContactId);
            dataBuff.setRequiredDescription(natDescription);
            dataBuff.setOptionalAddrLine1(natAddrLine1);
            dataBuff.setOptionalAddrLine2(natAddrLine2);
            dataBuff.setOptionalCity(natCity);
            dataBuff.setOptionalState(natState);
            dataBuff.setOptionalCountryId(natCountryId);
            dataBuff.setOptionalZip(natZip);
            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();
            ICFAccAddressObj realized = (ICFAccAddressObj) 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);
        }
    }

    public void endElement(String uri, String localName, String qName) throws SAXException {
    }
}