net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRqstHandler.CFAccXMsgRqstTSecGroupReadByTenantIdxHandler.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRqstHandler.CFAccXMsgRqstTSecGroupReadByTenantIdxHandler.java

Source

// Description: Java 7 XML Message SAX Response Delete By Index Element Handler for TSecGroup

/*
 *   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.CFAccXMsgRqstHandler;

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

/*
 *   CFAccXMsgRqstTSecGroupReadByHandler XML SAX Element Handler implementation
 *   for TSecGroup.
 */
public class CFAccXMsgRqstTSecGroupReadByTenantIdxHandler extends CFLibXmlCoreElementHandler {
    public CFAccXMsgRqstTSecGroupReadByTenantIdxHandler(CFAccXMsgRqstHandler xmsgRqstHandler) {
        super(xmsgRqstHandler);
    }

    public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
        try {
            // Common XML Attributes
            String attrId = null;
            String attrTenantId = null;
            // Attribute Extraction
            String attrLocalName;
            int numAttrs;
            int idxAttr;
            final String S_ProcName = "startElement";
            final String S_LocalName = "LocalName";

            assert qName.equals("RqstTSecGroupReadByTenantIdx");

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

            ICFAccSchemaObj 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("TenantId")) {
                    if (attrTenantId != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrTenantId = 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$implRqstTableReadByHandlerCheckReqKeyAttrs$

            // Save named attributes to context
            CFLibXmlCoreContext curContext = getParser().getCurContext();
            // Convert string attributes to native Java types
            // and apply the converted attributes to the editBuff.

            long natTenantId;
            natTenantId = Long.parseLong(attrTenantId);

            // Read the objects
            SortedMap<CFAccTSecGroupPKey, ICFAccTSecGroupObj> map = schemaObj.getTSecGroupTableObj()
                    .readTSecGroupByTenantIdx(natTenantId);
            String responseOpening = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                    + CFAccXMsgTSecGroupMessageFormatter.formatTSecGroupRspnListOpenTag();
            xmsgRqstHandler.appendResponse(responseOpening);
            Iterator<ICFAccTSecGroupObj> iter = map.values().iterator();
            ICFAccTSecGroupObj cur;
            String subxml;
            while (iter.hasNext()) {
                cur = iter.next();
                subxml = CFAccXMsgTSecGroupMessageFormatter.formatTSecGroupRspnDerivedRec("\n\t\t",
                        cur.getTSecGroupBuff());
                xmsgRqstHandler.appendResponse(subxml);
            }
            String responseClosing = "\n" + "\t"
                    + CFAccXMsgTSecGroupMessageFormatter.formatTSecGroupRspnListCloseTag()
                    + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
            xmsgRqstHandler.appendResponse(responseClosing);
        } catch (RuntimeException e) {
            String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                    + CFAccXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                    + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
            CFAccXMsgRqstHandler xmsgRqstHandler = ((CFAccXMsgRqstHandler) getParser());
            xmsgRqstHandler.resetResponse();
            xmsgRqstHandler.appendResponse(response);
            xmsgRqstHandler.setCaughtException(true);
        } catch (Error e) {
            String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                    + CFAccXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                    + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
            CFAccXMsgRqstHandler xmsgRqstHandler = ((CFAccXMsgRqstHandler) getParser());
            xmsgRqstHandler.resetResponse();
            xmsgRqstHandler.appendResponse(response);
            xmsgRqstHandler.setCaughtException(true);
        }
    }

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