00001
00002
00003
00004
00005
00006
00007
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
00052
00053
00054
00055
00056
00057
00058
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
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
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
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
00100
00101 void XMLFlowContext::setProcessor(const XMLProcessor* p_pXMLProcessor)
00102 {
00103 m_pXMLProcessor = p_pXMLProcessor;
00104 }
00105
00106
00107
00108
00109
00110 const XMLProcessor* XMLFlowContext::getProcessor()
00111 {
00112 return m_pXMLProcessor;
00113 }
00114
00115
00116
00117
00118
00119 void XMLFlowContext::setParent(const XMLFlowContext* p_pParent)
00120 {
00121 m_pParent = p_pParent;
00122 }
00123
00124
00125
00126
00127
00128 const XMLFlowContext* XMLFlowContext::getParent()
00129 {
00130 return m_pParent;
00131 }
00132
00133
00134
00135
00136
00137
00138
00139 unsigned int XMLFlowContext::getThreadId() const
00140 {
00141 DEBUG_FUNC(XMLFlow::getThreadId)
00142 return m_uiThreadId;
00143 }
00144
00145
00146
00147
00148 const char* XMLFlowContext::getEncoding () const
00149 {
00150 DEBUG_FUNC(XMLFlow::getEncoding)
00151 return exportCharBuffer( m_pszEncoding);
00152 }
00153
00154
00155
00156
00157
00158 XMLTranscoder* XMLFlowContext::getTranscoder() const
00159 {
00160 DEBUG_FUNC(XMLFlow::getEncoding)
00161 return m_fXCoder;
00162 }
00163
00164
00165
00166
00167
00168
00169
00170 unsigned int XMLFlowContext::getError() const
00171 {
00172 DEBUG_FUNC(XMLFlow::getError)
00173 return m_uiErrorNumber;
00174 }
00175
00176
00177
00178
00179
00180
00181
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
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
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
00221
00222
00223
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
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
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
00265
00266
00267
00268
00269 void XMLFlowContext::releaseBuffers()
00270 {
00271
00272 XMLStreamBuffer* l_pXMLStreamBuffer;
00273
00274
00275 DEBUG_FUNC(XMLFlow::releaseBuffers)
00276
00277
00278 while( !m_vaNamedBuffers.empty() )
00279 {
00280 l_pXMLStreamBuffer = m_vaNamedBuffers.pop();
00281
00282 delete l_pXMLStreamBuffer;
00283 }
00284 }
00285
00286
00287
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