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 "dbobject.hpp"
00041 # include "valuers/xpathdbvaluer.hpp"
00042 # include "flow/consumers/streamsax2parser.hpp"
00043
00044 BEGIN_XDFLENGINE_NS
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 DBObjectField::DBObjectField( const char* p_pszName)
00057 {
00058 DEBUG_CREATE(DBObjectField)
00059
00060 m_pszName = 0;
00061 m_pszValue = 0;
00062 m_pSAXDB_FieldDefinition = 0;
00063
00064 setName(p_pszName);
00065
00066 m_DBOBJParentNode=0;
00067 m_fCalculated=false;
00068 }
00069
00070
00071
00072
00073 DBObjectField::DBObjectField( const DBOBJDefinitionField* p_pDBObjectFieldDef)
00074 {
00075 DEBUG_CREATE(DBObjectField)
00076
00077 m_pszName = 0;
00078 m_pszValue = 0;
00079 m_pSAXDB_FieldDefinition = 0;
00080
00081 if(p_pDBObjectFieldDef) setDefinition( p_pDBObjectFieldDef);
00082
00083 m_DBOBJParentNode=0;
00084 m_fCalculated=false;
00085 }
00086
00087
00088
00089
00090 DBObjectField::~DBObjectField()
00091 {
00092 DEBUG_DEL(DBObjectField)
00093
00094 m_pszName=releaseCharBuffer( m_pszName);
00095 m_pszValue=releaseCharBuffer( m_pszValue);
00096 m_fAttribute = 0;
00097 m_pSAXDB_FieldDefinition = 0;
00098 }
00099
00100
00101
00102
00103
00104
00105 int DBObjectField::getType() const
00106 {
00107 DEBUG_FUNC(DBObjectField::getType)
00108
00109 return DBOBJECTTYPE_FIELD;
00110 }
00111
00112
00113
00114
00115 const char* DBObjectField::getName() const
00116 {
00117 DEBUG_FUNC(DBObjectField::getName)
00118
00119 DEBUG_ECHO << m_pszName << "\n";
00120 return exportCharBuffer( m_pszName);
00121 }
00122
00123
00124
00125
00126 const char* DBObjectField::getValue()
00127 {
00128
00129 DBOBJSetAction l_intAction;
00130 const char* l_pszValue;
00131 char* l_pszCalculatedValue;
00132
00133
00134 DEBUG_FUNC(DBObjectField::getValue)
00135
00136
00137 if(! m_fCalculated && m_pSAXDB_FieldDefinition )
00138 {
00139
00140 l_intAction = DBOBJaction_Unspec;
00141 if(m_DBOBJParentNode) l_intAction = m_DBOBJParentNode->getAction();
00142
00143 l_pszValue = DBOBJDEFFIELD_NOVALUE;
00144
00145 switch( l_intAction)
00146 {
00147 case DBOBJaction_Insert:
00148 l_pszValue = m_pSAXDB_FieldDefinition->getIValue();
00149 break;
00150 case DBOBJaction_Update:
00151 l_pszValue = m_pSAXDB_FieldDefinition->getUValue();
00152 break;
00153 case DBOBJaction_Delete:
00154 l_pszValue = m_pSAXDB_FieldDefinition->getDValue();
00155 break;
00156 }
00157
00158 if( strcmp( l_pszValue, DBOBJDEFFIELD_NOVALUE) == 0) l_pszValue=m_pSAXDB_FieldDefinition->getValue();
00159 if( strcmp( l_pszValue, DBOBJDEFFIELD_NOVALUE) == 0) l_pszValue=m_pszValue;
00160 if( !l_pszValue) l_pszValue="";
00161 l_pszCalculatedValue = m_DBOBJParentNode->calculateRelValue( l_pszValue);
00162
00163 if( strcmp( l_pszCalculatedValue, DBOBJDEFFIELD_NOVALUE) == 0 ) l_pszCalculatedValue=0;
00164 if(!l_pszCalculatedValue) l_pszCalculatedValue=copyCharBuffer("");
00165
00166 m_pszValue=importCharBuffer( m_pszValue,l_pszCalculatedValue);
00167 l_pszCalculatedValue = releaseCharBuffer( l_pszCalculatedValue);
00168 m_fCalculated=true;
00169 }
00170
00171 return m_pszValue;
00172 }
00173
00174
00175
00176
00177 bool DBObjectField::isAttribute() const
00178 {
00179 DEBUG_FUNC(DBObjectField::isAttribute)
00180 return m_fAttribute;
00181 }
00182
00183
00184
00185
00186 const DBOBJDefinitionField* DBObjectField::getDefinition() const
00187 {
00188 DEBUG_FUNC(DBObjectField::getDefinition)
00189 return m_pSAXDB_FieldDefinition;
00190 }
00191
00192
00193
00194
00195 void DBObjectField::getXML(XMLStreamConsumer* p_pXMLBufOut)
00196 {
00197
00198 DEBUG_FUNC(DBObjectField::getXML)
00199
00200 if(m_fAttribute)
00201 {
00202 (*p_pXMLBufOut) << (m_pszName+1) << "=\"" << getValue() << "\" ";
00203 }
00204 else
00205 {
00206 (*p_pXMLBufOut) << "<" << m_pszName << "><![CDATA[" << getValue() << "]]></" << m_pszName << ">\n";
00207 }
00208
00209 }
00210
00211
00212
00213
00214
00215
00216 void DBObjectField::setName( const char* p_pszName)
00217 {
00218 DEBUG_FUNC(DBObjectField::setName)
00219
00220 m_pszName=importCharBuffer( m_pszName, p_pszName);
00221 if(m_pszName[0]==DBOBJDEFFIELD_ATTR) setAttribute(true);
00222 else setAttribute(false);
00223 }
00224
00225
00226
00227
00228 void DBObjectField::setAttribute( bool p_fAttribute)
00229 {
00230 DEBUG_FUNC(DBObjectField::setAttribute)
00231
00232 m_fAttribute = p_fAttribute;
00233 }
00234
00235
00236
00237
00238
00239 void DBObjectField::setValue( const char* p_pszFieldValue)
00240 {
00241 DEBUG_FUNC(DBObjectField::setValue)
00242
00243
00244 m_pszValue=importCharBuffer( m_pszValue, p_pszFieldValue);
00245 }
00246
00247
00248
00249
00250 void DBObjectField::setParent( DBObjectNode* p_DBOBJParentNode)
00251 {
00252 DEBUG_FUNC(DBObjectField::setParent)
00253
00254 m_DBOBJParentNode=p_DBOBJParentNode;
00255 }
00256
00257
00258
00259
00260 void DBObjectField::setDefinition( const DBOBJDefinitionField* p_pDBObjectFieldDef)
00261 {
00262 DEBUG_FUNC(DBObjectField::setDefinition)
00263
00264 m_pSAXDB_FieldDefinition = p_pDBObjectFieldDef;
00265 m_fAttribute = m_pSAXDB_FieldDefinition->isAttribute() ;
00266 m_pszName = importCharBuffer( m_pszName, m_pSAXDB_FieldDefinition->getName());
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 DBObjectNode::DBObjectNode(const DBOBJDefinitionNode* p_pDBOBJDefNode )
00289 {
00290 m_pszName = 0;
00291 m_pValuableParent = 0;
00292 m_pParentNode = 0;
00293 m_pXpathValuer = 0;
00294
00295 setDefinition( p_pDBOBJDefNode);
00296 setAction( DBOBJaction_Unspec);
00297
00298 DEBUG_CREATE(DBObjectNode)
00299 }
00300
00301
00302
00303
00304
00305 DBObjectNode::~DBObjectNode()
00306 {
00307 DEBUG_DEL(DBObjectNode)
00308
00309 m_pszName = releaseCharBuffer( m_pszName);
00310 deleteTree();
00311 }
00312
00313
00314
00315
00316
00317
00318 int DBObjectNode::getType() const
00319 {
00320 DEBUG_FUNC(DBObjectField::getType)
00321 return DBOBJECTTYPE_NODE;
00322 }
00323
00324
00325
00326
00327
00328 const char* DBObjectNode::getName() const
00329 {
00330 DEBUG_FUNC(DBObjectNode::getName)
00331 return exportCharBuffer( m_pszName);
00332 }
00333
00334
00335
00336
00337 DBOBJSetAction DBObjectNode::getAction() const
00338 {
00339 DEBUG_FUNC(DBObjectNode::getAction)
00340 return m_intAction;
00341
00342 }
00343
00344
00345
00346
00347 DBObjectNode* DBObjectNode::getParent() const
00348 {
00349 DEBUG_FUNC(DBObjectNode::getParent)
00350 return m_pParentNode;
00351 }
00352
00353
00354
00355
00356 const DBOBJDefinitionNode* DBObjectNode::getDefinition() const
00357 {
00358 DEBUG_FUNC(DBObjectNode::getDefinition)
00359 return m_pDBObjectNodeDefinition;
00360 }
00361
00362
00363
00364
00365 XMLValuable* DBObjectNode::getValuable()
00366 {
00367 DEBUG_FUNC(DBObjectNode::getValuable)
00368 if(! m_pValuableParent) return m_pParentNode->getValuable();
00369 return m_pValuableParent;
00370 }
00371
00372
00373
00374
00375
00376
00377 void DBObjectNode::setAction( DBOBJSetAction p_intAction)
00378 {
00379 DEBUG_FUNC(DBObjectNode::setAction)
00380 m_intAction = p_intAction;
00381 }
00382
00383
00384
00385
00386
00387 void DBObjectNode::setParent( DBObjectNode* p_DBOBJParentNode)
00388 {
00389 DEBUG_FUNC(DBObjectNode::setParent)
00390
00391 m_pParentNode = p_DBOBJParentNode;
00392 }
00393
00394
00395
00396
00397 void DBObjectNode::setDefinition( const DBOBJDefinitionNode* p_pDBOBJDefNode)
00398 {
00399 DEBUG_FUNC(DBObjectNode::setDefinition)
00400
00401 m_pDBObjectNodeDefinition = p_pDBOBJDefNode;
00402 m_pszName = importCharBuffer( m_pszName, m_pDBObjectNodeDefinition->getName());
00403 }
00404
00405
00406
00407
00408 void DBObjectNode::setValuable(XMLValuable* p_pValuableParent)
00409 {
00410 DEBUG_FUNC(DBObjectNode::setValuable)
00411
00412 m_pValuableParent = p_pValuableParent;
00413 }
00414
00415
00416
00417
00418
00419
00420 void DBObjectNode::addChildNode( DBObjectNode* p_pChildNode)
00421 {
00422 DEBUG_FUNC(DBObjectNode::addChildNode)
00423
00424 m_vaChildren.add( p_pChildNode,p_pChildNode->getName());
00425 p_pChildNode->setParent(this);
00426
00427 }
00428
00429
00430
00431
00432 void DBObjectNode::removeChildNode( unsigned int p_uiIndex, bool p_fDestroy)
00433 {
00434
00435 DBObjectNode* l_pChildNode = 0;
00436
00437
00438 DEBUG_FUNC(DBObjectNode::removeChildNode)
00439
00440 l_pChildNode = m_vaChildren.remove(p_uiIndex);
00441 if(l_pChildNode)
00442 {
00443 l_pChildNode->setParent(0);
00444 if( p_fDestroy) delete l_pChildNode;
00445 }
00446 }
00447
00448
00449
00450
00451 void DBObjectNode::removeChildNode( const char* p_pszName, unsigned int p_uiIndex, bool p_fDestroy)
00452 {
00453
00454 DBObjectNode* l_pChildNode = 0;
00455
00456
00457 DEBUG_FUNC(DBObjectNode::removeChildNode)
00458
00459 l_pChildNode = m_vaChildren.get(p_pszName, p_uiIndex);
00460 if(l_pChildNode)
00461 {
00462 l_pChildNode->setParent(0);
00463 if( p_fDestroy) delete l_pChildNode;
00464 }
00465 }
00466
00467
00468
00469
00470 unsigned int DBObjectNode::getChildNodesCount() const
00471 {
00472 DEBUG_FUNC(DBObjectNode::getChildNodesCount)
00473 return m_vaChildren.size();
00474 }
00475
00476
00477
00478
00479 unsigned int DBObjectNode::getChildNodesCount( const char* p_pszName) const
00480 {
00481 DEBUG_FUNC(DBObjectNode::getChildNodesCount)
00482 return m_vaChildren.count( p_pszName);
00483 }
00484
00485
00486
00487
00488 DBObjectNode* DBObjectNode::getChildNode( unsigned int p_uiIndex) const
00489 {
00490 DEBUG_FUNC(DBObjectNode::getChildNode)
00491 return m_vaChildren.get(p_uiIndex);
00492 }
00493
00494
00495
00496
00497 DBObjectNode* DBObjectNode::getChildNode( const char* p_pszName, unsigned int p_uiIndex) const
00498 {
00499 DEBUG_FUNC(DBObjectNode::getChildNode(name))
00500 return m_vaChildren.get(p_pszName, p_uiIndex);
00501 }
00502
00503
00504
00505
00506 DBObjectNode* DBObjectNode::getCurrentChild()
00507 {
00508 DEBUG_FUNC(DBObjectNode::getCurrentChild)
00509 return m_vaChildren.current();
00510 }
00511
00512
00513
00514
00515 void DBObjectNode::movePreviousChild()
00516 {
00517 DEBUG_FUNC(DBObjectNode::movePreviousChild)
00518 m_vaChildren.movePrevious();
00519 }
00520
00521
00522
00523
00524 void DBObjectNode::moveNextChild()
00525 {
00526 DEBUG_FUNC(DBObjectNode::moveNextChild)
00527 m_vaChildren.moveNext();
00528 }
00529
00530
00531
00532
00533 void DBObjectNode::moveFirstChild()
00534 {
00535 DEBUG_FUNC(DBObjectNode::moveFirstChild)
00536 m_vaChildren.moveFirst();
00537 }
00538
00539
00540
00541
00542 void DBObjectNode::moveLastChild()
00543 {
00544 DEBUG_FUNC(DBObjectNode::moveLastChild)
00545 m_vaChildren.moveLast();
00546 }
00547
00548
00549
00550
00551
00552
00553 void DBObjectNode::addField(DBObjectField* p_pField)
00554 {
00555 DEBUG_FUNC(DBObjectNode::addField)
00556
00557 m_vaFields.add(p_pField, p_pField->getName());
00558 p_pField->setParent( this );
00559 }
00560
00561
00562
00563
00564 void DBObjectNode::removeField( unsigned int p_uiIndex, bool p_fDestroy)
00565 {
00566 DBObjectField* l_pField;
00567
00568 DEBUG_FUNC(DBObjectNode::removeField)
00569
00570 l_pField=m_vaFields.remove(p_uiIndex);
00571 if(l_pField)
00572 {
00573 l_pField->setParent(0);
00574 if(p_fDestroy) delete l_pField;
00575 }
00576 }
00577
00578
00579
00580
00581 void DBObjectNode::removeField( const char* p_pszName, bool p_fDestroy)
00582 {
00583 DBObjectField* l_pField;
00584
00585 DEBUG_FUNC(DBObjectNode::removeField)
00586
00587 l_pField=m_vaFields.remove(p_pszName);
00588 if(l_pField)
00589 {
00590 l_pField->setParent(0);
00591 if(p_fDestroy) delete l_pField;
00592 }
00593 }
00594
00595
00596
00597
00598 unsigned int DBObjectNode::getFieldsCount() const
00599 {
00600 DEBUG_FUNC(DBObjectNode::getFieldsCount)
00601 return m_vaFields.size();
00602 }
00603
00604
00605
00606
00607 DBObjectField* DBObjectNode::getField(unsigned int p_uiIndex) const
00608 {
00609 DEBUG_FUNC(DBObjectNode::getField(index))
00610
00611 return m_vaFields.get(p_uiIndex);
00612 }
00613
00614
00615
00616
00617 DBObjectField* DBObjectNode::getField(const char* p_pszName) const
00618 {
00619 DEBUG_FUNC(DBObjectNode::getField(name))
00620
00621 return m_vaFields.get(p_pszName);
00622 }
00623
00624
00625
00626
00627 DBObjectField* DBObjectNode::getCurrentField()
00628 {
00629 DEBUG_FUNC(DBObjectNode::getCurrentField)
00630 return m_vaFields.current();
00631 }
00632
00633
00634
00635
00636 void DBObjectNode::movePreviousField()
00637 {
00638 DEBUG_FUNC(DBObjectNode::movePreviousField)
00639 m_vaFields.movePrevious();
00640 }
00641
00642
00643
00644
00645 void DBObjectNode::moveNextField()
00646 {
00647 DEBUG_FUNC(DBObjectNode::moveNextField)
00648 m_vaFields.moveNext();
00649 }
00650
00651
00652
00653
00654 void DBObjectNode::moveFirstField()
00655 {
00656 DEBUG_FUNC(DBObjectNode::moveFirstField)
00657 m_vaFields.moveFirst();
00658 }
00659
00660
00661
00662
00663 void DBObjectNode::moveLastField()
00664 {
00665 DEBUG_FUNC(DBObjectNode::moveLastField)
00666 m_vaFields.moveLast();
00667 }
00668
00669
00670
00671
00672
00673 void DBObjectNode::getXML(XMLStreamConsumer* p_pXMLBufOut)
00674 {
00675
00676 DBObjectField* l_pDBObjectField;
00677 unsigned int i;
00678
00679
00680 DEBUG_FUNC(DBObjectNode::getXML)
00681
00682 (*p_pXMLBufOut) << "\n<" << m_pszName << " " ;
00683
00684 if (m_intAction==DBOBJaction_Delete) (*p_pXMLBufOut) << "map_status='delete' " ;
00685 if (m_intAction==DBOBJaction_Insert) (*p_pXMLBufOut) << "map_status='insert' " ;
00686 if (m_intAction==DBOBJaction_Update) (*p_pXMLBufOut) << "map_status='update' " ;
00687
00688 for( i=0 ; i < getFieldsCount() ; i++)
00689 {
00690 l_pDBObjectField = this->getField(i);
00691 if(l_pDBObjectField->isAttribute()) l_pDBObjectField->getXML(p_pXMLBufOut);
00692 }
00693
00694 (*p_pXMLBufOut) << ">\n";
00695
00696 for( i=0 ; i < getFieldsCount() ; i++)
00697 {
00698 l_pDBObjectField = this->getField(i);
00699 if(! l_pDBObjectField->isAttribute()) l_pDBObjectField->getXML(p_pXMLBufOut);
00700 }
00701
00702 for( i=0 ; i < getChildNodesCount() ; i++)
00703 {
00704 getChildNode(i)->getXML(p_pXMLBufOut);
00705 }
00706
00707 (*p_pXMLBufOut) << "</" << m_pszName << ">\n";
00708
00709 }
00710
00711
00712
00713
00714 DBObject* DBObjectNode::selectSingleNode(const char* p_pszPath)
00715 {
00716
00717 char* l_pszSelPath;
00718 char* l_pszNextPath;
00719 DBObject* l_pSelOBJ = 0;
00720 DBObjectNode* l_pChild = 0;
00721
00722
00723 DEBUG_FUNC(DBObjectNode::selectSingleNode)
00724
00725 DEBUG_ECHO << m_pszName << ":" << p_pszPath << "\n";
00726
00727
00728 if( strlen(p_pszPath) == 0 ) return (DBObject*) this;
00729
00730 l_pszSelPath = copyCharBuffer( p_pszPath);
00731 l_pszNextPath = strchr(l_pszSelPath, DBOBJECTNODE_SELREQSEP);
00732 if(! l_pszNextPath)
00733 {
00734
00735
00736
00737 l_pSelOBJ = (DBObject*) getField(p_pszPath);
00738 }
00739 else
00740 {
00741 l_pszNextPath[0]='\0';
00742 l_pszNextPath ++;
00743 DEBUG_ECHO << l_pszSelPath << "!" << l_pszNextPath << "\n";
00744
00745
00746 if( strcmp( l_pszSelPath, DBOBJECTNODE_SELF) == 0) l_pSelOBJ = (DBObject*) selectSingleNode( l_pszNextPath);
00747
00748 if( strcmp( l_pszSelPath, DBOBJECTNODE_PARENT) == 0) l_pSelOBJ = (DBObject*) m_pParentNode->selectSingleNode( l_pszNextPath);
00749
00750 if(!l_pSelOBJ)
00751 {
00752 l_pChild=getChildNode( l_pszSelPath);
00753 if(l_pChild) l_pSelOBJ = (DBObject*) l_pChild->selectSingleNode( l_pszNextPath);
00754 else l_pSelOBJ = 0;
00755 }
00756 }
00757 releaseCharBuffer( l_pszSelPath);
00758 return l_pSelOBJ;
00759 }
00760
00761
00762
00763
00764
00765
00766 char* DBObjectNode::calculateRelValue( const char* p_pszExpr)
00767 {
00768 if(! m_pXpathValuer) m_pXpathValuer = (XpathDBValuer*) getValuable()->getValuer( XPATHVALUER_TAG);
00769
00770 m_pXpathValuer->setRoot( this);
00771
00772 return getValuable()->calculateValue( p_pszExpr);
00773 }
00774
00775
00776
00777
00778
00779
00780
00781 void DBObjectNode::deleteTree()
00782 {
00783
00784 DEBUG_IN(DBObjectNode::deleteTree)
00785
00786
00787 while(! m_vaFields.empty()) delete m_vaFields.pop();
00788
00789
00790 while( ! m_vaChildren.empty()) delete m_vaChildren.pop();
00791
00792 DEBUG_OUT(DBObjectNode::deleteTree)
00793 }
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808 void DBObjectSAXBuilder::buildDBObject(XMLFlowContext* p_pContext, XMLStreamProvider* p_pInput, const DBOBJDefinitionNode* p_pDBOBJDefNode, DBOBJSetAction l_intBaseAction)
00809 {
00810
00811 DBObjectSAXBuilder* l_pDBObjectSAXBuilder=0;
00812 StreamSAX2Parser* l_pStreamParser=0;
00813 XDFLSaxErrorReporter* l_pErrReporter=0;
00814
00815
00816 DEBUG_IN(DBObjectSAXBuilder::buildDBObject);
00817 PREP_CATCH_XML_FLOW_ERROR;
00818
00819 WATCH_XML_FLOW_ERROR {
00820
00821
00822 l_pDBObjectSAXBuilder=new DBObjectSAXBuilder(p_pContext, p_pDBOBJDefNode, l_intBaseAction);
00823 l_pErrReporter= new XDFLSaxErrorReporter("DBObjectSAXBuilder::buildDBObject");
00824
00825
00826 l_pStreamParser = new StreamSAX2Parser(l_pDBObjectSAXBuilder, l_pErrReporter);
00827
00828
00829 (*p_pInput) >> (*l_pStreamParser);
00830 l_pStreamParser->commitStream(true);
00831
00832
00833 } CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN;
00834
00835 RELEASE_AND_RETURN:
00836
00837 delete l_pStreamParser;
00838 delete l_pErrReporter;
00839 delete l_pDBObjectSAXBuilder;
00840
00841 DEBUG_OUT(DBObjectSAXBuilder::buildDBObject);
00842 ON_XML_FLOW_ERROR_THROW;
00843 }
00844
00845
00846
00847
00848
00849
00850 DBObjectSAXBuilder::DBObjectSAXBuilder(XMLFlowContext* p_pContext, const DBOBJDefinitionNode* p_pDBOBJDefNode,DBOBJSetAction l_intBaseAction)
00851 {
00852 m_intBaseAction = l_intBaseAction;
00853 m_pSAXDB_objectDef=p_pDBOBJDefNode;
00854 m_pSAXDB_curFieldDef=0;
00855 m_pszCurFieldName = 0;
00856 m_pszCurFieldValue = 0;
00857 m_pContext = p_pContext;
00858 DEBUG_CREATE(DBObjectSAXBuilder)
00859 }
00860
00861
00862
00863
00864 DBObjectSAXBuilder::~DBObjectSAXBuilder()
00865 {
00866 DEBUG_DEL(DBObjectSAXBuilder)
00867
00868 m_pszCurFieldName = releaseCharBuffer( m_pszCurFieldName);
00869 m_pszCurFieldValue = releaseCharBuffer( m_pszCurFieldValue);
00870
00871 while(!m_vaNodes.empty()) delete m_vaNodes.pop();
00872 while(!m_vaObjects.empty()) delete m_vaObjects.pop();
00873
00874 }
00875
00876
00877
00878
00879
00880
00881
00882 void DBObjectSAXBuilder::startElement( const XMLCh* const uri,
00883 const XMLCh* const localname,
00884 const XMLCh* const qname,
00885 const Attributes& attrs)
00886 {
00887
00888 const DBOBJDefinitionNode* l_pSAXDB_nodeDef=0;
00889 const DBOBJDefinitionField* l_pDBObjectFieldDef=0;
00890 DBObjectNode* l_pSAXDB_node=0;
00891 DBObjectField* l_pDBObjectField=0;
00892 char l_szTagName[XMLPROCESSOR_MAX_TAG_SIZE];
00893 char l_szAttrName[XMLPROCESSOR_MAX_ATTRNAME_SIZE];
00894 char l_szAttrValue[XMLPROCESSOR_MAX_ATTRVAL_SIZE];
00895 DBOBJSetAction l_intAction;
00896 unsigned int l_uiAttrsCount;
00897 bool l_fRoot;
00898 bool l_fNode;
00899 unsigned int i;
00900
00901
00902 DEBUG_IN(DBObjectSAXBuilder::startElement);
00903 PREP_CATCH_XML_FLOW_ERROR;
00904
00905 WATCH_XML_FLOW_ERROR {
00906
00907 XSTR(m_pContext->getTranscoder(), localname, (char*) &l_szTagName);
00908
00909 DEBUG_ECHO << (char*) &l_szTagName << "\n";
00910
00911
00912 if( m_vaNodes.empty() )
00913 {
00914
00915 l_fRoot = true;
00916
00917 if( strcmp( m_pSAXDB_objectDef->getName(), (char*) &l_szTagName) == 0 )
00918 {
00919 l_fNode = true;
00920 l_pSAXDB_nodeDef = m_pSAXDB_objectDef;
00921
00922 }
00923 else
00924 {
00925 l_fNode = false;
00926 l_pSAXDB_nodeDef = 0;
00927 }
00928 }
00929 else
00930 {
00931
00932 l_fRoot = false;
00933 l_fNode = true;
00934 l_pSAXDB_nodeDef = m_vaNodes.top()->getDefinition()->getChildNode( (char*) &l_szTagName);
00935
00936 if(!l_pSAXDB_nodeDef)
00937 {
00938 l_fNode = false;
00939 l_pDBObjectFieldDef = m_vaNodes.top()->getDefinition()->getField( (char*) &l_szTagName);
00940
00941
00942
00943
00944 DEBUG_ECHO << "(field)" << "\n";
00945 }
00946 }
00947
00948
00949 if(l_fNode)
00950 {
00951 if(l_pSAXDB_nodeDef)
00952 {
00953 l_pSAXDB_node = new DBObjectNode( l_pSAXDB_nodeDef);
00954
00955
00956 SAX_getAttrValue(attrs,DBOBJECTNODE_ACTION,"", (char*)&l_szAttrValue);
00957 l_intAction = translateAction( (char*) &l_szAttrValue);
00958
00959
00960 if(l_fRoot) l_intAction=calcAction( l_intAction, m_intBaseAction );
00961 else l_intAction=calcAction( l_intAction, m_vaNodes.top()->getAction());
00962
00963 l_pSAXDB_node->setAction(l_intAction);
00964
00965
00966 l_uiAttrsCount = attrs.getLength();
00967 for (i=0 ; i< l_uiAttrsCount ; i++)
00968 {
00969 XSTR(m_pContext->getTranscoder(), attrs.getLocalName( i), (char*)(&l_szAttrName)+1);
00970 XSTR(m_pContext->getTranscoder(), attrs.getValue( i), (char*)&l_szAttrValue);
00971
00972 if( ( strcmp( ((char*)&l_szAttrName)+1, DBOBJECTNODE_ACTION) != 0 ) && (strcmp( ((char*)&l_szAttrName)+1,"map_status")!=0) )
00973 {
00974 l_szAttrName[0] = DBOBJDEFFIELD_ATTR;
00975 DEBUG_ECHO << (char*) &l_szAttrName << "=" << (char*) &l_szAttrValue << "\n";
00976
00977 l_pDBObjectFieldDef = l_pSAXDB_nodeDef->getField( (char*) &l_szAttrName );
00978 if(l_pDBObjectFieldDef)
00979 {
00980
00981 l_pDBObjectField = new DBObjectField( l_pDBObjectFieldDef);
00982 }
00983 else
00984 {
00985 l_pDBObjectField = new DBObjectField( l_szAttrName);
00986 }
00987 l_pDBObjectField->setValue( (char*) &l_szAttrValue);
00988 l_pSAXDB_node->addField( l_pDBObjectField );
00989 }
00990 }
00991
00992
00993 m_vaNodes.push(l_pSAXDB_node);
00994 }
00995 }
00996
00997
00998 if( !l_fNode && !l_fRoot)
00999 {
01000 if(l_pDBObjectFieldDef)
01001 {
01002 m_pszCurFieldName = releaseCharBuffer( m_pszCurFieldName);
01003 m_pSAXDB_curFieldDef=l_pDBObjectFieldDef;
01004 }
01005 else
01006 {
01007 m_pszCurFieldName = copyCharBuffer( l_szTagName);
01008 l_pDBObjectFieldDef = 0;
01009 }
01010 m_pszCurFieldValue = releaseCharBuffer( m_pszCurFieldValue);
01011 }
01012
01013
01014 if( !l_fNode && l_fRoot)
01015 {
01016 m_pSAXDB_curFieldDef=0;
01017 }
01018
01019 } CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN;
01020
01021 RELEASE_AND_RETURN:
01022
01023
01024 DEBUG_OUT(DBObjectSAXBuilder::startElement)
01025 ON_XML_FLOW_ERROR_THROW;
01026 }
01027
01028
01029
01030
01031 void DBObjectSAXBuilder::endElement( const XMLCh* const uri,
01032 const XMLCh* const localname,
01033 const XMLCh* const qname)
01034 {
01035
01036 DBObjectNode* l_pSAXDB_node;
01037 DBObjectField* l_pDBObjectField;
01038 char l_szTagName[XMLPROCESSOR_MAX_TAG_SIZE];
01039
01040
01041 DEBUG_IN(DBObjectSAXBuilder::endElement)
01042 PREP_CATCH_XML_FLOW_ERROR;
01043
01044 WATCH_XML_FLOW_ERROR {
01045
01046 XSTR(m_pContext->getTranscoder(), localname, (char*) &l_szTagName);
01047
01048 DEBUG_ECHO << l_szTagName << "\n";
01049
01050 if( m_pSAXDB_curFieldDef || m_pszCurFieldName)
01051 {
01052
01053 DEBUG_ECHO << l_szTagName << "=" << m_pszCurFieldValue << "\n";
01054
01055 if(m_pSAXDB_curFieldDef) l_pDBObjectField = new DBObjectField( m_pSAXDB_curFieldDef);
01056 else l_pDBObjectField = new DBObjectField( m_pszCurFieldName);
01057 l_pDBObjectField->setValue( m_pszCurFieldValue);
01058
01059 m_vaNodes.top()->addField( l_pDBObjectField );
01060 m_pSAXDB_curFieldDef=0;
01061 m_pszCurFieldName = releaseCharBuffer( m_pszCurFieldName);
01062 m_pszCurFieldValue=releaseCharBuffer( m_pszCurFieldValue);
01063 }
01064 else
01065 {
01066
01067 if(! m_vaNodes.empty())
01068 {
01069 l_pSAXDB_node=m_vaNodes.top();
01070 if( strcmp( l_pSAXDB_node->getName(), (char*) &l_szTagName) == 0)
01071 {
01072 m_vaNodes.pop();
01073 if(! m_vaNodes.empty())
01074 {
01075 m_vaNodes.top()->addChildNode( l_pSAXDB_node);
01076 }
01077 else
01078 {
01079
01080 logout << ".";
01081 m_vaObjects.push( l_pSAXDB_node);
01082 }
01083 }
01084 }
01085 }
01086
01087 } CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN;
01088
01089 RELEASE_AND_RETURN:
01090
01091 DEBUG_OUT(DBObjectSAXBuilder::endElement)
01092 ON_XML_FLOW_ERROR_THROW;
01093 }
01094
01095
01096
01097
01098 void DBObjectSAXBuilder::characters(const XMLCh* const chars ,
01099 const unsigned int length)
01100 {
01101
01102 char* l_pszChars = 0;
01103 char* l_pszTrimmedChars = 0;
01104
01105
01106 DEBUG_IN(DBObjectSAXBuilder::characters)
01107 PREP_CATCH_XML_FLOW_ERROR;
01108
01109 WATCH_XML_FLOW_ERROR {
01110
01111
01112 if( m_pSAXDB_curFieldDef || m_pszCurFieldName )
01113 {
01114 l_pszChars= XSTR(m_pContext->getTranscoder(), chars, length);
01115 l_pszTrimmedChars = trimCharBuffer( l_pszChars);
01116 l_pszChars = releaseCharBuffer( l_pszChars);
01117
01118 m_pszCurFieldValue = concatCharBuffer( m_pszCurFieldValue, l_pszTrimmedChars);
01119 }
01120
01121 } CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN;
01122
01123 RELEASE_AND_RETURN:
01124
01125 l_pszChars = releaseCharBuffer( l_pszChars);
01126 l_pszTrimmedChars = releaseCharBuffer( l_pszTrimmedChars);
01127
01128 DEBUG_OUT(DBObjectSAXBuilder::characters)
01129 ON_XML_FLOW_ERROR_THROW;
01130
01131 }
01132
01133
01134
01135
01136 DBOBJSetAction DBObjectSAXBuilder::translateAction(const char* p_pszAction)
01137 {
01138
01139 DBOBJSetAction l_intAction;
01140
01141
01142 DEBUG_FUNC(DBOBJSetRequest::translateAction)
01143
01144 l_intAction = DBOBJaction_Unspec;
01145 if( strcmp( p_pszAction, DBOBJECTNODE_ACTIONNONE) == 0) l_intAction = DBOBJaction_None;
01146 if( strcmp( p_pszAction, DBOBJECTNODE_ACTIONINSERT) == 0) l_intAction = DBOBJaction_Insert;
01147 if( strcmp( p_pszAction, DBOBJECTNODE_ACTIONUPDATE) == 0) l_intAction = DBOBJaction_Update;
01148 if( strcmp( p_pszAction, DBOBJECTNODE_ACTIONDELETE) == 0) l_intAction = DBOBJaction_Delete;
01149
01150 return l_intAction;
01151 }
01152
01153
01154
01155
01156
01157 char* DBObjectSAXBuilder::translateAction(DBOBJSetAction p_Action)
01158 {
01159
01160 const char* l_pszAction;
01161
01162
01163 DEBUG_FUNC(DBOBJSetRequest::translateAction)
01164
01165 l_pszAction = "";
01166 if( p_Action == DBOBJaction_None ) l_pszAction = DBOBJECTNODE_ACTIONNONE;
01167 if( p_Action == DBOBJaction_Insert ) l_pszAction = DBOBJECTNODE_ACTIONINSERT;
01168 if( p_Action == DBOBJaction_Update ) l_pszAction = DBOBJECTNODE_ACTIONUPDATE;
01169 if( p_Action == DBOBJaction_Delete ) l_pszAction = DBOBJECTNODE_ACTIONDELETE;
01170
01171 return copyCharBuffer( l_pszAction);
01172 }
01173
01174
01175
01176
01177
01178
01179
01180 unsigned int DBObjectSAXBuilder::getObjectsCount()
01181 {
01182 return m_vaObjects.size();
01183 }
01184
01185
01186
01187
01188 DBObjectNode* DBObjectSAXBuilder::popObject()
01189 {
01190 DBObjectNode* l_pDBObjectNode;
01191 l_pDBObjectNode= m_vaObjects.bottom();
01192 m_vaObjects.remove((unsigned int)0);
01193 return l_pDBObjectNode;
01194 }
01195
01196
01197
01198
01199 DBOBJSetAction DBObjectSAXBuilder::calcAction( DBOBJSetAction p_intCurAction, DBOBJSetAction p_intParentAction)
01200 {
01201 DEBUG_FUNC(DBOBJSetRequest::getNodeAction)
01202
01203 if (p_intCurAction==DBOBJaction_Unspec) return p_intParentAction;
01204 if (p_intCurAction==DBOBJaction_None) return DBOBJaction_None;
01205 else{
01206 switch(p_intParentAction)
01207 {
01208 case DBOBJaction_Unspec:
01209 return p_intCurAction;
01210 break;
01211
01212 case DBOBJaction_None:
01213 return p_intCurAction;
01214 break;
01215
01216 case DBOBJaction_Insert:
01217 if ( p_intCurAction==DBOBJaction_Delete ) return DBOBJaction_None;
01218 else return DBOBJaction_Insert;
01219 break;
01220
01221 case DBOBJaction_Update:
01222 return p_intCurAction;
01223 break;
01224
01225 case DBOBJaction_Delete:
01226 if ( p_intCurAction==DBOBJaction_Insert ) return DBOBJaction_None;
01227 else return DBOBJaction_Delete;
01228 break;
01229 }
01230 }
01231
01232 return DBOBJaction_Unspec;
01233 }
01234
01235
01236
01237
01238
01239
01240 END_XDFLENGINE_NS
01241
01242
01243
01244
01245