net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgRqstHandler.CFAsteriskXMsgRqstISOCountryLanguageReadByCountryIdxHandler.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgRqstHandler.CFAsteriskXMsgRqstISOCountryLanguageReadByCountryIdxHandler.java

Source

// Description: Java 8 XML Message SAX Response Delete By Index Element Handler for ISOCountryLanguage

/*
 *   Code Factory Asterisk 11 Configuration Model
 *
 *   Copyright (c) 2014-2015 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.
 *   
 */

package net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgRqstHandler;

import java.math.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import org.apache.commons.codec.binary.Base64;
import org.xml.sax.*;
import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurity.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternet.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsterisk.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurityObj.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternetObj.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsg.*;

/*
 *   CFAsteriskXMsgRqstISOCountryLanguageReadByHandler XML SAX Element Handler implementation
 *   for ISOCountryLanguage.
 */
public class CFAsteriskXMsgRqstISOCountryLanguageReadByCountryIdxHandler extends CFLibXmlCoreElementHandler {
    public CFAsteriskXMsgRqstISOCountryLanguageReadByCountryIdxHandler(CFAsteriskXMsgRqstHandler xmsgRqstHandler) {
        super(xmsgRqstHandler);
    }

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

            assert qName.equals("RqstISOCountryLanguageReadByCountryIdx");

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

            schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

            ICFAsteriskSchemaObj 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("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 ((attrISOCountryId == null) || (attrISOCountryId.length() <= 0)) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "ISOCountryId");
            }

            // Save named attributes to 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);

            // Read the objects
            List<ICFSecurityISOCountryLanguageObj> list = schemaObj.getISOCountryLanguageTableObj()
                    .readISOCountryLanguageByCountryIdx(natISOCountryId);
            String responseOpening = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                    + CFAsteriskXMsgISOCountryLanguageMessageFormatter.formatISOCountryLanguageRspnListOpenTag();
            xmsgRqstHandler.appendResponse(responseOpening);
            Iterator<ICFSecurityISOCountryLanguageObj> iter = list.iterator();
            ICFSecurityISOCountryLanguageObj cur;
            String subxml;
            while (iter.hasNext()) {
                cur = iter.next();
                subxml = CFAsteriskXMsgISOCountryLanguageMessageFormatter
                        .formatISOCountryLanguageRspnDerivedRec("\n\t\t", cur.getISOCountryLanguageBuff());
                xmsgRqstHandler.appendResponse(subxml);
            }
            String responseClosing = "\n" + "\t"
                    + CFAsteriskXMsgISOCountryLanguageMessageFormatter.formatISOCountryLanguageRspnListCloseTag()
                    + schemaFormatter.formatRspnXmlPostamble();
            xmsgRqstHandler.appendResponse(responseClosing);
        } catch (RuntimeException e) {
            CFAsteriskXMsgRqstHandler xmsgRqstHandler = ((CFAsteriskXMsgRqstHandler) getParser());
            schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
            String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                    + CFAsteriskXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                    + schemaFormatter.formatRspnXmlPostamble();
            xmsgRqstHandler.resetResponse();
            xmsgRqstHandler.appendResponse(response);
            xmsgRqstHandler.setCaughtException(true);
        } catch (Error e) {
            CFAsteriskXMsgRqstHandler xmsgRqstHandler = ((CFAsteriskXMsgRqstHandler) getParser());
            schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
            String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                    + CFAsteriskXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                    + schemaFormatter.formatRspnXmlPostamble();
            xmsgRqstHandler.resetResponse();
            xmsgRqstHandler.appendResponse(response);
            xmsgRqstHandler.setCaughtException(true);
        }
    }

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