Java tutorial
// Description: Java 7 XMsg Client DbIO implementation for Tld. /* * CF Asterisk 11 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.cfasterisk.v2_0.CFAstXMsgClient; 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 net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAst.*; import net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstObj.*; import net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsg.*; import net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgRspnHandler.*; /* * CFAstXMsgClientTldTable XMsg Client DbIO implementation * for Tld. */ public class CFAstXMsgClientTldTable implements ICFAstTldTable { private CFAstXMsgClientSchema schema; public CFAstXMsgClientTldTable(CFAstXMsgClientSchema argSchema) { schema = argSchema; } public void createTld(CFAstAuthorization Authorization, CFAstTldBuff Buff) { final String S_ProcName = "createTld"; String rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgTldMessageFormatter.formatTldRqstCreate("\n\t\t\t", Buff) + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); String rspn = schema.sendReceive(Authorization, rqst); if ((rspn == null) || (rspn.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "rspn"); } CFAstXMsgRspnHandler responseHandler = schema.getResponseHandler(); responseHandler.parseStringContents(rspn); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } Object lastObjectProcessed = responseHandler.getLastObjectProcessed(); if (lastObjectProcessed != null) { ICFAstTldObj realized = null; if (lastObjectProcessed instanceof ICFAstTldObj) { realized = (ICFAstTldObj) lastObjectProcessed; } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "lastObjectProcessed", lastObjectProcessed, "ICFAstTldObj"); } if (realized != null) { Buff.set(realized.getTldBuff()); } } else { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "responseHandler.getLastObjectProcessed()"); } } public CFAstTldBuff readDerived(CFAstAuthorization Authorization, CFAstTldPKey PKey) { final String S_ProcName = "readDerived"; String rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgTldMessageFormatter.formatTldRqstRead("\n\t\t\t", PKey) + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); String rspn = schema.sendReceive(Authorization, rqst); if ((rspn == null) || (rspn.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "rspn"); } CFAstXMsgRspnHandler responseHandler = schema.getResponseHandler(); responseHandler.parseStringContents(rspn); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } CFAstTldBuff buff = null; Object lastObjectProcessed = responseHandler.getLastObjectProcessed(); if (lastObjectProcessed != null) { ICFAstTldObj realized = null; if (lastObjectProcessed instanceof ICFAstTldObj) { realized = (ICFAstTldObj) lastObjectProcessed; } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "lastObjectProcessed", lastObjectProcessed, "ICFAstTldObj"); } if (realized != null) { buff = realized.getTldBuff(); } } return (buff); } public CFAstTldBuff lockDerived(CFAstAuthorization Authorization, CFAstTldPKey PKey) { final String S_ProcName = "lockDerived"; String rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgTldMessageFormatter.formatTldRqstLock("\n\t\t\t", PKey) + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); String rspn = schema.sendReceive(Authorization, rqst); if ((rspn == null) || (rspn.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "rspn"); } CFAstXMsgRspnHandler responseHandler = schema.getResponseHandler(); responseHandler.parseStringContents(rspn); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } CFAstTldBuff buff = null; Object lastObjectProcessed = responseHandler.getLastObjectProcessed(); if (lastObjectProcessed != null) { ICFAstTldObj realized = null; if (lastObjectProcessed instanceof ICFAstTldObj) { realized = (ICFAstTldObj) lastObjectProcessed; } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "lastObjectProcessed", lastObjectProcessed, "ICFAstTldObj"); } if (realized != null) { buff = realized.getTldBuff(); } } return (buff); } public CFAstTldBuff[] readAllDerived(CFAstAuthorization Authorization) { final String S_ProcName = "readAllDerived"; String rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgTldMessageFormatter.formatTldRqstReadAll("\n\t\t\t") + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); String rspn = schema.sendReceive(Authorization, rqst); if ((rspn == null) || (rspn.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "rspn"); } CFAstXMsgRspnHandler responseHandler = schema.getResponseHandler(); responseHandler.parseStringContents(rspn); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } Object sortedMapObj = responseHandler.getSortedMapOfObjects(); if (sortedMapObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "responseHandler.getSortedMapOfObjects"); } SortedMap<CFAstTldPKey, ICFAstTldObj> sortedMap = (SortedMap<CFAstTldPKey, ICFAstTldObj>) sortedMapObj; int sz = sortedMap.size(); CFAstTldBuff arr[] = new CFAstTldBuff[sz]; Iterator<ICFAstTldObj> iter = sortedMap.values().iterator(); ICFAstTldObj cur; for (int idx = 0; idx < sz; idx++) { cur = (ICFAstTldObj) iter.next(); arr[idx] = cur.getTldBuff(); } return (arr); } public CFAstTldBuff readDerivedByIdIdx(CFAstAuthorization Authorization, long argTenantId, long argTLDId) { final String S_ProcName = "readDerivedByIdIdx"; String rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgTldMessageFormatter.formatTldRqstReadByIdIdx("\n\t\t\t", argTenantId, argTLDId) + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); String rspn = schema.sendReceive(Authorization, rqst); if ((rspn == null) || (rspn.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "rspn"); } CFAstXMsgRspnHandler responseHandler = schema.getResponseHandler(); responseHandler.parseStringContents(rspn); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } CFAstTldBuff buff = null; Object lastObjectProcessed = responseHandler.getLastObjectProcessed(); if (lastObjectProcessed != null) { ICFAstTldObj realized = null; if (lastObjectProcessed instanceof ICFAstTldObj) { realized = (ICFAstTldObj) lastObjectProcessed; } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "lastObjectProcessed", lastObjectProcessed, "ICFAstTldObj"); } if (realized != null) { buff = realized.getTldBuff(); } } return (buff); } public CFAstTldBuff[] readDerivedByTenantIdx(CFAstAuthorization Authorization, long argTenantId) { final String S_ProcName = "readDerivedByTenantIdx"; String rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgTldMessageFormatter.formatTldRqstReadByTenantIdx("\n\t\t\t", argTenantId) + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); String rspn = schema.sendReceive(Authorization, rqst); if ((rspn == null) || (rspn.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "rspn"); } CFAstXMsgRspnHandler responseHandler = schema.getResponseHandler(); responseHandler.parseStringContents(rspn); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } Object sortedMapObj = responseHandler.getSortedMapOfObjects(); if (sortedMapObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "responseHandler.getSortedMapOfObjects"); } SortedMap<CFAstTldPKey, ICFAstTldObj> sortedMap = (SortedMap<CFAstTldPKey, ICFAstTldObj>) sortedMapObj; int sz = sortedMap.size(); CFAstTldBuff arr[] = new CFAstTldBuff[sz]; Iterator<ICFAstTldObj> iter = sortedMap.values().iterator(); ICFAstTldObj cur; for (int idx = 0; idx < sz; idx++) { cur = (ICFAstTldObj) iter.next(); arr[idx] = cur.getTldBuff(); } return (arr); } public CFAstTldBuff readDerivedByNameIdx(CFAstAuthorization Authorization, long argTenantId, String argName) { final String S_ProcName = "readDerivedByNameIdx"; String rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgTldMessageFormatter.formatTldRqstReadByNameIdx("\n\t\t\t", argTenantId, argName) + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); String rspn = schema.sendReceive(Authorization, rqst); if ((rspn == null) || (rspn.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "rspn"); } CFAstXMsgRspnHandler responseHandler = schema.getResponseHandler(); responseHandler.parseStringContents(rspn); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } CFAstTldBuff buff = null; Object lastObjectProcessed = responseHandler.getLastObjectProcessed(); if (lastObjectProcessed != null) { ICFAstTldObj realized = null; if (lastObjectProcessed instanceof ICFAstTldObj) { realized = (ICFAstTldObj) lastObjectProcessed; } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "lastObjectProcessed", lastObjectProcessed, "ICFAstTldObj"); } if (realized != null) { buff = realized.getTldBuff(); } } return (buff); } public CFAstTldBuff readBuff(CFAstAuthorization Authorization, CFAstTldPKey PKey) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "readBuff"); } public CFAstTldBuff lockBuff(CFAstAuthorization Authorization, CFAstTldPKey PKey) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "lockBuff"); } public CFAstTldBuff[] readAllBuff(CFAstAuthorization Authorization) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "readAllBuff"); } public CFAstTldBuff readBuffByIdIdx(CFAstAuthorization Authorization, long argTenantId, long argTLDId) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "readBuffByIdIdx"); } public CFAstTldBuff[] readBuffByTenantIdx(CFAstAuthorization Authorization, long argTenantId) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "readBuffByTenantIdx"); } public CFAstTldBuff readBuffByNameIdx(CFAstAuthorization Authorization, long argTenantId, String argName) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "readBuffByNameIdx"); } public void updateTld(CFAstAuthorization Authorization, CFAstTldBuff Buff) { final String S_ProcName = "updateTld"; String rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgTldMessageFormatter.formatTldRqstUpdate("\n\t\t\t", Buff) + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); String rspn = schema.sendReceive(Authorization, rqst); if ((rspn == null) || (rspn.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "rspn"); } CFAstXMsgRspnHandler responseHandler = schema.getResponseHandler(); responseHandler.parseStringContents(rspn); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } CFAstTldBuff buff = null; Object lastObjectProcessed = responseHandler.getLastObjectProcessed(); if (lastObjectProcessed != null) { ICFAstTldObj realized = null; if (lastObjectProcessed instanceof ICFAstTldObj) { realized = (ICFAstTldObj) lastObjectProcessed; } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "lastObjectProcessed", lastObjectProcessed, "ICFAstTldObj"); } if (realized != null) { buff = realized.getTldBuff(); } } if (buff != null) { Buff.set(buff); } } public void deleteTld(CFAstAuthorization Authorization, CFAstTldBuff Buff) { final String S_ProcName = "deleteTld"; String rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgTldMessageFormatter.formatTldRqstDelete("\n\t\t\t", Buff) + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); String rspn = schema.sendReceive(Authorization, rqst); if ((rspn == null) || (rspn.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "rspn"); } CFAstXMsgRspnHandler responseHandler = schema.getResponseHandler(); responseHandler.parseStringContents(rspn); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } boolean deleted = responseHandler.getDeleted(); if (!deleted) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Server did not respond with a Deleted message"); } } public void deleteTldByIdIdx(CFAstAuthorization Authorization, long argTenantId, long argTLDId) { final String S_ProcName = "deleteTldByIdIdx"; String rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgTldMessageFormatter.formatTldRqstDeleteByIdIdx("\n\t\t\t", argTenantId, argTLDId) + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); String rspn = schema.sendReceive(Authorization, rqst); if ((rspn == null) || (rspn.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "rspn"); } CFAstXMsgRspnHandler responseHandler = schema.getResponseHandler(); responseHandler.parseStringContents(rspn); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } boolean deleted = responseHandler.getDeleted(); if (!deleted) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Server did not respond with a Deleted message"); } } public void deleteTldByIdIdx(CFAstAuthorization Authorization, CFAstTldPKey argKey) { deleteTldByIdIdx(Authorization, argKey.getRequiredTenantId(), argKey.getRequiredTLDId()); } public void deleteTldByTenantIdx(CFAstAuthorization Authorization, long argTenantId) { final String S_ProcName = "deleteTldByTenantIdx"; String rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgTldMessageFormatter.formatTldRqstDeleteByTenantIdx("\n\t\t\t", argTenantId) + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); String rspn = schema.sendReceive(Authorization, rqst); if ((rspn == null) || (rspn.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "rspn"); } CFAstXMsgRspnHandler responseHandler = schema.getResponseHandler(); responseHandler.parseStringContents(rspn); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } boolean deleted = responseHandler.getDeleted(); if (!deleted) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Server did not respond with a Deleted message"); } } public void deleteTldByTenantIdx(CFAstAuthorization Authorization, CFAstTldByTenantIdxKey argKey) { deleteTldByTenantIdx(Authorization, argKey.getRequiredTenantId()); } public void deleteTldByNameIdx(CFAstAuthorization Authorization, long argTenantId, String argName) { final String S_ProcName = "deleteTldByNameIdx"; String rqst = CFAstXMsgSchemaMessageFormatter.formatRqstXmlPreamble() + "\n" + "\t" + CFAstXMsgTldMessageFormatter.formatTldRqstDeleteByNameIdx("\n\t\t\t", argTenantId, argName) + "\n" + CFAstXMsgSchemaMessageFormatter.formatRqstXmlPostamble(); String rspn = schema.sendReceive(Authorization, rqst); if ((rspn == null) || (rspn.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "rspn"); } CFAstXMsgRspnHandler responseHandler = schema.getResponseHandler(); responseHandler.parseStringContents(rspn); CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised(); if (exceptionRaised != null) { throw exceptionRaised; } boolean deleted = responseHandler.getDeleted(); if (!deleted) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Server did not respond with a Deleted message"); } } public void deleteTldByNameIdx(CFAstAuthorization Authorization, CFAstTldByNameIdxKey argKey) { deleteTldByNameIdx(Authorization, argKey.getRequiredTenantId(), argKey.getRequiredName()); } public CFAstCursor openTldCursorAll(CFAstAuthorization Authorization) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "openTldCursorAll"); } public CFAstCursor openTldCursorByTenantIdx(CFAstAuthorization Authorization, long argTenantId) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "openTldCursorByTenantIdx"); } public void closeTldCursor(CFAstCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "closeTldCursor"); } public CFAstTldBuff nextTldCursor(CFAstCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "next$Tablename$Cursor"); } public CFAstTldBuff prevTldCursor(CFAstCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "prevTldCursor"); } public CFAstTldBuff firstTldCursor(CFAstCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "firstTldCursor"); } public CFAstTldBuff lastTldCursor(CFAstCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "lastTldCursor"); } public CFAstTldBuff nthTldCursor(CFAstCursor Cursor, int Idx) { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "nthTldCursor"); } /** * Release the prepared statements. * <p> * When the schema changes connections, the prepared statements * have to be released because they contain connection-specific * information for most databases. */ public void releasePreparedStatements() { throw CFLib.getDefaultExceptionFactory().newNotSupportedException(getClass(), "releasePreparedStatements"); } }