Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

xmlflowcontext.cpp

Go to the documentation of this file.
00001 //============================================================================= 
00002 //
00003 // XDFLengine library
00004 //
00005 //-----------------------------------------------------------------------------
00006 //  XMLFLOWCONTEXT.CPP
00007 //----------------------------------------------------------------------------- 
00013 //_____________________________________________________________________________
00014 //
00015 //  Copyright (C) 2003 Guillaume Baurand. All Rights Reserved.
00016 //
00017 //  This file is part of the XDFLengine project.
00018 //
00019 //  The XDFLengine is free software; you can redistribute it and/or modify
00020 //  it under the terms of the GNU General Public License as published by
00021 //  the Free Software Foundation; either version 2 of the License, or
00022 //  (at your option) any later version.
00023 //
00024 //  This program is distributed in the hope that it will be useful,
00025 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00026 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00027 //  GNU General Public License for more details.
00028 //
00029 //  You should have received a copy of the GNU General Public License
00030 //  along with this program; if not, write to the Free Software
00031 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
00032 //  USA.
00033 //
00034 //  For more information, 
00035 //      contact  : guillaume@baurand.net 
00036 //      or visit : http://xdflengine.sourceforge.net
00037 //
00038 //=============================================================================  
00039 
00040 #   include "xmlflowcontext.hpp"
00041 #   include "processor/xmlprocessor.hpp"
00042 #   include <xercesc/util/PlatformUtils.hpp>
00043 #   include <xercesc/util/XMLUniDefs.hpp>
00044 #   include <xercesc/util/XMLString.hpp>
00045 #   include <xercesc/util/TransService.hpp>
00046 #   include <xercesc/util/TranscodingException.hpp>
00047 
00048 BEGIN_XDFLENGINE_NS
00049 
00050 //============================================================================= 
00051 //  CLASS XMLFlowContext
00052 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00053 
00054 
00055 //  CONSTRUCTORS AND DESTRUCTOR  
00056 
00057     //_________________________________________________________________________
00058     //  XMLFlowContext
00059     //-------------------------------------------------------------------------
00060     XMLFlowContext::XMLFlowContext( const XMLProcessor* p_pXMLProcessor, const XMLFlowContext* p_pParent, unsigned int p_uiThreadId , const char* p_pszEncoding )
00061     {
00062 
00063         XMLTransService::Codes l_resCode;
00064         unsigned int l_TmpBufSize;
00065         XMLCh* l_fOutEncoding;
00066 
00067         // Init pointers
00068         m_pXMLProcessor = p_pXMLProcessor;
00069         m_uiThreadId = p_uiThreadId;
00070                 if(!p_pszEncoding) p_pszEncoding = CHAR_ENCODING_DEFAULT;
00071         m_pszEncoding = importCharBuffer(0,  p_pszEncoding);
00072         m_pParent = p_pParent;
00073 
00074         // Try to create a transcoder for this encoding
00075         l_TmpBufSize     = 16 * 1024;           
00076         l_fOutEncoding = STRX( m_pszEncoding);
00077                 DEBUG_ECHO << "Create transcoder for " << m_pszEncoding << "\n";
00078         m_fXCoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor( l_fOutEncoding, l_resCode, l_TmpBufSize,XMLPlatformUtils::fgMemoryManager);
00079         delete[] l_fOutEncoding;
00080 
00081         DEBUG_CREATE(XMLFlowContext)
00082     }
00083 
00084     //_________________________________________________________________________
00085     //  ~XMLFlowContext
00086     //-------------------------------------------------------------------------
00087     XMLFlowContext::~XMLFlowContext()
00088     {       
00089         DEBUG_DEL(XMLFlowContext)
00090     
00091         delete m_fXCoder;
00092         m_pszEncoding = releaseCharBuffer( m_pszEncoding);
00093 
00094         releaseParameters();
00095         releaseBuffers();       
00096     }
00097 
00098     //_____________________________________________________________________
00099     //  SETPROCESSOR
00100     //---------------------------------------------------------------------
00101     void XMLFlowContext::setProcessor(const XMLProcessor* p_pXMLProcessor)
00102     {
00103         m_pXMLProcessor = p_pXMLProcessor;
00104     }
00105 
00106 
00107     //_____________________________________________________________________
00108     //  GETPROCESSOR
00109     //---------------------------------------------------------------------
00110     const XMLProcessor* XMLFlowContext::getProcessor()
00111     {
00112         return m_pXMLProcessor;
00113     }
00114 
00115 
00116     //_____________________________________________________________________
00117     //  SETPARENT
00118     //---------------------------------------------------------------------
00119     void XMLFlowContext::setParent(const XMLFlowContext* p_pParent)
00120     {
00121         m_pParent = p_pParent;
00122     }
00123 
00124 
00125     //_____________________________________________________________________
00126     //  GETPARENT
00127     //---------------------------------------------------------------------
00128     const XMLFlowContext* XMLFlowContext::getParent()
00129     {
00130         return m_pParent;
00131     }
00132 
00133 // GETTERS
00134 
00135 
00136     //_____________________________________________________________________
00137     //  GETTHREADID
00138     //---------------------------------------------------------------------
00139     unsigned int XMLFlowContext::getThreadId() const
00140     {
00141         DEBUG_FUNC(XMLFlow::getThreadId)
00142         return m_uiThreadId;
00143     }
00144 
00145     //_____________________________________________________________________
00146     //  GETENCODING
00147     //---------------------------------------------------------------------
00148     const char* XMLFlowContext::getEncoding () const
00149     {
00150         DEBUG_FUNC(XMLFlow::getEncoding)
00151         return exportCharBuffer( m_pszEncoding);
00152     }
00153 
00154 
00155     //_____________________________________________________________________
00156     //  GETTRANSCODER
00157     //---------------------------------------------------------------------
00158     XMLTranscoder* XMLFlowContext::getTranscoder() const
00159     {
00160         DEBUG_FUNC(XMLFlow::getEncoding)
00161         return m_fXCoder;
00162     }
00163 
00164 
00165 // ERROR
00166 
00167     //_____________________________________________________________________
00168     //  GETERROR
00169     //--------------------------------------------------------------------- 
00170     unsigned int XMLFlowContext::getError() const
00171     {
00172         DEBUG_FUNC(XMLFlow::getError)
00173         return m_uiErrorNumber;
00174     }
00175 
00176 
00177 
00178 //  PARAMETERS 
00179     
00180     //_________________________________________________________________________
00181     //  ADDPARAMETER
00182     //-------------------------------------------------------------------------
00183     void XMLFlowContext::addParameter ( const char* p_pszName, const char* p_pszValue)
00184     {
00185         DEBUG_FUNC(XMLFlow::addParameter)
00186         m_vaParameters.add( importCharBuffer( m_vaParameters.remove( p_pszName),p_pszValue), p_pszName); 
00187     }
00188 
00189     //_________________________________________________________________________
00190     //  GETPARAMETER
00191     //-------------------------------------------------------------------------
00192     const char* XMLFlowContext::getParameter ( const char* p_pszName) const
00193     {
00194         char*   l_pszValue=0;
00195 
00196         DEBUG_FUNC(XMLFlow::getParameter)
00197 
00198         l_pszValue = m_vaParameters.get( p_pszName);
00199         if( l_pszValue)
00200         {
00201             if(strlen(l_pszValue)>0) return exportCharBuffer( l_pszValue);
00202         }
00203 
00204         if(m_pParent) return m_pParent->getParameter( p_pszName);
00205         else return exportCharBuffer("");   
00206     }
00207 
00208 
00209     //_________________________________________________________________________
00210     //  REMOVEPARAMETER
00211     //-------------------------------------------------------------------------
00212     const char* XMLFlowContext::removeParameter ( const char* p_pszName) 
00213     {
00214         DEBUG_FUNC(XMLFlow::getParameter)
00215 
00216         return m_vaParameters.remove( p_pszName);
00217     }
00218 
00219 
00220 //  BUFFERS  
00221 
00222     //_________________________________________________________________________
00223     //  ADDNAMEDBUFFER
00224     //-------------------------------------------------------------------------
00225     void XMLFlowContext::addNamedBuffer( const char* p_pszName, XMLStreamBuffer* p_pXMLStreamBuffer)
00226     {
00227         //---------------------------------------------------------------------
00228         XMLStreamBuffer* l_pOldBuffer=0;
00229         //---------------------------------------------------------------------
00230 
00231         DEBUG_FUNC(XMLFlow::addNamedBuffer)
00232 
00233         delete( m_vaNamedBuffers.remove( p_pszName));
00234         m_vaNamedBuffers.add( p_pXMLStreamBuffer, p_pszName);
00235     }
00236 
00237     //_________________________________________________________________________
00238     //  GETNAMEDBUFFER
00239     //-------------------------------------------------------------------------
00240     XMLStreamBuffer* XMLFlowContext::getNamedBuffer( const char* p_pszName) const
00241     {
00242         XMLStreamBuffer*    l_pBuffer;
00243         DEBUG_FUNC(XMLFlow::getNamedBuffer)
00244         
00245         l_pBuffer = m_vaNamedBuffers.get( p_pszName);
00246         if( l_pBuffer) return l_pBuffer;
00247         else 
00248         {
00249             if(m_pParent) return m_pParent->getNamedBuffer(p_pszName);
00250             else return 0;
00251         }
00252     }
00253 
00254     //_________________________________________________________________________
00255     //  GETNAMEDBUFFER
00256     //-------------------------------------------------------------------------
00257     XMLStreamBuffer* XMLFlowContext::removeNamedBuffer( const char* p_pszName) 
00258     {
00259         DEBUG_FUNC(XMLFlow::getNamedBuffer)
00260         
00261         return m_vaNamedBuffers.remove( p_pszName);
00262     }
00263 
00264 // RELEASERS
00265 
00266     //_____________________________________________________________________
00267     //  RELEASEBUFFERS
00268     //---------------------------------------------------------------------
00269     void XMLFlowContext::releaseBuffers()
00270     {
00271         //-----------------------------------------------------------------
00272         XMLStreamBuffer*        l_pXMLStreamBuffer;
00273         //-----------------------------------------------------------------
00274 
00275         DEBUG_FUNC(XMLFlow::releaseBuffers)
00276 
00277         // Release buffers map;
00278         while( !m_vaNamedBuffers.empty() )
00279         {
00280             l_pXMLStreamBuffer = m_vaNamedBuffers.pop();
00281             //l_pXMLStreamBuffer->flush();
00282             delete l_pXMLStreamBuffer;  
00283         }
00284     }
00285 
00286     //_____________________________________________________________________
00287     //  RELEASEPARAMETERS
00288     //---------------------------------------------------------------------
00289     void XMLFlowContext::releaseParameters()
00290     {
00291         DEBUG_FUNC(XMLFlow::releaseParameters)
00292         while( !m_vaParameters.empty() ) releaseCharBuffer( m_vaParameters.pop());  
00293     }
00294 
00295 
00296 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00297 //=============================================================================
00298 
00299 END_XDFLENGINE_NS
00300 

Generated on Sat Oct 4 13:20:03 2003 for XDFLengine by doxygen1.3-rc2