00001 #if !defined(_DBOBJECT_HPP) 00002 #define _DBOBJECT_HPP 00003 //============================================================================= 00004 // 00005 // XDFLengine library 00006 // 00007 //----------------------------------------------------------------------------- 00008 // DBOBJECT.HPP 00009 //----------------------------------------------------------------------------- 00014 //_____________________________________________________________________________ 00015 // 00016 // Copyright (C) 2003 Guillaume Baurand. All Rights Reserved. 00017 // 00018 // This file is part of the XDFLengine project. 00019 // 00020 // The XDFLengine is free software; you can redistribute it and/or modify 00021 // it under the terms of the GNU General Public License as published by 00022 // the Free Software Foundation; either version 2 of the License, or 00023 // (at your option) any later version. 00024 // 00025 // This program is distributed in the hope that it will be useful, 00026 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00027 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00028 // GNU General Public License for more details. 00029 // 00030 // You should have received a copy of the GNU General Public License 00031 // along with this program; if not, write to the Free Software 00032 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00033 // USA. 00034 // 00035 // For more information, 00036 // contact : guillaume@baurand.net 00037 // or visit : http://xdflengine.sourceforge.net 00038 // 00039 //============================================================================= 00040 00041 # include "config/commonincs.hpp" 00042 # include "valuers/xmlvaluable.hpp" 00043 # include "processor/xmlflowcontext.hpp" 00044 # include "streamers/db/dbobject/dbobjdefinition.hpp" 00045 00046 BEGIN_XDFLENGINE_NS 00047 00048 class DBObjectNode; 00049 class XpathDBValuer; 00050 00051 enum DBOBJSetAction{DBOBJaction_Unspec, DBOBJaction_None, DBOBJaction_Insert, DBOBJaction_Update, DBOBJaction_Delete, DBOBJaction_CheckPre, DBOBJaction_CheckPost}; 00052 00053 //============================================================================= 00054 // CLASS DBOBJECT 00055 //----------------------------------------------------------------------------- 00057 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00058 class XDFLENGINE_EXPORT DBObject 00059 { 00060 public: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00061 00062 //_____________________________________________________________________ 00063 // getType 00064 //--------------------------------------------------------------------- 00069 //_____________________________________________________________________ 00070 virtual int getType() const=0; 00071 }; 00072 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00073 //============================================================================= 00074 00075 00076 00077 //============================================================================= 00078 // CLASS DBOBJECTFIELD 00079 //----------------------------------------------------------------------------- 00081 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00082 class XDFLENGINE_EXPORT DBObjectField:public DBObject 00083 { 00084 00085 private: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00086 00087 char* m_pszName; 00088 char* m_pszValue; 00089 bool m_fAttribute; 00090 bool m_fCalculated; 00091 const DBOBJDefinitionField* m_pSAXDB_FieldDefinition; 00092 DBObjectNode* m_DBOBJParentNode; 00093 00094 00095 public: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00096 00097 // CONSTRUCTOR & DESTRUCTOR 00098 00099 //_____________________________________________________________________ 00100 // DBOBJECTFIELD 00101 //--------------------------------------------------------------------- 00104 //_____________________________________________________________________ 00105 DBObjectField( const char* p_pszName); 00106 00107 //_____________________________________________________________________ 00108 // DBOBJECTFIELD 00109 //--------------------------------------------------------------------- 00112 //_____________________________________________________________________ 00113 DBObjectField( const DBOBJDefinitionField* p_pDBObjectFieldDef); 00114 00115 //_____________________________________________________________________ 00116 // ~DBOBJECTFIELD 00117 //--------------------------------------------------------------------- 00119 //_____________________________________________________________________ 00120 ~DBObjectField(); 00121 00122 00123 // GETTERS 00124 00125 //_____________________________________________________________________ 00126 // GETNAME 00127 //--------------------------------------------------------------------- 00130 //_____________________________________________________________________ 00131 const char* getName() const; 00132 00133 //_____________________________________________________________________ 00134 // GETVALUE 00135 //--------------------------------------------------------------------- 00138 //_____________________________________________________________________ 00139 const char* getValue(); 00140 00141 //_____________________________________________________________________ 00142 // ISATTRIBUTE 00143 //--------------------------------------------------------------------- 00146 //_____________________________________________________________________ 00147 bool isAttribute() const; 00148 00149 //_____________________________________________________________________ 00150 // GETDEFINITION 00151 //--------------------------------------------------------------------- 00154 //_____________________________________________________________________ 00155 const DBOBJDefinitionField* getDefinition() const; 00156 00157 // SETTERS 00158 00159 //_____________________________________________________________________ 00160 // SETNAME 00161 //--------------------------------------------------------------------- 00164 //_____________________________________________________________________ 00165 void setName( const char* p_pszName); 00166 00167 //_____________________________________________________________________ 00168 // SETATTRIBUTE 00169 //--------------------------------------------------------------------- 00172 //_____________________________________________________________________ 00173 void setAttribute( bool p_fAttribute); 00174 00175 //_____________________________________________________________________ 00176 // SETVALUE 00177 //--------------------------------------------------------------------- 00180 //_____________________________________________________________________ 00181 void setValue( const char* p_pszFieldValue); 00182 00183 //_____________________________________________________________________ 00184 // SETPARENT 00185 //--------------------------------------------------------------------- 00188 //_____________________________________________________________________ 00189 void setParent( DBObjectNode* p_DBOBJParentNode); 00190 00191 //_____________________________________________________________________ 00192 // SETDEFINITION 00193 //--------------------------------------------------------------------- 00196 //_____________________________________________________________________ 00197 void setDefinition( const DBOBJDefinitionField* p_pDBObjectFieldDef); 00198 00199 // FUNCTIONNALITIES 00200 00201 //_____________________________________________________________________ 00202 // GETXML 00203 //--------------------------------------------------------------------- 00206 //_____________________________________________________________________ 00207 void getXML(XMLStreamConsumer* p_pXMLBufOut); 00208 00209 // DBOBJECT //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00210 00211 //_____________________________________________________________________ 00212 // GETTYPE 00213 //--------------------------------------------------------------------- 00218 //_____________________________________________________________________ 00219 int getType() const; 00220 }; 00221 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00222 //============================================================================= 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 //============================================================================= 00233 // CLASS DBOBJECTNODE 00234 //----------------------------------------------------------------------------- 00236 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00237 class XDFLENGINE_EXPORT DBObjectNode:public DBObject 00238 { 00239 00240 00241 private: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00242 00243 char* m_pszName; 00244 DBOBJSetAction m_intAction; 00245 const DBOBJDefinitionNode* m_pDBObjectNodeDefinition; 00246 DBObjectNode* m_pParentNode; 00247 VAarray<DBObjectNode*> m_vaChildren; 00248 VAarray<DBObjectField*> m_vaFields; 00249 XMLValuable* m_pValuableParent; 00250 XpathDBValuer* m_pXpathValuer; 00251 00252 public: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00253 00254 // CONSTRUCTOR & DESTRUCTOR 00255 00256 //_____________________________________________________________________ 00257 // ~DBOBJECTNODE 00258 //--------------------------------------------------------------------- 00262 //_____________________________________________________________________ 00263 DBObjectNode( const DBOBJDefinitionNode* p_pDBOBJDefNode); 00264 00265 //_____________________________________________________________________ 00266 // ~DBOBJECTNODE 00267 //--------------------------------------------------------------------- 00271 //_____________________________________________________________________ 00272 ~DBObjectNode(); 00273 00274 // GETTERS 00275 00276 //_____________________________________________________________________ 00277 // GETNAME 00278 //--------------------------------------------------------------------- 00281 //_____________________________________________________________________ 00282 const char* getName() const; 00283 00284 //_____________________________________________________________________ 00285 // GETACTION 00286 //--------------------------------------------------------------------- 00289 //_____________________________________________________________________ 00290 DBOBJSetAction getAction() const; 00291 00292 //_____________________________________________________________________ 00293 // GETPARENT 00294 //--------------------------------------------------------------------- 00297 //_____________________________________________________________________ 00298 DBObjectNode* getParent() const; 00299 00300 //_____________________________________________________________________ 00301 // GETDEFINITION 00302 //--------------------------------------------------------------------- 00305 //_____________________________________________________________________ 00306 const DBOBJDefinitionNode* getDefinition() const; 00307 00308 00309 00310 // SETTERS 00311 00312 //_____________________________________________________________________ 00313 // SETACTION 00314 //--------------------------------------------------------------------- 00317 //_____________________________________________________________________ 00318 void setAction( DBOBJSetAction p_intAction); 00319 00320 //_____________________________________________________________________ 00321 // SETPARENT 00322 //--------------------------------------------------------------------- 00325 //_____________________________________________________________________ 00326 void setParent( DBObjectNode* p_DBOBJParentNode); 00327 00328 //_____________________________________________________________________ 00329 // SETDEFINITION 00330 //--------------------------------------------------------------------- 00333 //_____________________________________________________________________ 00334 void setDefinition( const DBOBJDefinitionNode* p_pDBOBJDefNode); 00335 00336 //_____________________________________________________________________ 00337 // SETVALUABLE 00338 //--------------------------------------------------------------------- 00341 //_____________________________________________________________________ 00342 void setValuable( XMLValuable* p_pValuableParent); 00343 00344 // CHILD NODES ACCESSORS AND BUILDERS 00345 00346 //_____________________________________________________________________ 00347 // ADDCHILDNODE 00348 //--------------------------------------------------------------------- 00351 //_____________________________________________________________________ 00352 void addChildNode( DBObjectNode* p_pChildNode); 00353 00354 //_____________________________________________________________________ 00355 // REMOVECHILDNODE 00356 //--------------------------------------------------------------------- 00360 //_____________________________________________________________________ 00361 void removeChildNode( unsigned int p_uiIndex, bool p_fDestroy=true); 00362 00363 //_____________________________________________________________________ 00364 // REMOVECHILDNODE 00365 //--------------------------------------------------------------------- 00370 //_____________________________________________________________________ 00371 void removeChildNode( const char* p_pszName, unsigned int p_uiIndex=0, bool p_fDestroy=true); 00372 00373 //_____________________________________________________________________ 00374 // GETCHILDNODESCOUNT 00375 //--------------------------------------------------------------------- 00378 //_____________________________________________________________________ 00379 unsigned int getChildNodesCount() const; 00380 00381 //_____________________________________________________________________ 00382 // GETCHILDNODESCOUNT 00383 //--------------------------------------------------------------------- 00387 //_____________________________________________________________________ 00388 unsigned int getChildNodesCount( const char* p_pszName) const; 00389 00390 //_____________________________________________________________________ 00391 // GETCHILDNODE 00392 //--------------------------------------------------------------------- 00396 //_____________________________________________________________________ 00397 DBObjectNode* getChildNode( unsigned int p_uiIndex) const; 00398 00399 //_____________________________________________________________________ 00400 // GETCHILDNODE 00401 //--------------------------------------------------------------------- 00406 //_____________________________________________________________________ 00407 DBObjectNode* getChildNode( const char* p_pszName, unsigned int p_uiIndex=0) const; 00408 00409 00410 //_____________________________________________________________________ 00411 // GETCURRENTFIELD 00412 //--------------------------------------------------------------------- 00413 DBObjectNode* getCurrentChild(); 00414 00415 //_____________________________________________________________________ 00416 // MOVEPREVIOUSFIELD 00417 //--------------------------------------------------------------------- 00418 void movePreviousChild(); 00419 00420 //_____________________________________________________________________ 00421 // MOVENEXTFIELD 00422 //--------------------------------------------------------------------- 00423 void moveNextChild(); 00424 00425 //_____________________________________________________________________ 00426 // moveFirstChild 00427 //--------------------------------------------------------------------- 00428 void moveFirstChild(); 00429 00430 //_____________________________________________________________________ 00431 // moveLastChild 00432 //--------------------------------------------------------------------- 00433 void moveLastChild(); 00434 00435 00436 // FIELDS ACCESSORS AND BUILDERS 00437 00438 //_____________________________________________________________________ 00439 // ADDFIELD 00440 //--------------------------------------------------------------------- 00443 //_____________________________________________________________________ 00444 void addField(DBObjectField* p_pField); 00445 00446 //_____________________________________________________________________ 00447 // REMOVEFIELD 00448 //--------------------------------------------------------------------- 00452 //_____________________________________________________________________ 00453 void removeField( unsigned int p_uiIndex, bool p_fDestroy=true); 00454 00455 //_____________________________________________________________________ 00456 // REMOVEFIELD 00457 //--------------------------------------------------------------------- 00461 //_____________________________________________________________________ 00462 void removeField( const char* p_pszName, bool p_fDestroy=true); 00463 00464 //_____________________________________________________________________ 00465 // GETFIELDSCOUNT 00466 //--------------------------------------------------------------------- 00469 //_____________________________________________________________________ 00470 unsigned int getFieldsCount() const; 00471 00472 //_____________________________________________________________________ 00473 // GETFIELD 00474 //--------------------------------------------------------------------- 00478 //_____________________________________________________________________ 00479 DBObjectField* getField( unsigned int p_uiIndex) const; 00480 00481 //_____________________________________________________________________ 00482 // GETFIELD 00483 //--------------------------------------------------------------------- 00487 //_____________________________________________________________________ 00488 DBObjectField* getField( const char* p_pszName) const; 00489 00490 //_____________________________________________________________________ 00491 // GETCURRENTFIELD 00492 //--------------------------------------------------------------------- 00493 DBObjectField* getCurrentField(); 00494 00495 //_____________________________________________________________________ 00496 // MOVEPREVIOUSFIELD 00497 //--------------------------------------------------------------------- 00498 void movePreviousField(); 00499 00500 //_____________________________________________________________________ 00501 // MOVENEXTFIELD 00502 //--------------------------------------------------------------------- 00503 void moveNextField(); 00504 00505 //_____________________________________________________________________ 00506 // moveFirstField 00507 //--------------------------------------------------------------------- 00508 void moveFirstField(); 00509 00510 //_____________________________________________________________________ 00511 // moveLastChild 00512 //--------------------------------------------------------------------- 00513 void moveLastField(); 00514 00515 // FUNCTIONNALITIES 00516 00517 //_____________________________________________________________________ 00518 // GETXML 00519 //--------------------------------------------------------------------- 00523 //_____________________________________________________________________ 00524 void getXML(XMLStreamConsumer* p_pXMLBufOut); 00525 00526 //_____________________________________________________________________ 00527 // SELECTSINGLENODE 00528 //--------------------------------------------------------------------- 00531 //_____________________________________________________________________ 00532 DBObject* selectSingleNode(const char* p_pszPath); 00533 00534 //_____________________________________________________________________ 00535 // GETVALUABLE 00536 //--------------------------------------------------------------------- 00539 //_____________________________________________________________________ 00540 XMLValuable* getValuable(); 00541 00542 00543 //_____________________________________________________________________ 00544 // GETVALUABLE 00545 //--------------------------------------------------------------------- 00546 char* calculateRelValue( const char* p_pszExpr); 00547 00548 // DBOBJECT INTERFACE 00549 00550 //_____________________________________________________________________ 00551 // ~getType 00552 //--------------------------------------------------------------------- 00557 //_____________________________________________________________________ 00558 int getType() const; 00559 00560 private: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00561 00562 //_____________________________________________________________________ 00563 // ~deleteTree 00564 //--------------------------------------------------------------------- 00566 //_____________________________________________________________________ 00567 void deleteTree(); 00568 00569 00570 00571 00572 }; 00573 //============================================================================= 00574 00575 00576 00577 00578 //============================================================================= 00579 // CLASS DBOBJECTSAXBUILDER 00580 //----------------------------------------------------------------------------- 00582 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00583 class XDFLENGINE_EXPORT DBObjectSAXBuilder : public ContentHandler 00584 { 00585 00586 private: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00587 00588 VAarray< DBObjectNode* > m_vaNodes; 00589 VAarray< DBObjectNode* > m_vaObjects; 00590 const DBOBJDefinitionNode* m_pSAXDB_objectDef; 00591 const DBOBJDefinitionField* m_pSAXDB_curFieldDef; 00592 char* m_pszCurFieldName; 00593 char* m_pszCurFieldValue; 00594 DBOBJSetAction m_intBaseAction; 00595 XMLFlowContext* m_pContext; // Parsing context 00596 00597 00598 public: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00599 00600 00601 // STATICS 00602 00603 //_____________________________________________________________________ 00604 // BUILDDBOBJECT 00605 //--------------------------------------------------------------------- 00610 //_____________________________________________________________________ 00611 static void buildDBObject(XMLFlowContext* p_pContext, XMLStreamProvider* p_pInput, const DBOBJDefinitionNode* p_pDBOBJDefNode,DBOBJSetAction l_intBaseAction); 00612 00613 // CONSTRUCTOR & DESTRUCTOR 00614 00615 //_____________________________________________________________________ 00616 // DBOBJECTSAXBUILDER 00617 //--------------------------------------------------------------------- 00620 //_____________________________________________________________________ 00621 DBObjectSAXBuilder (XMLFlowContext* p_pContext, const DBOBJDefinitionNode* p_pDBOBJDefNode,DBOBJSetAction l_intBaseAction); 00622 00623 //_____________________________________________________________________ 00624 // ~DBOBJECTSAXBUILDER 00625 //--------------------------------------------------------------------- 00628 //_____________________________________________________________________ 00629 ~DBObjectSAXBuilder (); 00630 00631 00632 // CONTENTHANDLER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00633 00634 //____________________________________________________________________ 00635 // STARTELEMENT 00636 //-------------------------------------------------------------------- 00645 //_____________________________________________________________________ 00646 void startElement( const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs); 00647 00648 //____________________________________________________________________ 00649 // CHARACTERS 00650 //-------------------------------------------------------------------- 00656 //_____________________________________________________________________ 00657 void characters( const XMLCh* const chars, const unsigned int length); 00658 00659 //____________________________________________________________________ 00660 // ENDELEMENT 00661 //-------------------------------------------------------------------- 00669 //_____________________________________________________________________ 00670 void endElement ( const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname); 00671 00672 // Non implemented : 00673 void startDocument (){}; 00674 void endDocument (){}; 00675 void startPrefixMapping ( const XMLCh* const prefix,const XMLCh* const uri){}; 00676 void endPrefixMapping ( const XMLCh* const prefix){}; 00677 void processingInstruction ( const XMLCh* const target, const XMLCh* const data){}; 00678 void ignorableWhitespace ( const XMLCh* const chars, const unsigned int length){}; 00679 void setDocumentLocator ( const Locator* const locator) {}; 00680 void skippedEntity ( const XMLCh* const name){}; 00681 00682 //_____________________________________________________________________ 00683 // TRANSLATEACTION 00684 //--------------------------------------------------------------------- 00688 //_____________________________________________________________________ 00689 static DBOBJSetAction translateAction( const char* p_pszAction); 00690 00691 //_____________________________________________________________________ 00692 // TRANSLATEACTION 00693 //--------------------------------------------------------------------- 00697 //_____________________________________________________________________ 00698 static char* translateAction( DBOBJSetAction p_Action); 00699 00700 // PRODUCED OBJECTS 00701 00702 //_____________________________________________________________________ 00703 // GETOBJECTCOUNT 00704 //--------------------------------------------------------------------- 00705 unsigned int getObjectsCount(); 00706 00707 //_____________________________________________________________________ 00708 // POPOBJECT 00709 //--------------------------------------------------------------------- 00710 DBObjectNode* popObject(); 00711 00712 00713 private: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00714 00715 //_____________________________________________________________________ 00716 // CALCACTION 00717 //--------------------------------------------------------------------- 00722 //_____________________________________________________________________ 00723 DBOBJSetAction calcAction ( DBOBJSetAction p_intCurAction, DBOBJSetAction p_intParentAction); 00724 }; 00725 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00726 //============================================================================= 00727 00728 00729 00730 00731 END_XDFLENGINE_NS 00732 00733 00734 #endif