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 "funccallstreamer.hpp"
00041 # include "processor/xmlprocessor.hpp"
00042 # include "processor/xmlflowcontext.hpp"
00043
00044
00045 BEGIN_XDFLENGINE_NS
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 FuncCallStreamer::FuncCallStreamer( const XMLStreamerFactory* p_pParent, StreamerParams* p_pParameters, XMLFlowContext* p_pContext, XMLStreamConsumer* p_pOutput)
00057 :XMLStreamer( p_pParent, p_pParameters, p_pContext, p_pOutput)
00058 {
00059 DEBUG_CREATE(FuncCallStreamer)
00060 m_pScriptParamBuffer = 0;
00061 }
00062
00063
00064
00065
00066 FuncCallStreamer::~FuncCallStreamer()
00067 {
00068 DEBUG_DEL(FuncCallStreamer)
00069 }
00070
00071
00072
00073
00074
00075
00076 bool FuncCallStreamer::initStream()
00077 {
00078
00079 DEBUG_IN(FuncCallStreamer::initStream)
00080
00081 m_pScriptParamBuffer = m_pContext->getProcessor() -> getNewBuffer();
00082
00083 DEBUG_OUT(FuncCallStreamer::initStream)
00084
00085 return true;
00086 }
00087
00088
00089
00090
00091 void FuncCallStreamer::writeData( const char* p_pszData, unsigned int p_uiDataLen)
00092 {
00093 DEBUG_IN(FuncCallStreamer::writeData)
00094
00095 m_pScriptParamBuffer -> writeData( p_pszData, p_uiDataLen);
00096
00097 DEBUG_OUT(FuncCallStreamer::writeData)
00098 }
00099
00100
00101
00102
00103 bool FuncCallStreamer::commitStream(bool p_fFinal)
00104 {
00105
00106 XMLFlowContext* l_pScriptContext=0;
00107 const RootStreamNode* l_pScriptRoot;
00108 unsigned int i;
00109 const char* l_pszScriptName;
00110
00111
00112 PREP_CATCH_XML_FLOW_ERROR;
00113
00114 l_pszScriptName = getParamValue( m_pParameters, FUNCCALLSTREAMER_NAME,"");
00115 if(p_fFinal )
00116 {
00117
00118 l_pScriptRoot = ((FuncCallStreamerFactory*) m_pParent)->getCachedScript(l_pszScriptName);
00119 if(!l_pScriptRoot) THROW_XMLFLOW_EXCEPTION( ERRCODE_LOC_FUNCCALLSTREAMER + ERRCODE_CAUSE_MISSINGREF , "Function not found." , l_pszScriptName, "FuncCallStreamer::commitStream", "", false );
00120
00121 l_pScriptContext = new XMLFlowContext( m_pContext->getProcessor(), m_pContext, m_pContext->getThreadId(), m_pContext->getEncoding());
00122
00123
00124 for( i=0; i<m_pParameters->size(); i++) l_pScriptContext->addParameter( m_pParameters->getKey(i), m_pParameters->get(i));
00125
00126 WATCH_XML_FLOW_ERROR
00127 {
00128 logout << "\t" << FUNCCALLSTREAMER_TAGNAME<< " : " << "Call function " << l_pszScriptName << "...\n";
00129 l_pScriptContext->addNamedBuffer( FUNCCALLSTREAMER_BUFINPUT, m_pScriptParamBuffer);
00130 m_pContext->getProcessor()->execute( l_pScriptRoot , m_pOutput, l_pScriptContext);
00131 }
00132 CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN
00133
00134 }
00135
00136 RELEASE_AND_RETURN:
00137 if(p_fFinal )
00138 {
00139 l_pScriptContext->removeNamedBuffer(FUNCCALLSTREAMER_BUFINPUT);
00140 delete m_pScriptParamBuffer;
00141 delete l_pScriptContext;
00142 }
00143 ON_XML_FLOW_ERROR_THROW;
00144 return false;
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 FuncCallStreamerFactory::~FuncCallStreamerFactory()
00163 {
00164 while(!m_pvaScriptCache.empty()) delete m_pvaScriptCache.pop();
00165 }
00166
00167
00168
00169
00170 XMLStreamer* FuncCallStreamerFactory::getStreamer(
00171 StreamerParams* p_pParameters,
00172 XMLFlowContext* p_pStreamContext,
00173 XMLStreamConsumer* p_pStreamConsumer) const
00174 {
00175 return (XMLStreamer*) new FuncCallStreamer( this, p_pParameters, p_pStreamContext, p_pStreamConsumer);
00176 }
00177
00178
00179
00180
00181
00182 void FuncCallStreamerFactory::cacheScript( RootStreamNode* p_pRootNode, const char* p_pszCacheName)
00183 {
00184 m_pvaScriptCache.add( p_pRootNode, p_pszCacheName);
00185 }
00186
00187
00188
00189
00190 const RootStreamNode* FuncCallStreamerFactory::getCachedScript( const char* p_pszCacheName)
00191 {
00192 return m_pvaScriptCache.get( p_pszCacheName);
00193 }
00194
00195
00196
00197
00198
00199 END_XDFLENGINE_NS
00200
00201
00202
00203
00204
00205
00206
00207