net.sourceforge.msscodefactory.cffreeswitch.v2_0.CFFswXMsgRspnHandler.CFFswXMsgRspnPbxIvrMenuEntryRecHandler.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cffreeswitch.v2_0.CFFswXMsgRspnHandler.CFFswXMsgRspnPbxIvrMenuEntryRecHandler.java

Source

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

/*
 *   CF FreeSwitch Configuration Model
 *
 *   Copyright (c) 2013-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.cffreeswitch.v2_0.CFFswXMsgRspnHandler;

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.cffreeswitch.v2_0.CFFsw.*;
import net.sourceforge.msscodefactory.cffreeswitch.v2_0.CFFswObj.*;

/*
 *   CFFswXMsgRspnPbxIvrMenuEntryRecHandler XML SAX Element Handler implementation
 *   for PbxIvrMenuEntry.
 */
public class CFFswXMsgRspnPbxIvrMenuEntryRecHandler extends CFLibXmlCoreElementHandler {
    public CFFswXMsgRspnPbxIvrMenuEntryRecHandler(CFFswXMsgRspnHandler 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;
            // PbxIvrMenuEntry Attributes
            String attrTenantId = null;
            String attrMenuEntryId = null;
            String attrMenuId = null;
            String attrDigits = null;
            String attrEntryType = null;
            String attrParam = null;
            // Attribute Extraction
            String attrLocalName;
            int numAttrs;
            int idxAttr;
            final String S_ProcName = "startElement";
            final String S_LocalName = "LocalName";

            assert qName.equals("PbxIvrMenuEntry");

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

            ICFFswSchemaObj 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("TenantId")) {
                    if (attrTenantId != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrTenantId = attrs.getValue(idxAttr);
                } else if (attrLocalName.equals("MenuEntryId")) {
                    if (attrMenuEntryId != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrMenuEntryId = attrs.getValue(idxAttr);
                } else if (attrLocalName.equals("MenuId")) {
                    if (attrMenuId != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrMenuId = attrs.getValue(idxAttr);
                } else if (attrLocalName.equals("Digits")) {
                    if (attrDigits != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrDigits = attrs.getValue(idxAttr);
                } else if (attrLocalName.equals("EntryType")) {
                    if (attrEntryType != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrEntryType = attrs.getValue(idxAttr);
                } else if (attrLocalName.equals("Param")) {
                    if (attrParam != null) {
                        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                                S_ProcName, S_LocalName, attrLocalName);
                    }
                    attrParam = 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 ((attrMenuEntryId == null) || (attrMenuEntryId.length() <= 0)) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "MenuEntryId");
            }
            if ((attrMenuId == null) || (attrMenuId.length() <= 0)) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "MenuId");
            }
            if (attrDigits == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "Digits");
            }
            if (attrEntryType == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "EntryType");
            }
            if (attrParam == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "Param");
            }

            // Save named attributes to context
            CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext();

            // Convert string attributes to native Java types

            long natTenantId = Long.parseLong(attrTenantId);

            long natMenuEntryId = Long.parseLong(attrMenuEntryId);

            long natMenuId = Long.parseLong(attrMenuId);

            String natDigits = attrDigits;

            String natEntryType = attrEntryType;

            String natParam = attrParam;

            int natRevision = Integer.parseInt(attrRevision);
            // Get the parent context
            CFLibXmlCoreContext parentContext = curContext.getPrevContext();
            // Instantiate a buffer for the parsed information
            ICFFswPbxIvrMenuEntryObj obj = schemaObj.getPbxIvrMenuEntryTableObj().newInstance();
            CFFswPbxIvrMenuEntryBuff dataBuff = obj.getPbxIvrMenuEntryBuff();
            dataBuff.setRequiredTenantId(natTenantId);
            dataBuff.setRequiredMenuEntryId(natMenuEntryId);
            dataBuff.setRequiredMenuId(natMenuId);
            dataBuff.setRequiredDigits(natDigits);
            dataBuff.setRequiredEntryType(natEntryType);
            dataBuff.setRequiredParam(natParam);
            dataBuff.setRequiredRevision(natRevision);
            obj.copyBuffToPKey();
            SortedMap<CFFswPbxIvrMenuEntryPKey, ICFFswPbxIvrMenuEntryObj> sortedMap = (SortedMap<CFFswPbxIvrMenuEntryPKey, ICFFswPbxIvrMenuEntryObj>) xmsgRspnHandler
                    .getSortedMapOfObjects();
            ICFFswPbxIvrMenuEntryObj realized = (ICFFswPbxIvrMenuEntryObj) obj.realize();
            xmsgRspnHandler.setLastObjectProcessed(realized);
            if (sortedMap != null) {
                sortedMap.put(realized.getPKey(), 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 {
    }
}