00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "stdafx.h"
00023 #include "BONImpl.h"
00024 #include "Extensions.h"
00025
00026 #define COMTHROW(x) BONCOMTHROW(x)
00027
00028 extern const bool g_GME_ADDON;
00029 extern const bool g_TEST_META_CONFORMANCE_INSIDE_BON;
00030
00031 #ifndef NAMESPACE_PREF
00032 #define NAMESPACE_PREF ""
00033 #endif
00034
00035
00036 namespace BON
00037 {
00038
00039
00040
00041
00042
00043
00044
00045 inline ProjectImpl* _getProject( IMgaObject* spObject, ProjectImpl* pProject )
00046 {
00047 if ( pProject )
00048 return pProject;
00049 ProjectPtr spProject;
00050 COMCHECK2( spObject, spObject->get_Project( spProject.Addr() ) );
00051 return (ProjectImpl*) ProjectImpl::attach( spProject ).getCounted();
00052 }
00053
00054 inline MON::ObjectPtr _getMetaBase( IMgaObject* spObject )
00055 {
00056 MON::ObjectPtr spMeta;
00057 COMCHECK2( spObject, spObject->get_MetaBase( spMeta.Addr() ) );
00058 return spMeta;
00059 }
00060
00061 inline std::string _getMetaName( IMgaObject* spObject )
00062 {
00063 CComBSTR bstrName;
00064 COMCHECK2( _getMetaBase( spObject ), _getMetaBase( spObject )->get_Name( &bstrName ) );
00065 return Util::Copy( bstrName );
00066 }
00067
00068 inline long _getMetaRef( IMgaObject* spObject )
00069 {
00070 long lRef;
00071 COMCHECK2( _getMetaBase( spObject ), _getMetaBase( spObject )->get_MetaRef( &lRef ) );
00072 return lRef;
00073 }
00074
00075 inline MON::Containment _getMetaRole( IMgaFCO* spFCO )
00076 {
00077 MON::ContainmentPtr spMeta;
00078 COMCHECK2( spFCO, spFCO->get_MetaRole( spMeta.Addr() ) );
00079 return MON::Containment(spMeta);
00080 }
00081
00082 inline void _checkIsCallable( ObjectImpl* pObject )
00083 {
00084 if (g_GME_ADDON && pObject->getStatus() != OST_Exists )
00085 ASSERTTHROW( Exception( "Object is already deleted. Operation is illegal!" ) );
00086 }
00087
00088 inline bool _isAddOn()
00089 {
00090 return g_GME_ADDON;
00091 }
00092
00093 template < class T >
00094 std::set<T>& filterByAspect( std::set<T>& inSet, const MON::Aspect& meta )
00095 {
00096 if ( meta ) {
00097 std::set<T>::iterator it = inSet.begin();
00098 while ( it != inSet.end() ) {
00099 std::set<T>::iterator itSaved = it;
00100 it++;
00101 if ( ! (*itSaved)->isVisible( meta, true ) )
00102 inSet.erase( itSaved );
00103 }
00104 }
00105 return inSet;
00106 }
00107
00108 template < class T , class TI>
00109 void setCopy( const std::set<TI*>& setIn, std::set<T>& setOut )
00110 {
00111 for ( std::set<TI*>::const_iterator it = setIn.begin() ; it != setIn.end() ; it++ )
00112 setOut.insert( *it );
00113 }
00114
00115 template < class T , class TI, class TC>
00116 void setCastCopy( const std::set<TI*>& setIn, std::set<T>& setOut )
00117 {
00118 for ( std::set<TI*>::const_iterator it = setIn.begin() ; it != setIn.end() ; it++ )
00119 setOut.insert( dynamic_cast<TC*>( *it ) );
00120 }
00121
00122 #define THROW_METAPROJECT_BELONG( META ) \
00123 if ( META.project() != getProject()->getProjectMeta() ) \
00124 { \
00125 MON::Exception exc( "? does not belong to ? of ?!"); \
00126 exc << META.infoString() << getProject()->getProjectMeta().infoString() << getProject()->getInfoString(); \
00127 ASSERTTHROW( exc); \
00128 }
00129
00130 #define THROW_PROJECT_BELONG( OBJECT ) \
00131 if ( OBJECT->getProject() != getProject() ) \
00132 { \
00133 BON::Exception exc( "? does not belong to ?!"); \
00134 exc << OBJECT->getInfoString().c_str() << getProject()->getInfoString().c_str(); \
00135 ASSERTTHROW( exc ); \
00136 }
00137
00138 #define THROW_METAPROJECT_DOES_NOT_HAVE( META, CLASS, NAME ) \
00139 if ( ! META ) \
00140 {\
00141 MON::Exception exc( "MON::##CLASS [ ? ] does not exist in ? of ?!");\
00142 exc << NAME.c_str() << getProject()->getProjectMeta().infoString().c_str() << getProject()->getInfoString().c_str();\
00143 ASSERTTHROW( exc );\
00144 }
00145
00146 #define THROW_CANNOT_BE_NULL( META, CLASS ) \
00147 if ( ! META ) \
00148 {\
00149 ASSERTTHROW( Exception( std::string( CLASS ) + " cannot be null!" ) );\
00150 }
00151
00152 #define THROW_CANNOT_BE_EMPTY( WHAT, THESTR ) \
00153 if ( THESTR.empty() ) \
00154 ASSERTTHROW( Exception( std::string( WHAT ) + " cannot be empty string!" ) );
00155
00156 #define PREF_Color "/color"
00157 #define PREF_NameColor "/nameColor"
00158 #define PREF_NameEnabled "/isNameEnabled"
00159 #define PREF_HelpURL "/help"
00160 #define PREF_Location1 "PartRegs/"
00161 #define PREF_Location2 "/Position"
00162 #define PREF_NamePosition "/namePosition"
00163 #define PREF_NameWrap "/nameWrap"
00164 #define PREF_HotSpotEnabled "/isHotspotEnabled"
00165 #define PREF_TypeNameEnabled "/isTypeShown"
00166 #define PREF_TypeInfoEnabled "/isTypeInfoShown"
00167 #define PREF_ModelAutoRoutingEnabled "/isModelAutoRouted"
00168 #define PREF_Decorator "/decorator"
00169 #define PREF_Icon "/icon"
00170 #define PREF_PortIcon "/porticon"
00171 #define PREF_SubTypeIcon "/subTypeIcon"
00172 #define PREF_InstanceIcon "/instanceIcon"
00173 #define PREF_BorderColor "/borderColor"
00174 #define PREF_BackgroundColor "/backgroundColor"
00175 #define PREF_PortNameColor "/portColor"
00176 #define PREF_LineType "/lineType"
00177 #define PREF_SrcLineEndType "/srcStyle"
00178 #define PREF_DstLineEndType "/dstStyle"
00179 #define PREF_LabelFormat "/labelFormatStr"
00180 #define PREF_SrcLabel1 "/srcLabel1"
00181 #define PREF_SrcLabel2 "/srcLabel2"
00182 #define PREF_DstLabel1 "/dstLabel1"
00183 #define PREF_DstLabel2 "/dstLabel2"
00184 #define PREF_ConnectionAutoRoutingEnabled "/isAutoRouted"
00185
00186 bool Convert( const std::string& strValue, long& lValue, bool bIsHexa )
00187 {
00188 return sscanf( strValue.c_str(), ( bIsHexa ) ? "%x" : "%d", &lValue ) == 1;
00189 }
00190
00191 bool Convert( const std::string& strValue, COLORREF& crValue )
00192 {
00193 long lValue;
00194 if ( ! Convert( strValue, lValue, true ) ) {
00195 crValue = 0x0;
00196 return false;
00197 }
00198 unsigned int uiR = ( lValue & 0xFF0000 ) >> 16;
00199 unsigned int uiG = ( lValue & 0xFF00 ) >> 8;
00200 unsigned int uiB = ( lValue & 0xFF );
00201 crValue = RGB( uiR, uiG, uiB );
00202 return true;
00203 }
00204
00205 std::string Convert( COLORREF crValue )
00206 {
00207 char chBuffer[ 100 ];
00208 sprintf( chBuffer, "%x", crValue );
00209 return chBuffer;
00210 }
00211
00212 bool Convert( const std::string& strValueIn, NamePosition& eValue )
00213 {
00214 int iValue = 0;
00215 if ( sscanf( strValueIn.c_str(), "%d", &iValue ) == 1 ) {
00216 eValue = (NamePosition) iValue;
00217 return true;
00218 }
00219 CString strValue( strValueIn.c_str() );
00220 strValue.TrimLeft( _T("\t ") );
00221 strValue.TrimRight( _T("\t ") );
00222 if ( strValue == "N") {
00223 eValue = NP_North;
00224 return true;
00225 }
00226 if ( strValue == "NE") {
00227 eValue = NP_NorthEast;
00228 return true;
00229 }
00230 if ( strValue == "E") {
00231 eValue = NP_East;
00232 return true;
00233 }
00234 if ( strValue == "SE") {
00235 eValue = NP_SouthEast;
00236 return true;
00237 }
00238 if ( strValue == "S") {
00239 eValue = NP_South;
00240 return true;
00241 }
00242 if ( strValue == "SW") {
00243 eValue = NP_SouthWest;
00244 return true;
00245 }
00246 if ( strValue == "W") {
00247 eValue = NP_West;
00248 return true;
00249 }
00250 if ( strValue == "NW") {
00251 eValue = NP_NorthWest;
00252 return true;
00253 }
00254 if ( strValue =="C") {
00255 eValue = NP_Center;
00256 return true;
00257 }
00258 return false;
00259 }
00260
00261 std::string Convert( NamePosition pos )
00262 {
00263 switch ( pos ) {
00264 case NP_Center : return "C";
00265 case NP_South : return "S";
00266 case NP_North : return "N";
00267 case NP_West : return "W";
00268 case NP_East : return "E";
00269 case NP_SouthWest : return "SW";
00270 case NP_SouthEast : return "SE";
00271 case NP_NorthWest : return "NW";
00272 case NP_NorthEast : return "NE";
00273 }
00274 return "S";
00275 }
00276
00277 bool Convert( const std::string& strValue, LineType& eType )
00278 {
00279 if ( strValue == "dash" ) {
00280 eType = LT_Dash;
00281 return true;
00282 }
00283 if ( strValue == "solid" ) {
00284 eType = LT_Solid;
00285 return true;
00286 }
00287 return false;
00288 }
00289
00290 std::string Convert( LineType eType )
00291 {
00292 switch ( eType ) {
00293 case LT_Solid : return "solid";
00294 case LT_Dash : return "dash";
00295 }
00296 return "solid";
00297 }
00298
00299 bool Convert( const std::string& strValue, LineEndType& eType )
00300 {
00301 if ( strValue == "butt" ) {
00302 eType = LET_Butt;
00303 return true;
00304 }
00305 if ( strValue == "arrow" ) {
00306 eType = LET_Arrow;
00307 return true;
00308 }
00309 if ( strValue == "diamond" ) {
00310 eType = LET_Diamond;
00311 return true;
00312 }
00313 if ( strValue == "apex" ) {
00314 eType = LET_Apex;
00315 return true;
00316 }
00317 if ( strValue == "bullet" ) {
00318 eType = LET_Bullet;
00319 return true;
00320 }
00321 if ( strValue == "empty diamond" ) {
00322 eType = LET_EmptyDiamond;
00323 return true;
00324 }
00325 if ( strValue == "empty apex" ) {
00326 eType = LET_EmptyApex;
00327 return true;
00328 }
00329 if ( strValue == "empty bullet" ) {
00330 eType = LET_EmptyBullet;
00331 return true;
00332 }
00333 if ( strValue == "left half arrow" ) {
00334 eType = LET_LeftHalfArrow;
00335 return true;
00336 }
00337 if ( strValue == "right half arrow" ) {
00338 eType = LET_RightHalfArrow;
00339 return true;
00340 }
00341 return false;
00342 }
00343
00344 std::string Convert( LineEndType eType )
00345 {
00346 switch ( eType ) {
00347 case LET_Butt : return "butt";
00348 case LET_Arrow : return "arrow";
00349 case LET_Diamond : return "diamond";
00350 case LET_Apex : return "apex";
00351 case LET_Bullet : return "bullet";
00352 case LET_EmptyDiamond : return "empty diamond";
00353 case LET_EmptyApex : return "empty apex";
00354 case LET_EmptyBullet : return "empty bullet";
00355 case LET_LeftHalfArrow : return "left half arrow";
00356 case LET_RightHalfArrow : return "right half arrow";
00357 }
00358 return "butt";
00359 }
00360
00361
00362
00363
00364
00365
00366
00367 ProjectImpl::ProjectMap ProjectImpl::mapProjects;
00368
00369 ProjectImpl::ProjectImpl( IMgaProject* spProject )
00370 : Util::GenRefCounted( true, NULL ), m_spProject( spProject ), m_bAutoCommit( true ), m_bIsDestructionActive( false )
00371 {
00372
00373 mapProjects.insert( ProjectMap::value_type( ProjectPtr( spProject ), this ) );
00374
00375
00376 MON::ProjectPtr spMeta;
00377 COMCHECK2( m_spProject, m_spProject->get_RootMeta( spMeta.Addr() ) );
00378 m_meta = MON::Project( spMeta );
00379 }
00380
00381 ProjectImpl::~ProjectImpl()
00382 {
00383 m_bIsDestructionActive = true;
00384
00385 if ( ! isDeleted() ) {
00386 for ( ObjectMap::iterator it = m_mapObjects.begin() ; it != m_mapObjects.end() ; it++ )
00387 delete it->second;
00388 }
00389
00390 mapProjects.erase( m_spProject );
00391
00392 m_mapObjects.clear();
00393 m_mapObjectsByID.clear();
00394 m_mapObjectsByKind.clear();
00395 m_spProject = NULL;
00396 m_gme = NULL;
00397 m_meta = MON::Project();
00398 }
00399
00400 void ProjectImpl::finalizeObjects()
00401 {
00402 ObjectSet objects;
00403 for ( ObjectMap::iterator it = m_mapObjects.begin() ; it != m_mapObjects.end() ; it++ )
00404 objects.insert( it->second );
00405 for ( ObjectSet::iterator it2 = objects.begin() ; it2 != objects.end() ; it2++ )
00406 (*it2)->finalize();
00407 }
00408
00409 Project ProjectImpl::attach( IMgaProject* spProject )
00410 {
00411 ProjectMap::iterator it = mapProjects.find( spProject );
00412 if ( it != mapProjects.end() )
00413 return it->second;
00414
00415 return new ProjectImpl( spProject );
00416 }
00417
00418 bool ProjectImpl::setDeleted()
00419 {
00420 { using namespace Util; if ( GenRefCounted::setDeleted() ) return true; }
00421
00422 for ( ObjectMap::iterator it = m_mapObjects.begin() ; it != m_mapObjects.end() ; it++ )
00423 it->second->setDeleted();
00424 return false;
00425 }
00426
00427
00428
00429
00430 bool ProjectImpl::isAutoCommit() const
00431 {
00432 return m_bAutoCommit;
00433 }
00434
00435 void ProjectImpl::setAutoCommit( bool bAutoCommit )
00436 {
00437 m_bAutoCommit = bAutoCommit;
00438 if ( ! m_bAutoCommit && bAutoCommit ) {
00439 commit();
00440 }
00441 }
00442
00443 void ProjectImpl::commit()
00444 {
00445 COMCHECK2( m_spProject, m_spProject->CommitTransaction() );
00446
00447 if (!m_spTerritory) {
00448 COMCHECK2( m_spProject, m_spProject->CreateTerritory( NULL, m_spTerritory.Addr() ) );
00449 }
00450 COMCHECK2( m_spProject, m_spProject->BeginTransaction( m_spTerritory ) );
00451 }
00452
00453 void ProjectImpl::commitOnly()
00454 {
00455 COMCHECK2( m_spProject, m_spProject->CommitTransaction() );
00456 }
00457
00458 void ProjectImpl::beginOnly()
00459 {
00460 beginOnly(TRANSACTION_GENERAL);
00461 }
00462
00463 void ProjectImpl::beginOnly(transactiontype_enum mode)
00464 {
00465 if (!m_spTerritory) {
00466 COMCHECK2( m_spProject, m_spProject->CreateTerritory( NULL, m_spTerritory.Addr() ) );
00467 }
00468 COMCHECK2( m_spProject, m_spProject->BeginTransaction( m_spTerritory, mode ) );
00469 }
00470
00471 void ProjectImpl::abort()
00472 {
00473 COMCHECK2( m_spProject, m_spProject->AbortTransaction() );
00474
00475 if (!m_spTerritory) {
00476 COMCHECK2( m_spProject, m_spProject->CreateTerritory( NULL, m_spTerritory.Addr() ) );
00477 }
00478 COMCHECK2( m_spProject, m_spProject->BeginTransaction( m_spTerritory ) );
00479 }
00480
00481 void ProjectImpl::abortOnly()
00482 {
00483 COMCHECK2( m_spProject, m_spProject->AbortTransaction() );
00484 }
00485
00486 bool ProjectImpl::isDestructionActive() const
00487 {
00488 return m_bIsDestructionActive;
00489 }
00490
00491 ProjectPtr ProjectImpl::getProjectI() const
00492 {
00493 return m_spProject;
00494 }
00495
00496 TerritoryPtr ProjectImpl::getTerritoryI() const
00497 {
00498 return m_spTerritory;
00499 }
00500
00501 const MON::Project& ProjectImpl::getProjectMeta() const
00502 {
00503 return m_meta;
00504 }
00505
00506 std::string ProjectImpl::getName() const
00507 {
00508 CComBSTR bstrName;
00509 COMCHECK2( m_spProject, m_spProject->get_Name( &bstrName ) );
00510 return Util::Copy( bstrName );
00511 }
00512
00513 std::string ProjectImpl::getAuthor() const
00514 {
00515 CComBSTR bstrAuthor;
00516 COMCHECK2( m_spProject, m_spProject->get_Author( &bstrAuthor ) );
00517 return Util::Copy( bstrAuthor );
00518 }
00519
00520 std::string ProjectImpl::getComment() const
00521 {
00522 CComBSTR bstrComment;
00523 COMCHECK2( m_spProject, m_spProject->get_Comment( &bstrComment ) );
00524 return Util::Copy( bstrComment );
00525 }
00526
00527 std::string ProjectImpl::getCreationTime() const
00528 {
00529 CComBSTR bstrTime;
00530 COMCHECK2( m_spProject, m_spProject->get_CreateTime( &bstrTime ) );
00531 return Util::Copy( bstrTime );
00532 }
00533
00534 std::string ProjectImpl::getChangeTime() const
00535 {
00536 CComBSTR bstrTime;
00537 COMCHECK2( m_spProject, m_spProject->get_ChangeTime( &bstrTime ) );
00538 return Util::Copy( bstrTime );
00539 }
00540
00541 std::string ProjectImpl::getGUID() const
00542 {
00543 CComVariant v;
00544 COMCHECK2( m_spProject, m_spProject->get_GUID( &v ) );
00545
00546 if (v.vt != (VT_UI1 | VT_ARRAY) ||
00547 v.parray == NULL ||
00548 v.parray->cbElements != 1 ||
00549 v.parray->cDims != 1 ||
00550 v.parray->rgsabound[0].cElements != sizeof(GUID)) {
00551
00552 ASSERTTHROW( BON::Exception( "Invalid GUID format!" ) );
00553
00554 }
00555
00556 GUID guid;
00557 unsigned char *start = (unsigned char*)&guid;
00558 unsigned char *end = (unsigned char*)(&guid+1);
00559 const unsigned char *q = NULL;
00560
00561 BONCOMTHROW( SafeArrayAccessData(v.parray, (void**)&q) );
00562
00563 if (q == NULL ) {
00564 ASSERTTHROW( BON::Exception( "Error in GUID conversion!" ) );
00565 }
00566
00567 memcpy( start, q, (end - start) * sizeof(unsigned char) );
00568 BONCOMTHROW( SafeArrayUnaccessData(v.parray) );
00569
00570 wchar_t *guidstr = NULL;
00571 BONCOMTHROW(StringFromCLSID(guid,&guidstr));
00572 std::string strResult = Util::Copy( guidstr );
00573 CoTaskMemFree(guidstr);
00574
00575 return strResult;
00576 }
00577
00578 std::string ProjectImpl::getVersion() const
00579 {
00580 CComBSTR bstrVersion;
00581 COMCHECK2( m_spProject, m_spProject->get_Version( &bstrVersion ) );
00582 return Util::Copy( bstrVersion );
00583 }
00584
00585 std::string ProjectImpl::getProjectPath() const
00586 {
00587 CComBSTR bstrName;
00588 COMCHECK2( m_spProject, m_spProject->get_ProjectConnStr( &bstrName ) );
00589 return Util::Copy( bstrName ).substr(4);
00590 }
00591
00592 std::string ProjectImpl::getParadigmPath() const
00593 {
00594 CComBSTR bstrName;
00595 COMCHECK2( m_spProject, m_spProject->get_ParadigmConnStr( &bstrName ) );
00596 return Util::Copy( bstrName ).substr(4);
00597 }
00598
00599 void ProjectImpl::setName( const std::string& strName )
00600 {
00601 COMCHECK2( m_spProject, m_spProject->put_Name( Util::Copy( strName ) ) );
00602 if ( isAutoCommit() )
00603 commit();
00604 }
00605
00606 void ProjectImpl::setAuthor( const std::string& strAuthor )
00607 {
00608 COMCHECK2( m_spProject, m_spProject->put_Author( Util::Copy( strAuthor ) ) );
00609 if ( isAutoCommit() )
00610 commit();
00611 }
00612
00613 void ProjectImpl::setComment( const std::string& strComment )
00614 {
00615 COMCHECK2( m_spProject, m_spProject->put_Comment( Util::Copy( strComment ) ) );
00616 if ( isAutoCommit() )
00617 commit();
00618 }
00619
00620 std::string ProjectImpl::getInfoString( unsigned short usOptions ) const
00621 {
00622 bool bAll = ( usOptions & Util::IO_All ) ? true : false;
00623 bool bIdent = bAll || ( usOptions & Util::IO_Identifiers );
00624 bool bLine = bAll || ( usOptions & Util::IO_NewLine );
00625 std::string strDelim = ( bLine ) ? "\n" : ", ";
00626
00627 std::string strInfo( "BON::Project" );
00628 strInfo += ( bLine ) ? " :\n" : " [";
00629
00630 if ( bIdent )
00631 strInfo += "name: ";
00632 strInfo += getName();
00633
00634 if ( ( usOptions & Util::IO_Specific ) || bAll ) {
00635 strInfo += strDelim;
00636 if ( bIdent )
00637 strInfo += "author: ";
00638 strInfo += getAuthor() + strDelim;
00639 if ( bIdent )
00640 strInfo += "comment: ";
00641 strInfo += getComment() + strDelim;
00642 if ( bIdent )
00643 strInfo += "creationTime: ";
00644 strInfo += getCreationTime() + strDelim;
00645 if ( bIdent )
00646 strInfo += "changeTime: ";
00647 strInfo += getChangeTime();
00648 }
00649
00650 if ( ( usOptions & Util::IO_Meta ) || bAll ) {
00651 strInfo += strDelim;
00652 if ( bIdent )
00653 strInfo += "meta: ";
00654 strInfo += getProjectMeta().infoString( bIdent );
00655 }
00656
00657 if ( ! bLine )
00658 strInfo += "]";
00659
00660 return strInfo;
00661 }
00662
00663 std::string ProjectImpl::getInfoString( const std::set<Util::InfoOption>& setOptions ) const
00664 {
00665 return getInfoString( copy( setOptions ) );
00666 }
00667
00668 void ProjectImpl::assignTerritory(TerritoryPtr terr) {
00669 m_spTerritory = terr;
00670 }
00671
00672 void ProjectImpl::consoleClear()
00673 {
00674 putConsoleContents("");
00675 }
00676
00677 void ProjectImpl::consoleMsg(const std::string& msg, msgtype_enum type)
00678 {
00679 GMEAppPtr pGME = getGME();
00680 COMCHECK2(pGME, pGME->ConsoleMessage(Util::Copy( msg ), type));
00681 }
00682
00683 std::string ProjectImpl::getConsoleContents()
00684 {
00685 GMEAppPtr pGME = getGME();
00686 CComBSTR ccBstr;
00687 COMCHECK2(pGME, pGME->get_ConsoleContents( &ccBstr));
00688 return Util::Copy( ccBstr );
00689 }
00690
00691 void ProjectImpl::putConsoleContents(const std::string& htmlMsg )
00692 {
00693 GMEAppPtr pGME = getGME();
00694 CComBSTR ccBstr(htmlMsg.c_str());
00695 COMCHECK2(pGME, pGME->put_ConsoleContents( ccBstr));
00696 }
00697
00698 std::string ProjectImpl::getGMEVersion()
00699 {
00700 GMEAppPtr pGME = getGME();
00701 CComBSTR verBstr;
00702 COMCHECK2(pGME, pGME->get_Version(&verBstr));
00703 return Util::Copy( verBstr );
00704 }
00705
00706 int ProjectImpl::getGMEVersionMajor() {
00707 GMEAppPtr pGME = getGME();
00708 short n;
00709 COMCHECK2(pGME, pGME->get_VersionMajor(&n));
00710 return n;
00711 }
00712
00713 int ProjectImpl::getGMEVersionMinor() {
00714 GMEAppPtr pGME = getGME();
00715 short n;
00716 COMCHECK2(pGME, pGME->get_VersionMinor(&n));
00717 return n;
00718 }
00719
00720 int ProjectImpl::getGMEVersionPatchLevel() {
00721 GMEAppPtr pGME = getGME();
00722 short n;
00723 COMCHECK2(pGME, pGME->get_VersionPatchLevel(&n));
00724 return n;
00725 }
00726
00727 void ProjectImpl::saveProject() {
00728 if (m_spTerritory) {
00729 COMCHECK2( m_spProject, m_spProject->CommitTransaction( ));
00730 }
00731
00732 GMEAppPtr pGME = getGME();
00733 COMCHECK2(pGME, pGME->SaveProject());
00734
00735 if (m_spTerritory) {
00736 COMCHECK2( m_spProject, m_spProject->BeginTransaction( m_spTerritory ));
00737 }
00738
00739 }
00740
00741 void ProjectImpl::saveProjectAs(const std::string& connstr) {
00742 if (m_spTerritory) {
00743 COMCHECK2( m_spProject, m_spProject->CommitTransaction( ));
00744 }
00745
00746 GMEAppPtr pGME = getGME();
00747 COMCHECK2(pGME, pGME->SaveProjectAs(Util::Copy( connstr )));
00748
00749 if (m_spTerritory) {
00750 COMCHECK2( m_spProject, m_spProject->BeginTransaction( m_spTerritory ));
00751 }
00752 }
00753
00754 void ProjectImpl::exportProject(const std::string& connstr) {
00755 if (m_spTerritory) {
00756 COMCHECK2( m_spProject, m_spProject->CommitTransaction( ));
00757 }
00758
00759 GMEAppPtr pGME = getGME();
00760 COMCHECK2(pGME, pGME->ExportProject(Util::Copy( connstr )));
00761
00762 if (m_spTerritory) {
00763 COMCHECK2( m_spProject, m_spProject->BeginTransaction( m_spTerritory ));
00764 }
00765 }
00766
00767 void ProjectImpl::importProject(const std::string& connstr) {
00768 if (m_spTerritory) {
00769 COMCHECK2( m_spProject, m_spProject->CommitTransaction( ));
00770 }
00771
00772 GMEAppPtr pGME = getGME();
00773 COMCHECK2(pGME, pGME->ImportProject(Util::Copy( connstr )));
00774
00775 if (m_spTerritory) {
00776 COMCHECK2( m_spProject, m_spProject->BeginTransaction( m_spTerritory ));
00777 }
00778 }
00779
00780 void ProjectImpl::checkConstraints() {
00781 if (m_spTerritory) {
00782 COMCHECK2( m_spProject, m_spProject->CommitTransaction( ));
00783 }
00784
00785 GMEAppPtr pGME = getGME();
00786 COMCHECK2(pGME, pGME->CheckAllConstraints());
00787
00788 if (m_spTerritory) {
00789 COMCHECK2( m_spProject, m_spProject->BeginTransaction( m_spTerritory ));
00790 }
00791 }
00792
00793 void ProjectImpl::runComponent(const std::string& progID) {
00794 if (m_spTerritory) {
00795 COMCHECK2( m_spProject, m_spProject->CommitTransaction( ));
00796 }
00797
00798 GMEAppPtr pGME = getGME();
00799 COMCHECK2(pGME, pGME->RunComponent(Util::Copy( progID )));
00800
00801 if (m_spTerritory) {
00802 COMCHECK2( m_spProject, m_spProject->BeginTransaction( m_spTerritory ));
00803 }
00804 }
00805
00806 void ProjectImpl::showFCO(FCO fco) {
00807 if (m_spTerritory) {
00808 COMCHECK2( m_spProject, m_spProject->CommitTransaction( ));
00809 }
00810
00811 GMEAppPtr pGME = getGME();
00812 COMCHECK2(pGME, pGME->ShowFCO(fco->getFCOI()));
00813
00814 if (m_spTerritory) {
00815 COMCHECK2( m_spProject, m_spProject->BeginTransaction( m_spTerritory ));
00816 }
00817 }
00818
00819 std::string ProjectImpl::prefixWNmsp( const std::string& pKindOrRole) const
00820 {
00821 return ( m_nmsp.length()>0? m_nmsp + "::" : "") + pKindOrRole;
00822 }
00823
00824 std::string ProjectImpl::getNmsp()
00825 {
00826 m_meta.m_nmsp = m_nmsp = getNmspFrTerritory();
00827 return m_nmsp;
00828 }
00829
00830 void ProjectImpl::setNmsp( const std::string& pNmsp)
00831 {
00832 m_meta.m_nmsp = m_nmsp = pNmsp;
00833 setNmspInTerritory();
00834 }
00835
00836 std::string ProjectImpl::getNmspFrTerritory() const
00837 {
00838 if( m_spTerritory)
00839 {
00840 CComBSTR nms;
00841 m_spTerritory->GetNamespace( &nms);
00842 return Util::Copy( nms);
00843 }
00844 ASSERT(0);
00845 return "";
00846 }
00847
00848 bool ProjectImpl::setNmspInTerritory()
00849 {
00850 if( m_spTerritory)
00851 {
00852 m_spTerritory->SetNamespace( CComBSTR( m_nmsp.c_str()));
00853 return true;
00854 }
00855 ASSERT(0);
00856 return false;
00857 }
00858
00859
00860
00861
00862 ObjectImpl* ProjectImpl::findByCOMI( IMgaObject* spObject ) const
00863 {
00864 ObjectMap::const_iterator it = m_mapObjects.find( ObjectPtr( spObject ) );
00865 return ( it == m_mapObjects.end() ) ? NULL : it->second;
00866 }
00867
00868 ObjectImpl* ProjectImpl::findByIDI( const std::string& strID )
00869 {
00870
00871
00872 ObjectMapByID::iterator it = m_mapObjectsByID.find( strID );
00873 if ( it != m_mapObjectsByID.end() )
00874 return it->second;
00875
00876
00877
00878 ObjectPtr spObject;
00879 COMCHECK2( m_spProject, m_spProject->GetObjectByID( Util::Copy( strID ), spObject.Addr() ) );
00880 if ( ! spObject )
00881 return NULL;
00882
00883 return ObjectImpl::attachI( spObject, this );
00884 }
00885
00886 ObjectSet ProjectImpl::findByKindI( const MON::FCO& meta )
00887 {
00888
00889 ObjectMapByKind::iterator it = m_mapObjectsByKind.find( meta );
00890 if ( it != m_mapObjectsByKind.end() && it->second.first )
00891 return it->second.second;
00892
00893
00894 Util::ComPtr<IMgaFilter> spFilter;
00895 COMCHECK2( m_spProject, m_spProject->CreateFilter( spFilter.Addr() ) );
00896 COMCHECK2( spFilter, spFilter->put_Kind( Util::Copy( meta.name() ) ) );
00897
00898
00899 Util::ComPtr<IMgaFCOs> spFCOs;
00900 COMCHECK2( m_spProject, m_spProject->AllFCOs( spFilter, spFCOs.Addr() ) );
00901
00902
00903 MGACOLL_ITERATE( IMgaFCO, spFCOs.p ) {
00904 ObjectImpl::attachI( MGACOLL_ITER, this, meta );
00905 } MGACOLL_ITERATE_END;
00906
00907
00908 m_mapObjectsByKind[ meta ].first = true;
00909 return m_mapObjectsByKind[ meta ].second;
00910 }
00911
00912 ObjectSet ProjectImpl::findByKindI( const MON::Folder& meta )
00913 {
00914
00915 ObjectMapByKind::iterator it = m_mapObjectsByKind.find( meta );
00916 if ( it != m_mapObjectsByKind.end() && it->second.first )
00917 return it->second.second;
00918
00919
00920 findByKindI( getRootFolder()->getFolderI(), meta );
00921
00922
00923 m_mapObjectsByKind[ meta ].first = true;
00924 return m_mapObjectsByKind[ meta ].second;
00925 }
00926
00927 void ProjectImpl::findByKindI( FolderPtr spFolder, const MON::Folder& meta )
00928 {
00929
00930 if ( _getMetaRef( spFolder ) == meta.ref() )
00931 ObjectImpl::attachI( spFolder, this, meta );
00932
00933
00934 Util::ComPtr<IMgaFolders> spFolders;
00935 COMCHECK2( spFolder, spFolder->get_ChildFolders( spFolders.Addr() ) );
00936 MGACOLL_ITERATE( IMgaFolder, spFolders.p ) {
00937 findByKindI( MGACOLL_ITER, meta );
00938 } MGACOLL_ITERATE_END;
00939 }
00940
00941 GMEAppPtr ProjectImpl::getGMEI()
00942 {
00943 GMEAppPtr p;
00944 try {
00945 p = getGME();
00946 } catch( Util::Exception &) {
00947
00948 }
00949 return p;
00950 }
00951
00952 GMEAppPtr ProjectImpl::getGME()
00953 {
00954 if (!m_gme) {
00955 CComBSTR bstrName("GME.Application");
00956 CComQIPtr<IMgaClient> pClient;
00957 HRESULT hr = m_spProject->GetClientByName(bstrName, &pClient);
00958 if( FAILED( hr))
00959 ASSERTTHROW( Exception( "Can't retrieve GME Application object" ) );
00960 if (pClient) {
00961 CComQIPtr<IDispatch> pDispatch;
00962 COMCHECK2(pClient, pClient->get_OLEServer(&pDispatch));
00963 if (pDispatch) {
00964 BONCOMTHROW(pDispatch.QueryInterface(m_gme.Addr()));
00965 }
00966 }
00967 }
00968 if (!m_gme) {
00969 ASSERTTHROW( Exception( "Unable to retrieve GME Application object" ) );
00970 }
00971 return m_gme;
00972 }
00973
00974
00975
00976
00977
00978
00979
00980
00981 ObjsPtr ProjectImpl::getSelectedObjsFromBrowser()
00982 {
00983 GMEAppPtr g = getGME();
00984 GMECollPtr coll;
00985 if( g) COMCHECK2( g, g->get_Panels( coll.Addr()));
00986 long cnt;
00987 if( coll) COMCHECK2( coll, coll->get_Count( &cnt));
00988 if( cnt > 0)
00989 {
00990 CComQIPtr<IDispatch> pDispatch;
00991
00992 COMCHECK2( coll, coll->get_Item( 1, &pDispatch));
00993 if( pDispatch)
00994 {
00995 GMEPanelPtr panel;
00996 BONCOMTHROW( pDispatch.QueryInterface( panel.Addr()));
00997 CComBSTR nm;
00998 COMCHECK2( panel, panel->get_Name( &nm));
00999 ASSERT( nm == CComBSTR("Browser"));
01000 CComQIPtr<IDispatch> pi;
01001 COMCHECK2( panel, panel->get_Interface( &pi));
01002 CComDispatchDriver dd;
01003 dd = pi;
01004 CComVariant w;
01005
01006
01007
01008 HRESULT hw = dd.Invoke0( 4, &w);
01009
01010
01011 if( hw == S_OK && w.vt == VT_UNKNOWN && w.punkVal != 0)
01012 {
01013 CComQIPtr<IMgaObjects> objs( w.punkVal);
01014 return objs;
01015 }
01016 }
01017 }
01018
01019 return ObjsPtr();
01020 }
01021
01022 bool ProjectImpl::isGMEAvailable() const
01023 {
01024 if( m_gme) return true;
01025 CComBSTR bstrName("GME.Application");
01026 CComQIPtr<IMgaClient> pClient;
01027 HRESULT hr = m_spProject->GetClientByName(bstrName, &pClient);
01028 if( FAILED( hr)) return false;
01029 return true;
01030 }
01031
01032
01033
01034
01035 void ProjectImpl::onObjectRetrieved( ObjectImpl* pObject )
01036 {
01037 m_mapObjectsByID[ pObject->getID() ] = pObject;
01038
01039 ObjectMapByKind::iterator it = m_mapObjectsByKind.find( pObject->getObjectMeta() );
01040 if ( it == m_mapObjectsByKind.end() )
01041 m_mapObjectsByKind[ pObject->getObjectMeta() ] = ObjectSetPair( false, ObjectSet() );
01042 m_mapObjectsByKind[ pObject->getObjectMeta() ].second.insert( pObject );
01043 m_mapObjects.insert( ObjectMap::value_type( pObject->getObjectI(), pObject ) );
01044 }
01045
01046 void ProjectImpl::onObjectReleased( ObjectImpl* pObject, bool bOnlyMemoryFree )
01047 {
01048 m_mapObjectsByID.erase( pObject->getID() );
01049 m_mapObjectsByKind[ pObject->getObjectMeta() ].second.erase( pObject );
01050 m_mapObjects.erase( pObject->getObjectI() );
01051 if ( bOnlyMemoryFree )
01052 m_mapObjectsByKind[ pObject->getObjectMeta() ].first = false;
01053 }
01054
01055
01056
01057
01058 Folder ProjectImpl::getRootFolder()
01059 {
01060 FolderPtr spFolder;
01061 COMCHECK2( m_spProject, m_spProject->get_RootFolder( spFolder.Addr() ) );
01062 return (FolderImpl*) ObjectImpl::attachI( spFolder, this );
01063 }
01064
01065
01066
01067 std::set<Folder> ProjectImpl::getLibraries()
01068 {
01069 std::set<Folder> setResult;
01070 std::set<Object> set = findByKind( "RootFolder" );
01071 for ( std::set<Object>::iterator it = set.begin() ; it != set.end() ; ++it )
01072 if ( getRootFolder() != *it )
01073 setResult.insert( Folder( *it ) );
01074 return setResult;
01075 }
01076
01077
01078
01079 Object ProjectImpl::findByID( const std::string& strID, bool bExIfNotExist, bool bTolerateZombies )
01080 {
01081 BON::Object object = findByIDI( strID );
01082 if( !bTolerateZombies && object && object->getStatus() != OST_Exists)
01083 object = Object();
01084
01085 if ( bExIfNotExist && ! object )
01086 {
01087 Exception exc( "BON::Object with ID [ ? ] does not exist!");
01088 exc << strID;
01089 ASSERTTHROW( exc );
01090 }
01091 return object;
01092 }
01093
01094 std::set<Object> ProjectImpl::findByKind( const MON::Object& meta )
01095 {
01096 if ( ! meta )
01097 ASSERTTHROW( Exception( "MON::Object cannot be null!" ) );
01098 if ( meta.project() != getProjectMeta() )
01099 {
01100 MON::Exception exc( "? does not belong to ? of ?!");
01101 exc << meta.infoString() << getProjectMeta().infoString() << getInfoString().c_str();
01102 ASSERTTHROW( exc);
01103 }
01104 if ( meta.type() < MON::OT_Model || meta.type() > MON::OT_Folder )
01105 {
01106 Exception exc( "Type of ? can be only MON::Folder or MON::FCO!");
01107 exc << meta.infoString();
01108 ASSERTTHROW( exc );
01109 }
01110
01111 std::set<Object> setResult;
01112 setCopy<Object,ObjectImpl>( ( meta.type() == MON::OT_Folder ) ? findByKindI( MON::Folder( meta ) ) : findByKindI( MON::FCO( meta ) ), setResult );
01113 return setResult;
01114 }
01115
01116 std::set<Object> ProjectImpl::findByKind( const std::string& strKind )
01117 {
01118 MON::Object meta = getProjectMeta().findByName( strKind );
01119 if ( ! meta )
01120 {
01121 MON::Exception exc( "MON::Folder [ ? ] or MON::FCO [ ? ] does not exist in ? of ?!");
01122 exc << strKind.c_str() << strKind.c_str() << getProjectMeta().infoString().c_str() << getInfoString().c_str();
01123 ASSERTTHROW( exc );
01124 }
01125 if ( meta.type() < MON::OT_Model || meta.type() > MON::OT_Folder )
01126 {
01127 Exception exc( "? is not MON::Folder or MON::FCO!");
01128 exc << meta.infoString().c_str();
01129 ASSERTTHROW( exc );
01130 }
01131
01132 std::set<Object> setResult;
01133 setCopy<Object,ObjectImpl>( ( meta.type() == MON::OT_Folder ) ? findByKindI( MON::Folder( meta ) ) : findByKindI( MON::FCO( meta ) ), setResult );
01134 return setResult;
01135 }
01136
01137
01138
01139
01140
01141
01142
01143 ObjectImpl::ObjectImpl()
01144 : m_bAllParentFolders( false ), m_bIsDestructionActive( false )
01145 {
01146 setDisposable( _isAddOn() );
01147 }
01148
01149 ObjectImpl* ObjectImpl::getEx( IMgaObject* spObject, ObjectType eType, const MON::Object& meta )
01150 {
01151 std::string strKind = ( meta ) ? meta.name() : _getMetaName( spObject );
01152 std::string strRole;
01153 if ( eType != OT_Folder ) {
01154 CComQIPtr<IMgaFCO> spFCO = spObject;
01155 MON::Containment role = _getMetaRole( spFCO );
01156 if ( role )
01157 strRole = role.name();
01158 }
01159 return ExtensionManager::createImpl( eType, strKind, strRole );
01160 }
01161
01162 void ObjectImpl::doInitialize( IMgaObject* spObject, ProjectImpl* pProject, const MON::Object& meta )
01163 {
01164 m_spObject = spObject;
01165 m_pProject = _getProject( spObject, pProject );
01166 std::set<Util::GenRefCounted*> setAggrs;
01167 setAggrs.insert( m_pProject );
01168 setAggregators( setAggrs );
01169 m_meta = meta;
01170
01171
01172 if ( ! meta ) {
01173 MON::ObjectPtr spMetaBase;
01174 COMCHECK2( m_spObject, m_spObject->get_MetaBase( spMetaBase.Addr() ) );
01175 long lRef;
01176 COMCHECK2( spMetaBase, spMetaBase->get_MetaRef( &lRef ) );
01177 m_meta = m_pProject->getProjectMeta().findByRef( lRef );
01178 }
01179
01180
01181 m_parentFolder.first = MON::Folder();
01182 m_parentFolder.second = NULL;
01183
01184
01185 m_pProject->onObjectRetrieved( this );
01186 }
01187
01188 ObjectImpl* ObjectImpl::find( ProjectImpl* pProject, IMgaObject* spObject )
01189 {
01190 return _getProject( spObject, pProject )->findByCOMI( spObject );
01191 }
01192
01193 ObjectImpl* ObjectImpl::attachI( IMgaObject* spObject, ProjectImpl* pProject, const MON::Object& meta )
01194 {
01195
01196 CComQIPtr<IMgaFolder> spFolder = spObject;
01197 if ( spFolder )
01198 return FolderImpl::attachI( spFolder, pProject, meta );
01199 CComQIPtr<IMgaFCO> spFCO = spObject;
01200 if ( spFCO )
01201 return FCOImpl::attachI( spFCO, pProject, meta );
01202 ASSERTTHROW( Util::Exception( "Unprocessed Object Type!" ) );
01203 }
01204
01205 Object ObjectImpl::attach( IMgaObject* spObject )
01206 {
01207 return attachI( spObject );
01208 }
01209
01210 ObjectImpl::~ObjectImpl()
01211 {
01212 m_bIsDestructionActive = true;
01213
01214 if ( ! m_pProject->isDestructionActive() && ! isDeleted() ) {
01215 if ( m_parentFolder.second )
01216 m_parentFolder.second->onReleasedAsObjectParent( this, true );
01217 m_pProject->onObjectReleased( this, true );
01218 }
01219
01220 for ( RegistryMap::iterator it = m_mapNodes.begin() ; it != m_mapNodes.end() ; it++ )
01221 delete it->second;
01222
01223 m_mapNodes.clear();
01224 m_parentFolder.first = MON::Folder();
01225 m_parentFolder.second = NULL;
01226 m_meta = MON::Object();
01227 m_pProject = NULL;
01228 m_spObject = NULL;
01229 }
01230
01231 bool ObjectImpl::setDeleted()
01232 {
01233 { using namespace Util; if ( GenRefCounted::setDeleted() ) return true; }
01234 finalize();
01235
01236 if ( m_parentFolder.second )
01237 m_parentFolder.second->onReleasedAsObjectParent( this, false );
01238 m_pProject->onObjectReleased( this, false );
01239
01240 for ( RegistryMap::iterator it = m_mapNodes.begin() ; it != m_mapNodes.end() ; it++ )
01241 it->second->setDeleted();
01242 return false;
01243 }
01244
01245 void ObjectImpl::destroy()
01246 {
01247
01248 if ( isInLibrary() )
01249 {
01250 BON::Exception exc( "? belongs to a library, thus it cannot be destroyed!");
01251 exc << getInfoString().c_str();
01252 ASSERTTHROW( exc );
01253 }
01254
01255 if ( ! _isAddOn() )
01256 setDeleted();
01257 COMCHECK2( getObjectI(), getObjectI()->DestroyObject() );
01258 if ( getProject()->isAutoCommit() )
01259 getProject()->commit();
01260 }
01261
01262
01263
01264
01265 bool ObjectImpl::isDestructionActive() const
01266 {
01267 return m_bIsDestructionActive;
01268 }
01269
01270 Project ObjectImpl::getProject() const
01271 {
01272 return m_pProject;
01273 }
01274
01275 ObjectPtr ObjectImpl::getObjectI() const
01276 {
01277 return m_spObject;
01278 }
01279
01280 const MON::Object& ObjectImpl::getObjectMeta() const
01281 {
01282 return m_meta;
01283 }
01284
01285 std::string ObjectImpl::getID() const
01286 {
01287 CComBSTR bstrID;
01288 COMCHECK2( m_spObject, m_spObject->get_ID( &bstrID ) );
01289 return Util::Copy( bstrID );
01290 }
01291
01292 ObjectStatus ObjectImpl::getStatus() const
01293 {
01294 long lStatus;
01295 COMCHECK2( m_spObject, m_spObject->get_Status( &lStatus ) );
01296 switch ( lStatus ) {
01297 case OBJECT_EXISTS :
01298 return OST_Exists;
01299 case OBJECT_ZOMBIE :
01300 return OST_Zombie;
01301 case OBJECT_DELETED :
01302 return OST_Deleted;
01303 default :
01304 ASSERTTHROW( Util::Exception( "Unprocessed Object Status!" ) );
01305 }
01306 }
01307
01308 bool ObjectImpl::isReadOnly() const
01309 {
01310 VARIANT_BOOL vbWritable;
01311 COMCHECK2( m_spObject, m_spObject->get_IsWritable( &vbWritable ) );
01312 return ( vbWritable ) ? false : true;
01313 }
01314
01315 bool ObjectImpl::isInLibrary() const
01316 {
01317 VARIANT_BOOL vbLibrary;
01318 COMCHECK2( m_spObject, m_spObject->get_IsLibObject( &vbLibrary ) );
01319 return ( vbLibrary ) ? true : false;
01320 }
01321
01322 std::string ObjectImpl::getName() const
01323 {
01324 CComBSTR bstrName;
01325 COMCHECK2( m_spObject, m_spObject->get_Name( &bstrName ) );
01326 return Util::Copy( bstrName );
01327 }
01328
01329 void ObjectImpl::setName( const std::string& strName )
01330 {
01331 COMCHECK2( m_spObject, m_spObject->put_Name( Util::Copy( strName ) ) );
01332 if ( getProject()->isAutoCommit() )
01333 getProject()->commit();
01334 }
01335
01336 std::string ObjectImpl::getPath( const std::string& strDelimiter, bool bReverseOrder, bool bNeedRootFolder ) const
01337 {
01338 Object p = ( (ObjectImpl*) this)->getParent();
01339 if ( ! p ) {
01340 if ( bNeedRootFolder )
01341 return ( bReverseOrder ) ? getName() + strDelimiter : strDelimiter + getName();
01342 return "";
01343 }
01344
01345 return ( bReverseOrder ) ? getName() + strDelimiter + p->getPath( strDelimiter, true, bNeedRootFolder ) : p->getPath( strDelimiter, false, bNeedRootFolder ) + strDelimiter + getName();
01346 }
01347
01348 std::string ObjectImpl::getInfoString( const std::set<Util::InfoOption>& setOptions ) const
01349 {
01350 return getInfoString( copy( setOptions ) );
01351 }
01352
01353 std::string ObjectImpl::getInfoStringHelper( unsigned short usOptions, const std::string& strStereo ) const
01354 {
01355 bool bAll = ( usOptions & Util::IO_All ) ? true : false;
01356 bool bIdent = bAll || ( usOptions & Util::IO_Identifiers );
01357 bool bLine = bAll || ( usOptions & Util::IO_NewLine );
01358 std::string strDelim = ( bLine ) ? "\n" : ", ";
01359
01360 std::string strInfo( "BON::" + strStereo );
01361 strInfo += ( bLine ) ? " :\n" : " [";
01362
01363 if ( bIdent )
01364 strInfo += "name: ";
01365 strInfo += getName();
01366
01367 if ( ( usOptions & Util::IO_ID ) || bAll ) {
01368 strInfo += strDelim;
01369 if ( bIdent )
01370 strInfo += "id: ";
01371 strInfo += getID();
01372 }
01373
01374 if ( ( usOptions & Util::IO_Path ) || bAll ) {
01375 strInfo += strDelim;
01376 if ( bIdent )
01377 strInfo += "path: ";
01378 strInfo += getPath();
01379 }
01380
01381 if ( ( usOptions & Util::IO_Meta ) || bAll ) {
01382 strInfo += strDelim;
01383 if ( bIdent )
01384 strInfo += "meta: ";
01385 strInfo += getObjectMeta().infoString( bIdent, ( usOptions & Util::IO_ID ) ? true : false );
01386 }
01387
01388 return strInfo;
01389 }
01390
01391
01392
01393
01394 FolderImpl* ObjectImpl::getParentFolderI( const MON::Folder& meta )
01395 {
01396
01397 if ( getObjectMeta().name() == "RootFolder" ) {
01398 m_bAllParentFolders = true;
01399 return NULL;
01400 }
01401
01402
01403
01404 if ( m_parentFolder.first )
01405 return ( ! meta || meta == m_parentFolder.first ) ? m_parentFolder.second : NULL;
01406 if ( m_bAllParentFolders )
01407 return NULL;
01408
01409
01410 ObjectPtr spObject;
01411 COMCHECK2( getObjectI(), getObjectI()->GetParent( spObject.Addr() ) );
01412 CComQIPtr<IMgaFolder> spFolder = spObject;
01413
01414
01415 if ( ! spFolder ) {
01416 m_bAllParentFolders = true;
01417 return NULL;
01418 }
01419
01420
01421 if ( ! meta || _getMetaRef( spFolder ) == meta.ref() ) {
01422 m_parentFolder.first = ( meta ) ? meta : MON::Folder( m_pProject->getProjectMeta().findByName( _getMetaName( spFolder ) ) );
01423 m_parentFolder.second = FolderImpl::attachI( spFolder, m_pProject, m_parentFolder.first );
01424 m_parentFolder.second->onRetrievedAsObjectParent( this, false );
01425 if ( ! meta )
01426 m_bAllParentFolders = true;
01427 }
01428 return m_parentFolder.second;
01429 }
01430
01431
01432
01433
01434 bool ObjectImpl::onRetrievedAsFolderChild( FolderImpl* pFolder, bool bCheckAll )
01435 {
01436 m_bAllParentFolders = true;
01437 m_parentFolder.first = pFolder->getFolderMeta();
01438 m_parentFolder.second = pFolder;
01439 return true;
01440 }
01441
01442 void ObjectImpl::onReleasedAsFolderChild( FolderImpl* pFolder, bool bOnlyFreeMemory )
01443 {
01444 m_bAllParentFolders = false;
01445 m_parentFolder.first = MON::Folder();
01446 m_parentFolder.second = NULL;
01447 }
01448
01449 void ObjectImpl::eventPerformedI( const Event& event )
01450 {
01451 switch ( event.getType() ) {
01452 case MON::OET_ObjectCreated :
01453 onObjectCreated();
01454 break;
01455 case MON::OET_ObjectDestroyed :
01456 setDeleted();
01457 break;
01458 case MON::OET_ObjectMoved :
01459 onObjectMoved( NULL, NULL );
01460 break;
01461 case MON::OET_RegistryChanged :
01462 onRegistryChanged();
01463 break;
01464 }
01465 }
01466
01467 void ObjectImpl::onObjectCreated()
01468 {
01469
01470 ObjectPtr spObject;
01471 COMCHECK2( m_spObject, m_spObject->GetParent( spObject.Addr() ) );
01472 Folder folder( ObjectImpl::attachI( spObject, m_pProject ) );
01473 if ( folder )
01474 folder->onChildAdded( this );
01475
01476 }
01477
01478 void ObjectImpl::onObjectMoved( ObjectImpl* pOldParent, ObjectImpl* pNewParent )
01479 {
01480 if ( pOldParent && pNewParent ) {
01481 if ( pOldParent->getStereotype() == OT_Folder )
01482 dynamic_cast<FolderImpl*>( pOldParent )->onChildRemoved( this );
01483 if ( pNewParent->getStereotype() == OT_Folder )
01484 dynamic_cast<FolderImpl*>( pNewParent )->onChildAdded( this );
01485 return;
01486 }
01487
01488
01489 if ( m_parentFolder.second )
01490 m_parentFolder.second->onChildRemoved( this );
01491 ObjectPtr spObject;
01492 COMCHECK2( m_spObject, m_spObject->GetParent( spObject.Addr() ) );
01493 Folder folder( ObjectImpl::attachI( spObject, m_pProject ) );
01494 if ( folder )
01495 folder->onChildAdded( this );
01496
01497 }
01498
01499 void ObjectImpl::onRegistryChanged()
01500 {
01501 for ( RegistryMap::iterator it = m_mapNodes.begin() ; it != m_mapNodes.end() ; it++ )
01502 it->second->setDeleted();
01503 }
01504
01505
01506
01507
01508 RegistryNode ObjectImpl::getRegistry() const
01509 {
01510 return RegistryNodeImpl::attachI( NULL, (ObjectImpl*) this );
01511 }
01512
01513 Object ObjectImpl::getParent()
01514 {
01515 return getParentFolder();
01516 }
01517
01518 Folder ObjectImpl::getParentFolder( const MON::Folder& meta )
01519 {
01520 if ( ! meta )
01521 return getParentFolderI();
01522
01523 THROW_METAPROJECT_BELONG( meta );
01524 if ( ! getObjectMeta().isFolderParent( meta ) )
01525 {
01526 MON::Exception exc( "? cannot be parent of ?!");
01527 exc << meta.infoString() << getObjectMeta().infoString();
01528 ASSERTTHROW( exc );
01529 }
01530
01531 return getParentFolderI( meta );
01532 }
01533
01534 Folder ObjectImpl::getParentFolder( const std::string& strFolder )
01535 {
01536 if ( strFolder.empty() )
01537 return getParentFolder();
01538
01539 MON::Folder meta( getProject()->getProjectMeta().findByName( strFolder ) );
01540 THROW_METAPROJECT_DOES_NOT_HAVE( meta, Folder, strFolder );
01541 if ( ! getObjectMeta().isFolderParent( meta ) )
01542 {
01543 MON::Exception exc( "? cannot be parent of ?!");
01544 exc << meta.infoString() << getObjectMeta().infoString();
01545 ASSERTTHROW( exc );
01546 }
01547
01548 return getParentFolder( meta );
01549 }
01550
01551
01552
01553
01554 void ObjectImpl::accept( Visitor* pVisitor )
01555 {
01556 if ( getStereotype() == OT_Folder )
01557 ( (FolderImpl*) this)->accept( pVisitor );
01558 else
01559 ( (FCOImpl*) this)->accept( pVisitor );
01560 }
01561
01562
01563
01564
01565
01566
01567
01568 RegistryNodeImpl::RegistryNodeImpl( IMgaRegNode* spNode, ObjectImpl* pObject )
01569 : Util::GenRefCounted( !_isAddOn(), pObject ), m_spNode( spNode ), m_pObject( pObject )
01570 {
01571 pObject->m_mapNodes.insert( ObjectImpl::RegistryMap::value_type( spNode, this ) );
01572 }
01573
01574 RegistryNodeImpl* RegistryNodeImpl::attachI( IMgaRegNode* spNode, ObjectImpl* pObject )
01575 {
01576 if ( spNode )
01577 return new RegistryNodeImpl( spNode, pObject );
01578 switch ( pObject->getStereotype() ) {
01579 case OT_Folder : return new RegistryNodeImpl( NULL, pObject );
01580 case OT_Model : return new ModelRegistryNodeImpl( dynamic_cast<ModelImpl*>( pObject ) );
01581 case OT_Connection : return new ConnectionRegistryNodeImpl( dynamic_cast<ConnectionImpl*>( pObject ) );
01582 default : return new FCOExRegistryNodeImpl( (FCOImpl*) pObject );
01583 }
01584 }
01585
01586 RegistryNodeImpl::~RegistryNodeImpl()
01587 {
01588 if ( ! m_pObject->isDestructionActive() && ! isDeleted() )
01589 m_pObject->m_mapNodes.erase( getRegNodeI() );
01590
01591 m_pObject = NULL;
01592 m_spNode = NULL;
01593 }
01594
01595 bool RegistryNodeImpl::setDeleted()
01596 {
01597 { using namespace Util; if ( GenRefCounted::setDeleted() ) return true; }
01598
01599 m_pObject->m_mapNodes.erase( getRegNodeI() );
01600 return false;
01601 }
01602
01603
01604
01605
01606 Project RegistryNodeImpl::getProject() const
01607 {
01608 return m_pObject->getProject();
01609 }
01610
01611 Object RegistryNodeImpl::getObject() const
01612 {
01613 return m_pObject;
01614 }
01615
01616 RegNodePtr RegistryNodeImpl::getRegNodeI() const
01617 {
01618 return m_spNode;
01619 }
01620
01621 bool RegistryNodeImpl::isRootNode() const
01622 {
01623 return ( m_spNode ) ? false : true;
01624 }
01625
01626 std::string RegistryNodeImpl::getName() const
01627 {
01628 if ( m_spNode ) {
01629 CComBSTR bstrName;
01630 COMCHECK2( m_spNode, m_spNode->get_Name( &bstrName ) );
01631 return Util::Copy( bstrName );
01632 }
01633 return "";
01634 }
01635
01636 std::string RegistryNodeImpl::getPath() const
01637 {
01638 if ( m_spNode ) {
01639 CComBSTR bstrName;
01640 COMCHECK2( m_spNode, m_spNode->get_Path( &bstrName ) );
01641 return "/" + Util::Copy( bstrName );
01642 }
01643 return "/";
01644 }
01645
01646 RegistryNodeStatus RegistryNodeImpl::getStatus() const
01647 {
01648 if ( m_spNode ) {
01649 long lStatus;
01650 COMCHECK2( m_spNode, m_spNode->get_Status( &lStatus ) );
01651 return lStatus;
01652 }
01653 return RNS_Undefined;
01654 }
01655
01656 std::string RegistryNodeImpl::getValue() const
01657 {
01658 if ( m_spNode ) {
01659 CComBSTR bstrValue;
01660 COMCHECK2( m_spNode, m_spNode->get_Value( &bstrValue ) );
01661 return Util::Copy( bstrValue );
01662 }
01663 return "";
01664 }
01665
01666 void RegistryNodeImpl::setValue( const std::string& strValue )
01667 {
01668 if ( m_spNode ) {
01669 COMCHECK2( m_spNode, m_spNode->put_Value( Util::Copy( strValue ) ) );
01670 if ( getProject()->isAutoCommit() )
01671 getProject()->commit();
01672 }
01673 }
01674
01675 long RegistryNodeImpl::getIntegerValue() const
01676 {
01677 long ret = (long) Util::Variant( getValue() );
01678 return ret;
01679 }
01680
01681 void RegistryNodeImpl::setIntegerValue( long lValue )
01682 {
01683 setValue( (std::string) Util::Variant( lValue ) );
01684 }
01685
01686 double RegistryNodeImpl::getRealValue() const
01687 {
01688 return (double) Util::Variant( getValue() );
01689 }
01690
01691 void RegistryNodeImpl::setRealValue( double dValue )
01692 {
01693 setValue( (std::string) Util::Variant( dValue ) );
01694 }
01695
01696 bool RegistryNodeImpl::getBoolValue() const
01697 {
01698 return (bool) Util::Variant( getValue() );
01699 }
01700
01701 void RegistryNodeImpl::setBoolValue( bool bValue )
01702 {
01703 setValue( (std::string) Util::Variant( bValue ) );
01704 }
01705
01706 void RegistryNodeImpl::clear()
01707 {
01708 if ( m_spNode ) {
01709 COMCHECK2( m_spNode, m_spNode->Clear() );
01710 }
01711 }
01712
01713 std::string RegistryNodeImpl::getValueByPath( const std::string& strPath ) const
01714 {
01715 std::string strPath2 = getPath().substr( 1 ) + strPath;
01716
01717 CComBSTR bstrValue;
01718 CComQIPtr<IMgaFCO> spFCO = m_pObject->getObjectI();
01719 if ( spFCO ) {
01720 COMCHECK2( spFCO, spFCO->get_RegistryValue( Util::Copy( strPath2 ), &bstrValue ) );
01721 }
01722 else {
01723 CComQIPtr<IMgaFolder> spFolder = m_pObject->getObjectI();
01724 COMCHECK2( spFolder, spFolder->get_RegistryValue( Util::Copy( strPath2 ), &bstrValue ) );
01725 }
01726
01727 return Util::Copy( bstrValue );
01728 }
01729
01730 void RegistryNodeImpl::setValueByPath( const std::string& strPath, const std::string& strValue )
01731 {
01732 std::string strPath2 = getPath().substr( 1 ) + strPath;
01733 if ( ! m_spNode )
01734 strPath2 = strPath2.substr( 1 );
01735
01736 CComQIPtr<IMgaFCO> spFCO = m_pObject->getObjectI();
01737 if ( spFCO ) {
01738 COMCHECK2( spFCO, spFCO->put_RegistryValue( Util::Copy( strPath2 ), Util::Copy( strValue ) ) );
01739 }
01740 else {
01741 CComQIPtr<IMgaFolder> spFolder = m_pObject->getObjectI();
01742 COMCHECK2( spFolder, spFolder->put_RegistryValue( Util::Copy( strPath2 ), Util::Copy( strValue ) ) );
01743 }
01744 if ( getProject()->isAutoCommit() )
01745 getProject()->commit();
01746 }
01747
01748
01749
01750
01751 RegistryNode RegistryNodeImpl::getParent() const
01752 {
01753 if ( m_spNode ) {
01754 RegNodePtr spNode;
01755 COMCHECK2( m_spNode, m_spNode->get_ParentNode( spNode.Addr() ) );
01756 return attachI( spNode, m_pObject );
01757 }
01758 return NULL;
01759 }
01760
01761 std::set<RegistryNode> RegistryNodeImpl::getChildren( bool bVirtualsAlso ) const
01762 {
01763 std::set<RegistryNode> setNodes;
01764 Util::ComPtr<IMgaRegNodes> spNodes;
01765
01766 if ( m_spNode ) {
01767 COMCHECK2( m_spNode, m_spNode->get_SubNodes( ( bVirtualsAlso ) ? VARIANT_TRUE : VARIANT_FALSE, spNodes.Addr() ) );
01768 }
01769 else {
01770 CComQIPtr<IMgaFCO> spFCO = m_pObject->getObjectI();
01771 if ( spFCO ) {
01772 COMCHECK2( spFCO, spFCO->get_Registry( ( bVirtualsAlso ) ? VARIANT_TRUE : VARIANT_FALSE, spNodes.Addr() ) );
01773 }
01774 else {
01775 CComQIPtr<IMgaFolder> spFolder = m_pObject->getObjectI();
01776 COMCHECK2( spFolder, spFolder->get_Registry( ( bVirtualsAlso ) ? VARIANT_TRUE : VARIANT_FALSE, spNodes.Addr() ) );
01777 }
01778 }
01779
01780 if ( spNodes ) {
01781 MGACOLL_ITERATE( IMgaRegNode, spNodes.p ) {
01782 setNodes.insert( attachI( MGACOLL_ITER, m_pObject ) );
01783 } MGACOLL_ITERATE_END;
01784 }
01785 return setNodes;
01786 }
01787
01788 RegistryNode RegistryNodeImpl::getChild( const std::string& strName ) const
01789 {
01790 RegNodePtr spNode;
01791 if ( m_spNode ) {
01792 COMCHECK2( m_spNode, m_spNode->get_SubNodeByName( Util::Copy( strName ), spNode.Addr() ) );
01793 }
01794 else {
01795 CComQIPtr<IMgaFCO> spFCO = m_pObject->getObjectI();
01796 if ( spFCO ) {
01797 COMCHECK2( spFCO, spFCO->get_RegistryNode( Util::Copy( strName ), spNode.Addr() ) );
01798 }
01799 else {
01800 CComQIPtr<IMgaFolder> spFolder = m_pObject->getObjectI();
01801 COMCHECK2( spFolder, spFolder->get_RegistryNode( Util::Copy( strName ), spNode.Addr() ) );
01802 }
01803 }
01804 return ( spNode ) ? attachI( spNode, m_pObject ) : NULL;
01805 }
01806
01807 void RegistryNodeImpl::removeTree()
01808 {
01809 if ( m_spNode ) {
01810 COMCHECK2( m_spNode, m_spNode->RemoveTree() );
01811 return;
01812 }
01813
01814 Util::ComPtr<IMgaRegNodes> spNodes;
01815 CComQIPtr<IMgaFCO> spFCO = m_pObject->getObjectI();
01816 if ( spFCO ) {
01817 COMCHECK2( spFCO, spFCO->get_Registry( VARIANT_FALSE, spNodes.Addr() ) );
01818 }
01819 else {
01820 CComQIPtr<IMgaFolder> spFolder = m_pObject->getObjectI();
01821 COMCHECK2( spFolder, spFolder->get_Registry( VARIANT_FALSE, spNodes.Addr() ) );
01822 }
01823
01824 if ( spNodes ) {
01825 MGACOLL_ITERATE( IMgaRegNode, spNodes.p ) {
01826 COMCHECK2( MGACOLL_ITER, MGACOLL_ITER->RemoveTree() );
01827 } MGACOLL_ITERATE_END;
01828 }
01829 if ( getProject()->isAutoCommit() )
01830 getProject()->commit();
01831 }
01832
01833 RegistryNode RegistryNodeImpl::getDescendantByPath( const std::string& strPath ) const
01834 {
01835 std::string strPath2 = strPath;
01836 if ( m_spNode )
01837 strPath2 = getPath().substr( 1 ) + strPath;
01838
01839 RegNodePtr spNode;
01840 CComQIPtr<IMgaFCO> spFCO = m_pObject->getObjectI();
01841 if ( spFCO ) {
01842 COMCHECK2( spFCO, spFCO->get_RegistryNode( Util::Copy( strPath2 ), spNode.Addr() ) );
01843 }
01844 else {
01845 CComQIPtr<IMgaFolder> spFolder = m_pObject->getObjectI();
01846 COMCHECK2( spFolder, spFolder->get_RegistryNode( Util::Copy( strPath2 ), spNode.Addr() ) );
01847 }
01848
01849 return ( spNode ) ? attachI( spNode, m_pObject ) : NULL;
01850 }
01851
01852
01853
01854
01855
01856
01857
01858 FolderImpl::FolderImpl()
01859 : ObjectImpl(), m_bAllChildObjects( false )
01860 {
01861 }
01862
01863 FolderImpl* FolderImpl::attachI( IMgaFolder* spFolder, ProjectImpl* pProject, const MON::Object& meta )
01864 {
01865
01866 if ( ! spFolder )
01867 return NULL;
01868
01869
01870 pProject = _getProject( spFolder, pProject );
01871 ObjectImpl* pObject = find( pProject, spFolder );
01872 if ( pObject )
01873 return (FolderImpl*) pObject;
01874
01875
01876 pObject = getEx( spFolder, OT_Folder, meta );
01877 if ( ! pObject )
01878 pObject = new FolderImpl();
01879 pObject->doInitialize( spFolder, pProject, meta );
01880 pObject->initialize();
01881 return (FolderImpl*) pObject;
01882 }
01883
01884 FolderImpl::~FolderImpl()
01885 {
01886 if ( ! m_pProject->isDestructionActive() && ! isDeleted() ) {
01887 for ( ManyObjectLink::iterator it1 = m_childObjects.begin() ; it1 != m_childObjects.end() ; it1++ )
01888 for ( ObjectSet::iterator it2 = it1->second.second.begin() ; it2 != it1->second.second.end() ; it2++ )
01889 (*it2)->onReleasedAsFolderChild( this, true );
01890 }
01891 m_childObjects.clear();
01892 }
01893
01894 bool FolderImpl::setDeleted()
01895 {
01896 if ( ObjectImpl::setDeleted() )
01897 return true;
01898 if ( ! _isAddOn() ) {
01899 for ( ManyObjectLink::iterator it1 = m_childObjects.begin() ; it1 != m_childObjects.end() ; it1++ )
01900 for ( ObjectSet::iterator it2 = it1->second.second.begin() ; it2 != it1->second.second.end() ; it2++ )
01901 (*it2)->setDeleted();
01902 }
01903 return false;
01904 }
01905
01906 Folder FolderImpl::attach( IMgaFolder* spFolder )
01907 {
01908 return attachI( spFolder );
01909 }
01910
01911 Folder FolderImpl::create( const Folder& parent, const MON::Folder& meta )
01912 {
01913 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
01914 return parent->createChildObjectI( meta, MON::OT_Folder );
01915 }
01916
01917 Folder FolderImpl::create( const Folder& parent, const std::string& strFolder )
01918 {
01919 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
01920 MON::Folder meta;
01921 if ( ! strFolder.empty() ) {
01922 meta = parent->getProject()->getProjectMeta().findByName( strFolder );
01923 if ( ! meta )
01924 {
01925 MON::Exception exc( "MON::Folder [ ? ] does not exist in ? of ?!");
01926 exc << strFolder.c_str() << parent->getProject()->getProjectMeta().infoString().c_str() << parent->getProject()->getInfoString().c_str();
01927 ASSERTTHROW( exc);
01928 }
01929 }
01930 return create( parent, meta );
01931 }
01932
01933
01934
01935
01936 ObjectType FolderImpl::getStereotype() const
01937 {
01938 return OT_Folder;
01939 }
01940
01941 FolderPtr FolderImpl::getFolderI() const
01942 {
01943 CComQIPtr<IMgaFolder> spFolder = getObjectI().p;
01944 return spFolder.p;
01945 }
01946
01947 MON::Folder FolderImpl::getFolderMeta() const
01948 {
01949 return getObjectMeta();
01950 }
01951
01952 std::string FolderImpl::getInfoString( unsigned short usOptions ) const
01953 {
01954 bool bAll = ( usOptions & Util::IO_All ) ? true : false;
01955 bool bLine = bAll || ( usOptions & Util::IO_NewLine );
01956
01957 std::string strInfo = getInfoStringHelper( usOptions, "Folder" );
01958 if ( ! ( usOptions & Util::IO_NewLine ) && ! ( usOptions & Util::IO_All ) )
01959 strInfo += "]";
01960
01961 return strInfo;
01962 }
01963
01964
01965
01966
01967 bool FolderImpl::isChildObjectsRetrieved( const MON::Object& meta )
01968 {
01969 ManyObjectLink::iterator it = m_childObjects.find( meta );
01970 if ( it != m_childObjects.end() ) {
01971 if ( it->second.first )
01972 return true;
01973 it->second.first = true;
01974 return false;
01975 }
01976 m_childObjects[ meta ] = ObjectSetPair( true, ObjectSet() );
01977 return false;
01978 }
01979
01980 void FolderImpl::getChildFolders( std::set<ObjectPtr>& setSPFolders )
01981 {
01982 Util::ComPtr<IMgaFolders> spFolders;
01983 COMCHECK2( getFolderI(), getFolderI()->get_ChildFolders( spFolders.Addr() ) );
01984 MGACOLL_ITERATE( IMgaFolder, spFolders.p ) {
01985 setSPFolders.insert( MGACOLL_ITER.p );
01986 } MGACOLL_ITERATE_END;
01987 }
01988
01989 void FolderImpl::getRootFCOs( std::set<ObjectPtr>& setSPFCOs )
01990 {
01991 Util::ComPtr<IMgaFCOs> spFCOs;
01992 COMCHECK2( getFolderI(), getFolderI()->get_ChildFCOs( spFCOs.Addr() ) );
01993 MGACOLL_ITERATE( IMgaFCO, spFCOs.p ) {
01994 setSPFCOs.insert( MGACOLL_ITER.p );
01995 } MGACOLL_ITERATE_END;
01996 }
01997
01998 void FolderImpl::getChildObjects( const MON::Object& meta, std::set<ObjectPtr>& setSPObjects, bool bErase )
01999 {
02000 std::set<ObjectPtr>::iterator it = setSPObjects.begin();
02001 while ( it != setSPObjects.end() ) {
02002 std::set<ObjectPtr>::iterator itSaved = it;
02003 it++;
02004 if ( _getMetaRef( *itSaved ) == meta.ref() ) {
02005 ObjectImpl* pObject = ObjectImpl::attachI( *itSaved, m_pProject, meta );
02006 if ( m_childObjects[ meta ].second.find( pObject ) == m_childObjects[ meta ].second.end() ) {
02007 m_childObjects[ meta ].second.insert( pObject );
02008 pObject->onRetrievedAsFolderChild( this, false );
02009 }
02010 if ( bErase )
02011 setSPObjects.erase( itSaved );
02012 }
02013 }
02014 }
02015
02016 ObjectSet FolderImpl::getChildObjectsI( const MON::Object& meta )
02017 {
02018 if ( meta ) {
02019 if ( ! isChildObjectsRetrieved( meta ) ) {
02020 std::set<ObjectPtr> setSPObjects;
02021 if ( meta.type() == OT_Folder )
02022 getChildFolders( setSPObjects);
02023 else
02024 getRootFCOs( setSPObjects );
02025 getChildObjects( meta, setSPObjects, false );
02026 }
02027 return m_childObjects[ meta ].second;
02028 }
02029
02030 if ( ! m_bAllChildObjects ) {
02031 m_bAllChildObjects = true;
02032 std::set<ObjectPtr> setSPFolders;
02033 getChildFolders( setSPFolders );
02034 std::set<ObjectPtr> setSPFCOs;
02035 getRootFCOs( setSPFCOs );
02036 std::set<MON::Object> setMetas = getFolderMeta().childObjects();
02037 for ( std::set<MON::Object>::iterator it = setMetas.begin() ; it != setMetas.end() ; it++ ) {
02038 if ( ! isChildObjectsRetrieved( *it ) )
02039 getChildObjects( *it, ( it->type() == OT_Folder ) ? setSPFolders : setSPFCOs, true );
02040 }
02041 }
02042
02043 ObjectSet setObjects;
02044 for ( ManyObjectLink::iterator it = m_childObjects.begin() ; it != m_childObjects.end() ; it++ )
02045 setObjects.insert( it->second.second.begin(), it->second.second.end() );
02046 return setObjects;
02047 }
02048
02049 ObjectImpl* FolderImpl::createChildObjectI( const MON::Object& meta, MON::ObjectType eType )
02050 {
02051 MON::Object objectMeta;
02052 if ( ! meta ) {
02053 std::set<MON::Object> metas = getFolderMeta().childObjects();
02054 for ( std::set<MON::Object>::iterator it = metas.begin() ; it != metas.end() ; it++ ) {
02055 if ( it->type() == eType ) {
02056 if ( objectMeta )
02057 {
02058 MON::Exception exc( "? cannot be null because ? can contain more than one ? as child!");
02059 exc << toString( eType ).c_str() << getObjectMeta().infoString().c_str() << toString( eType ).c_str();
02060 ASSERTTHROW( exc);
02061 }
02062 objectMeta = *it;
02063 }
02064 }
02065 if ( ! objectMeta )
02066 {
02067 MON::Exception exc( "? does not have ? as child!");
02068 exc << getObjectMeta().infoString().c_str() << toString( eType ).c_str();
02069 ASSERTTHROW( exc);
02070 }
02071 }
02072 else {
02073 THROW_METAPROJECT_BELONG( meta );
02074 if ( ! getFolderMeta().isObjectChild( meta ) )
02075 {
02076 MON::Exception exc( "? does not have ? as child!");
02077 exc << getObjectMeta().infoString().c_str() << meta.infoString().c_str();
02078 ASSERTTHROW( exc);
02079 }
02080 objectMeta = meta;
02081 }
02082
02083 if ( eType == MON::OT_Folder ) {
02084 FolderPtr spFolder;
02085 COMCHECK2( getFolderI(), getFolderI()->CreateFolder( MON::Folder( objectMeta ).getFolderI(), spFolder.Addr() ) );
02086 FolderImpl* pFolder = FolderImpl::attachI( spFolder, (ProjectImpl*) getProject().getCounted(), objectMeta );
02087 if ( ! _isAddOn() )
02088 pFolder->eventPerformedI( Event( MON::OET_ObjectCreated, pFolder ) );
02089 return pFolder;
02090 }
02091 FCOPtr spFCO;
02092 COMCHECK2( getFolderI(), getFolderI()->CreateRootObject( MON::FCO( objectMeta ).getFCOI(), spFCO.Addr() ) );
02093 FCOImpl* pFCO = FCOImpl::attachI( spFCO, (ProjectImpl*) getProject().getCounted(), objectMeta );
02094 if ( getProject()->isAutoCommit() )
02095 getProject()->commit();
02096 if ( ! _isAddOn() )
02097 pFCO->eventPerformedI( Event( MON::OET_ObjectCreated, pFCO ) );
02098 return pFCO;
02099
02100 }
02101
02102 FCOImpl* FolderImpl::createChildFCOI( const FCO& fco, bool bAsInstance, MON::ObjectType eType )
02103 {
02104 THROW_CANNOT_BE_NULL( fco, "MON::" + toString( eType, false ) );
02105 THROW_PROJECT_BELONG( fco );
02106 if ( ! getFolderMeta().isObjectChild( fco->getObjectMeta() ) )
02107 {
02108 MON::Exception exc( "? does not have ? as child!");
02109 exc << getObjectMeta().infoString() << fco->getObjectMeta().infoString();
02110 ASSERTTHROW( exc);
02111 }
02112
02113 FCOPtr spFCO;
02114 COMCHECK2( getFolderI(), getFolderI()->DeriveRootObject( fco->getFCOI(), ( bAsInstance ) ? VARIANT_TRUE : VARIANT_FALSE, spFCO.Addr() ) );
02115 FCOImpl* pFCO = FCOImpl::attachI( spFCO, (ProjectImpl*) getProject().getCounted(), fco->getFCOMeta() );
02116 if ( getProject()->isAutoCommit() )
02117 getProject()->commit();
02118 if ( ! _isAddOn() ) {
02119 pFCO->eventPerformedI( Event( MON::OET_ObjectCreated, pFCO ) );
02120 fco->eventPerformedI( Event( MON::OET_DescendantCreated, fco ) );
02121 }
02122 return pFCO;
02123 }
02124
02125
02126
02127
02128 bool FolderImpl::onRetrievedAsObjectParent( ObjectImpl* pObject, bool bCheckAll )
02129 {
02130 ManyObjectLink::iterator it = m_childObjects.find( pObject->getObjectMeta() );
02131 if ( it == m_childObjects.end() ) {
02132 if ( bCheckAll )
02133 return false;
02134 m_childObjects[ pObject->getObjectMeta() ] = ObjectSetPair( false, ObjectSet() );
02135 }
02136 if ( ! bCheckAll || bCheckAll && m_childObjects[ pObject->getObjectMeta() ].first ) {
02137 m_childObjects[ pObject->getObjectMeta() ].second.insert( pObject );
02138 return true;
02139 }
02140 return false;
02141 }
02142
02143 void FolderImpl::onReleasedAsObjectParent( ObjectImpl* pObject, bool bOnlyMemoryFree )
02144 {
02145 ManyObjectLink::iterator it = m_childObjects.find( pObject->getObjectMeta() );
02146 if ( it != m_childObjects.end() ) {
02147 m_childObjects[ pObject->getObjectMeta() ].second.erase( pObject );
02148 if ( bOnlyMemoryFree && m_childObjects[ pObject->getObjectMeta() ].first ) {
02149 m_childObjects[ pObject->getObjectMeta() ].first = false;
02150 m_bAllChildObjects = false;
02151 }
02152 }
02153 }
02154
02155 void FolderImpl::eventPerformedI( const Event& event )
02156 {
02157 ObjectImpl::eventPerformedI( event );
02158 switch ( event.getType() ) {
02159 case MON::OET_ChildAdded :
02160 onChildAdded( NULL );
02161 break;
02162 case MON::OET_ChildLost :
02163 onChildRemoved( NULL );
02164 break;
02165 }
02166 }
02167
02168 void FolderImpl::onChildAdded( ObjectImpl* pChild )
02169 {
02170 if ( pChild ) {
02171 if ( onRetrievedAsObjectParent( pChild, true ) )
02172 pChild->onRetrievedAsFolderChild( this, false );
02173 }
02174 }
02175
02176 void FolderImpl::onChildRemoved( ObjectImpl* pChild )
02177 {
02178 if ( pChild ) {
02179 onReleasedAsObjectParent( pChild, false );
02180 pChild->onReleasedAsFolderChild( this, false );
02181 }
02182 }
02183
02184
02185
02186
02187 std::set<Object> FolderImpl::getChildObjects( const MON::Object& meta )
02188 {
02189 if ( meta ) {
02190 THROW_METAPROJECT_BELONG( meta );
02191 if ( meta.type() < MON::OT_Model || meta.type() > MON::OT_Folder )
02192 {
02193 Exception exc( "Type of ? can be only MON::Folder or MON::FCO!");
02194 exc << meta.infoString().c_str();
02195 ASSERTTHROW( exc);
02196 }
02197 if ( ! getFolderMeta().isObjectChild( meta ) )
02198 {
02199 MON::Exception exc( "? cannot be child of ?!");
02200 exc << meta.infoString().c_str() << getObjectMeta().infoString().c_str();
02201 ASSERTTHROW( exc);
02202 }
02203 }
02204
02205 std::set<Object> setResult;
02206 setCopy<Object,ObjectImpl>( getChildObjectsI( meta ), setResult );
02207 return setResult;
02208 }
02209
02210 std::set<Object> FolderImpl::getChildObjects( const std::string& strObject )
02211 {
02212 MON::Object meta;
02213 if ( ! strObject.empty() ) {
02214 meta = getProject()->getProjectMeta().findByName( strObject );
02215 if ( ! meta || meta.type() < MON::OT_Model || meta.type() > MON::OT_Folder )
02216 {
02217 MON::Exception exc( "MON::Folder or MON::FCO [ ? ] does not exist in ? of ?!");
02218 exc << strObject.c_str() << getProject()->getProjectMeta().infoString().c_str() << getProject()->getInfoString().c_str();
02219 ASSERTTHROW( exc);
02220 }
02221 }
02222 return getChildObjects( meta );
02223 }
02224
02225 std::set<Folder> FolderImpl::getChildFolders()
02226 {
02227 std::set<Folder> setResult;
02228 std::set<MON::Folder> set = getFolderMeta().childFolders();
02229 for ( std::set<MON::Folder>::iterator it = set.begin() ; it != set.end() ; ++it )
02230 setCastCopy<Folder,ObjectImpl,FolderImpl>( getChildObjectsI( *it ), setResult );
02231 return setResult;
02232 }
02233
02234 std::set<FCO> FolderImpl::getRootFCOs()
02235 {
02236 std::set<FCO> setResult;
02237 std::set<MON::FCO> set = getFolderMeta().childFCOs();
02238 for ( std::set<MON::FCO>::iterator it = set.begin() ; it != set.end() ; ++it )
02239 setCastCopy<FCO,ObjectImpl,FCOImpl>( getChildObjectsI( *it ), setResult );
02240 return setResult;
02241 }
02242
02243 std::set<Atom> FolderImpl::getChildAtoms()
02244 {
02245 std::set<Atom> setResult;
02246 std::set<MON::Atom> set = getFolderMeta().childAtoms();
02247 for ( std::set<MON::Atom>::iterator it = set.begin() ; it != set.end() ; ++it )
02248 setCastCopy<Atom,ObjectImpl,AtomImpl>( getChildObjectsI( *it ), setResult );
02249 return setResult;
02250 }
02251
02252 std::set<Model> FolderImpl::getChildModels()
02253 {
02254 std::set<Model> setResult;
02255 std::set<MON::Model> set = getFolderMeta().childModels();
02256 for ( std::set<MON::Model>::iterator it = set.begin() ; it != set.end() ; ++it )
02257 setCastCopy<Model,ObjectImpl,ModelImpl>( getChildObjectsI( *it ), setResult );
02258 return setResult;
02259 }
02260
02261 Object FolderImpl::findByPath( const std::string& strPath, const std::string& strDelimiter, bool bReverseOrder )
02262 {
02263 std::string strPath2;
02264 std::string strName;
02265 size_t iPos = ( bReverseOrder ) ? strPath.rfind( strDelimiter ) : strPath.find( strDelimiter );
02266 if ( iPos == std::string::npos ) {
02267 strName = strPath;
02268 strPath2 = "";
02269 }
02270 else {
02271 if ( bReverseOrder && iPos + strDelimiter.length() == strPath.length() )
02272 strPath2 = strPath.substr( 0, iPos );
02273 if ( ! bReverseOrder && iPos == 0 )
02274 strPath2 = strPath.substr( iPos + strDelimiter.length() );
02275 iPos = ( bReverseOrder ) ? strPath2.rfind( strDelimiter ) : strPath2.find( strDelimiter );
02276 if ( iPos == std::string::npos ) {
02277 strName = strPath2;
02278 strPath2 = "";
02279 }
02280 else {
02281 strName = ( bReverseOrder ) ? strPath2.substr( iPos ) : strPath2.substr( 0, iPos );
02282 strPath2 = ( bReverseOrder ) ? strPath2.substr( 0, iPos ) : strPath2.substr( iPos );
02283 }
02284 }
02285
02286 std::set<Object> objects = getChildObjects();
02287 for ( std::set<Object>::iterator it = objects.begin() ; it != objects.end() ; it++ )
02288 if ( strName == (*it)->getName() ) {
02289 if ( strPath2.empty() )
02290 return *it;
02291 else {
02292 if ( (*it)->getStereotype() == OT_Model ) {
02293 FCO o = Model( *it )->findByPath( strPath2, strDelimiter, bReverseOrder );
02294 if ( o )
02295 return o;
02296 }
02297 if ( (*it)->getStereotype() == OT_Folder ) {
02298 Object o = Folder( *it )->findByPath( strPath2, strDelimiter, bReverseOrder );
02299 if ( o )
02300 return o;
02301 }
02302 }
02303 }
02304 return NULL;
02305 }
02306
02307
02308
02309
02310 void FolderImpl::accept( Visitor* pVisitor )
02311 {
02312 ObjectSet children = getChildObjectsI();
02313 for ( ObjectSet::iterator it = children.begin() ; it != children.end() ; it++ )
02314 (*it)->accept( pVisitor );
02315 pVisitor->visitFolder( Folder( this ) );
02316 }
02317
02318
02319
02320
02321
02322
02323
02324 ConnectionEndImpl::ConnectionEndImpl()
02325 : m_bAllConnections( false ), m_pProject( NULL )
02326 {
02327 }
02328
02329 ConnectionEndImpl* ConnectionEndImpl::attachI( IMgaConnPoint* spCP, ProjectImpl* pProject, const MON::Object& meta )
02330 {
02331 FCOPtr spTarget;
02332 COMCHECK2( spCP, spCP->get_Target( spTarget.Addr() ) );
02333 FCOImpl* pTarget = FCOImpl::attachI( spTarget, pProject, meta );
02334
02335 Util::ComPtr<IMgaFCOs> spRefs;
02336 COMCHECK2( spCP, spCP->get_References( spRefs.Addr() ) );
02337
02338 long lCount;
02339 COMCHECK2( spRefs, spRefs->get_Count( &lCount ) );
02340 if ( lCount == 0 )
02341 return pTarget;
02342
02343 FCOPtr spRefFirst;
02344 COMCHECK2( spRefs, spRefs->get_Item( 1, spRefFirst.Addr() ) );
02345 FCOPtr spRefLast;
02346 COMCHECK2( spRefs, spRefs->get_Item( lCount, spRefLast.Addr() ) );
02347
02348 CComQIPtr<IMgaReference> spRef = spRefLast;
02349 FCOPtr spRefTarget;
02350 COMCHECK2( spRef, spRef->get_Referred( spRefTarget.Addr() ) );
02351 if ( spRefTarget == spTarget )
02352 return FCOImpl::attachI( spRefFirst, pProject );
02353
02354 return dynamic_cast<ReferenceImpl*>( FCOImpl::attachI( spRefFirst, pProject ) )->getRefPort( pTarget );
02355 }
02356
02357 ConnectionEndImpl::~ConnectionEndImpl()
02358 {
02359 if ( ! m_pProject->isDestructionActive() && ! isDeleted() ) {
02360 for ( ManyConnectionLink::iterator it = m_connections.begin() ; it != m_connections.end() ; it++ )
02361 for ( ConnectionSet::iterator it2 = it->second.second.begin() ; it2 != it->second.second.end() ; it2++ )
02362 (*it2)->onReleasedAsConnection( this, it->first.first, true );
02363 }
02364
02365 m_connections.clear();
02366 m_pProject = NULL;
02367 }
02368
02369 bool ConnectionEndImpl::setDeleted()
02370 {
02371 bool bRet = GenRefCounted::setDeleted();
02372
02373 for ( ManyConnectionLink::iterator it = m_connections.begin() ; it != m_connections.end() ; it++ )
02374 for ( ConnectionSet::iterator it2 = it->second.second.begin() ; it2 != it->second.second.end() ; it2++ )
02375 (*it2)->setDeleted();
02376 m_connections.clear();
02377
02378 return bRet;
02379 }
02380
02381 void ConnectionEndImpl::setProject( ProjectImpl* pProject )
02382 {
02383 m_pProject = pProject;
02384 }
02385
02386
02387
02388
02389 Project ConnectionEndImpl::getProject() const
02390 {
02391 return m_pProject;
02392 }
02393
02394 std::string ConnectionEndImpl::getInfoString( const std::set<Util::InfoOption>& setOptions ) const
02395 {
02396 return getInfoString( copy( setOptions ) );
02397 }
02398
02399
02400
02401
02402 bool ConnectionEndImpl::isConnectionsRetrieved( const MON::ConnectionEnd::Pair& meta )
02403 {
02404 ManyConnectionLink::iterator it = m_connections.find( meta );
02405 if ( it != m_connections.end() ) {
02406 if ( it->second.first )
02407 return true;
02408 it->second.first = true;
02409 return false;
02410 }
02411 m_connections[ meta ] = ConnectionSetPair( true, ConnectionSet() );
02412 return false;
02413 }
02414
02415 void ConnectionEndImpl::getConnections( std::set<ConnPointPtr>& setSPConnPoints )
02416 {
02417 Util::ComPtr<IMgaConnPoints> spCPs;
02418 COMCHECK2( getFCOHelper()->getFCOI(), getFCOHelper()->getFCOI()->get_PartOfConns( spCPs.Addr() ) );
02419 MGACOLL_ITERATE( IMgaConnPoint, spCPs.p ) {
02420 setSPConnPoints.insert( MGACOLL_ITER );
02421 } MGACOLL_ITERATE_END;
02422 }
02423
02424 void ConnectionEndImpl::getConnections( const MON::ConnectionEnd::Pair& meta, std::set<ConnPointPtr>& setSPConnPoints, bool bErase )
02425 {
02426 std::set<ConnPointPtr>::iterator it = setSPConnPoints.begin();
02427 while ( it != setSPConnPoints.end() ) {
02428 std::set<ConnPointPtr>::iterator itSaved = it;
02429 it++;
02430 CComBSTR bstrRole;
02431 COMCHECK2( (*itSaved), (*itSaved)->get_ConnRole( &bstrRole ) );
02432 if ( Util::Copy( bstrRole ) == meta.first ) {
02433 ConnectionPtr spConnection;
02434 COMCHECK2( (*itSaved), (*itSaved)->get_Owner( spConnection.Addr() ) );
02435 if ( _getMetaRef( spConnection ) == meta.second.ref() ) {
02436 ConnectionEndImpl* pEnd = ConnectionEndImpl::attachI( *itSaved, m_pProject );
02437 pEnd->isConnectionsRetrieved( meta );
02438 ConnectionImpl* pConnection = ConnectionImpl::attachI( spConnection, m_pProject, meta.second );
02439 if ( pEnd->m_connections[ meta ].second.find( pConnection ) == pEnd->m_connections[ meta ].second.end() ) {
02440 pEnd->m_connections[ meta ].second.insert( pConnection );
02441 pConnection->onRetrievedAsConnection( pEnd, meta.first, false );
02442 }
02443 if ( bErase )
02444 setSPConnPoints.erase( itSaved );
02445 }
02446 }
02447 }
02448 }
02449
02450 ConnectionSet ConnectionEndImpl::getConnectionsI( const std::string& strRole, const MON::Connection& meta, bool bOnlyCE )
02451 {
02452 std::set<ConnectionEndImpl*> CEs;
02453 if ( ! bOnlyCE ) {
02454 CEs.insert( this );
02455 if ( isReferencePort() ) {
02456 std::set<ReferencePort> ports = ( (ReferencePortImpl*) this )->getDescendantPorts();
02457 for ( std::set<ReferencePort>::iterator it = ports.begin() ; it != ports.end() ; it++ )
02458 CEs.insert( dynamic_cast<ConnectionEndImpl*> ( it->getCounted() ) );
02459 }
02460 else {
02461 ReferencePortSet ports = ( (FCOImpl*) this )->getRefPortRefsI();
02462 CEs.insert( ports.begin(), ports.end() );
02463 }
02464 }
02465
02466 if ( ! strRole.empty() && meta ) {
02467 MON::ConnectionEnd::Pair metaRole( strRole, meta );
02468 if ( ! isConnectionsRetrieved( metaRole ) ) {
02469 std::set<ConnPointPtr> setSPConnPoints;
02470 getConnections( setSPConnPoints );
02471 getConnections( metaRole, setSPConnPoints, false );
02472 }
02473 if ( bOnlyCE )
02474 return m_connections[ metaRole ].second;
02475
02476
02477 ConnectionSet setOut;
02478 for ( std::set<ConnectionEndImpl*>::iterator it = CEs.begin() ; it != CEs.end() ; it++ )
02479 setOut.insert( (*it)->m_connections[ metaRole ].second.begin(), (*it)->m_connections[ metaRole ].second.end() );
02480 return setOut;
02481 }
02482
02483 ConnectionSet setOut;
02484 if ( ! m_bAllConnections ) {
02485 std::set<MON::ConnectionRole> roles = getFCOHelper()->getFCOMeta().targetOf();
02486 for ( std::set<MON::ConnectionRole>::iterator it = roles.begin() ; it != roles.end() ; it++ ) {
02487 if ( ( strRole.empty() || strRole == it->name() ) && ( ! meta || meta == it->specification().connection() ) ) {
02488 MON::ConnectionEnd::Pair metaRole( it->name(), it->specification().connection() );
02489 if ( ! isConnectionsRetrieved( metaRole ) ) {
02490 std::set<ConnPointPtr> setSPConnPoints;
02491 getConnections( setSPConnPoints );
02492 getConnections( metaRole, setSPConnPoints, true );
02493 }
02494 }
02495 }
02496
02497 if ( strRole.empty() && ! meta ) {
02498 for ( std::set<ConnectionEndImpl*>::iterator it = CEs.begin() ; it != CEs.end() ; it++ )
02499 (*it)->m_bAllConnections = true;
02500 }
02501 }
02502
02503 std::set<MON::ConnectionRole> roles = getFCOHelper()->getFCOMeta().targetOf();
02504 for ( std::set<MON::ConnectionRole>::iterator it = roles.begin() ; it != roles.end() ; it++ ) {
02505 if ( ( strRole.empty() || strRole == it->name() ) && ( ! meta || meta == it->specification().connection() ) ) {
02506 MON::ConnectionEnd::Pair metaRole( it->name(), it->specification().connection() );
02507 if ( bOnlyCE )
02508 setOut.insert( m_connections[ metaRole ].second.begin(), m_connections[ metaRole ].second.end() );
02509 else {
02510 for ( std::set<ConnectionEndImpl*>::iterator it2 = CEs.begin() ; it2 != CEs.end() ; it2++ )
02511 setOut.insert( (*it2)->m_connections[ metaRole ].second.begin(), (*it2)->m_connections[ metaRole ].second.end() );
02512 }
02513 }
02514 }
02515 return setOut;
02516 }
02517
02518 FCOImpl* ConnectionEndImpl::getFCOHelper() const
02519 {
02520 return ( isReferencePort() ) ? ( (ReferencePortImpl*) this)->m_pFCO : (FCOImpl*) this;
02521 }
02522
02523
02524
02525
02526 bool ConnectionEndImpl::onRetrievedAsConnectionEnd( ConnectionImpl* pConnection, const std::string& strRole, bool bCheckAll )
02527 {
02528 MON::ConnectionEnd::Pair meta( strRole, pConnection->getConnectionMeta() );
02529 ManyConnectionLink::iterator it = m_connections.find( meta );
02530 if ( it == m_connections.end() ) {
02531 if ( bCheckAll )
02532 return false;
02533 m_connections[ meta ] = ConnectionSetPair( false, ConnectionSet() );
02534 }
02535 if ( ! bCheckAll || bCheckAll && m_connections[ meta ].first ) {
02536 m_connections[ meta ].second.insert( pConnection );
02537 return true;
02538 }
02539 return false;
02540 }
02541
02542 void ConnectionEndImpl::onReleasedAsConnectionEnd( ConnectionImpl* pConnection, const std::string& strRole, bool bOnlyFreeMemory )
02543 {
02544 MON::ConnectionEnd::Pair meta( strRole, pConnection->getConnectionMeta() );
02545 ManyConnectionLink::iterator it = m_connections.find( meta );
02546 if ( it != m_connections.end() ) {
02547 m_connections[ meta ].second.erase( pConnection );
02548 if ( bOnlyFreeMemory && m_connections[ meta ].first ) {
02549 FCOImpl* pFCO = ( isReferencePort() ) ? ( (ReferencePortImpl*) this)->m_pFCO : (FCOImpl*) this;
02550 ReferencePortSet ports = pFCO->getRefPortRefsI();
02551 for ( ReferencePortSet::iterator it = ports.begin() ; it != ports.end() ; it++ ) {
02552 ( (ConnectionEndImpl*) (*it) )->m_connections[ meta ].first = false;
02553 ( (ConnectionEndImpl*) (*it) )->m_bAllConnections = false;
02554 }
02555 ( (ConnectionEndImpl*) pFCO )->m_connections[ meta ].first = false;
02556 ( (ConnectionEndImpl*) pFCO )->m_bAllConnections = false;
02557 }
02558 }
02559 }
02560
02561
02562
02563
02564 std::set<Connection> ConnectionEndImpl::getConnLinks( const MON::Connection& meta, const std::string& strRole, bool bAsFCO, const MON::Aspect& aspect )
02565 {
02566 if ( aspect && aspect.project() != getProject()->getProjectMeta() )
02567 {
02568 MON::Exception exc( "? does not belong to ? of ?!");
02569 exc << aspect.infoString().c_str() << getProject()->getProjectMeta().infoString().c_str() << getProject()->getInfoString().c_str();
02570 ASSERTTHROW( exc);
02571 }
02572
02573
02574 if ( meta ) {
02575 if ( meta.project() != getProject()->getProjectMeta() )
02576 {
02577 MON::Exception exc( "? does not belong to ? of ?!");
02578 exc << meta.infoString().c_str() << getProject()->getProjectMeta().infoString().c_str() << getProject()->getInfoString().c_str();
02579 ASSERTTHROW( exc );
02580 }
02581
02582 std::string str = meta.name();
02583 bool bFound = false;
02584 size_t iCnt = meta.specificationCount();
02585 for ( int i = 0 ; i < iCnt ; i++ ) {
02586 std::set<MON::ConnectionRole> roles = meta.specification( i ).roles();
02587 for ( std::set<MON::ConnectionRole>::iterator it = roles.begin() ; it != roles.end() ; it++ ) {
02588 if ( ( strRole.empty() || strRole == it->name() ) && it->isTarget( getFCOHelper()->getFCOMeta() ) ) {
02589 bFound = true;
02590 break;
02591 }
02592 }
02593 if ( bFound )
02594 break;
02595 }
02596
02597 if ( ! bFound )
02598 if ( strRole.empty() ) {
02599 MON::Exception exc( "? cannot be target of ?!");
02600 exc << getFCOHelper()->getObjectMeta().infoString().c_str() << meta.infoString().c_str();
02601 ASSERTTHROW( exc);
02602 }
02603 else {
02604 MON::Exception exc( "? cannot be target of ? with role ?!");
02605 exc << getFCOHelper()->getObjectMeta().infoString().c_str() << meta.infoString().c_str() << strRole.c_str();
02606 ASSERTTHROW( exc);
02607 }
02608
02609 std::set<Connection> setResult;
02610 setCopy<Connection,ConnectionImpl>( getConnectionsI( strRole, meta, ! bAsFCO ), setResult );
02611 return filterByAspect<Connection>( setResult, aspect );
02612 }
02613
02614
02615
02616 if ( ! strRole.empty() ) {
02617 bool bFound = false;
02618 std::set<MON::ConnectionRole> roles = getFCOHelper()->getFCOMeta().targetOf();
02619 for ( std::set<MON::ConnectionRole>::iterator it = roles.begin() ; it != roles.end() ; it++ ) {
02620 if ( it->name() == strRole ) {
02621 bFound = true;
02622 break;
02623 }
02624 }
02625 if ( ! bFound )
02626 {
02627 MON::Exception exc( "? cannot be target of any MON::Connection with role ?!");
02628 exc << getFCOHelper()->getObjectMeta().infoString() << strRole;
02629 ASSERTTHROW( exc);
02630 }
02631
02632 std::set<Connection> setResult;
02633 setCopy<Connection,ConnectionImpl>( getConnectionsI( strRole, meta, ! bAsFCO ), setResult );
02634 return filterByAspect<Connection>( setResult, aspect );
02635 }
02636
02637
02638
02639 std::set<Connection> setResult;
02640 setCopy<Connection,ConnectionImpl>( getConnectionsI( strRole, meta, ! bAsFCO ), setResult );
02641 return filterByAspect<Connection>( setResult, aspect );
02642 }
02643
02644 std::set<Connection> ConnectionEndImpl::getConnLinks( const std::string& strConnection, const std::string& strRole, bool bAsFCO, const MON::Aspect& aspect )
02645 {
02646 MON::Connection meta;
02647 if ( ! strConnection.empty() ) {
02648 meta = MON::Connection( getProject()->getProjectMeta().findByName( strConnection ) );
02649 if (g_TEST_META_CONFORMANCE_INSIDE_BON)
02650 {
02651 THROW_METAPROJECT_DOES_NOT_HAVE( meta, Connection, strConnection );
02652 }
02653 else
02654 if( !meta)
02655 return std::set<Connection>();
02656 }
02657 return getConnLinks( meta, strRole, bAsFCO, aspect );
02658 }
02659
02660 std::set<Connection> ConnectionEndImpl::getInConnLinks( const MON::Connection& meta, bool bAsFCO, const MON::Aspect& aspect )
02661 {
02662 return getConnLinks( meta, "dst", bAsFCO, aspect );
02663 }
02664
02665 std::set<Connection> ConnectionEndImpl::getInConnLinks( const std::string& strConnection, bool bAsFCO, const MON::Aspect& aspect )
02666 {
02667 return getConnLinks( strConnection, "dst", bAsFCO, aspect );
02668 }
02669
02670 std::set<Connection> ConnectionEndImpl::getOutConnLinks( const MON::Connection& meta, bool bAsFCO, const MON::Aspect& aspect )
02671 {
02672 return getConnLinks( meta, "src", bAsFCO, aspect );
02673 }
02674
02675 std::set<Connection> ConnectionEndImpl::getOutConnLinks( const std::string& strConnection, bool bAsFCO, const MON::Aspect& aspect )
02676 {
02677 return getConnLinks( strConnection, "src", bAsFCO, aspect );
02678 }
02679
02680 typedef std::vector<std::string> RoleVec;
02681 typedef std::pair<MON::Connection,RoleVec> RoleMeta2;
02682
02683 std::multiset<ConnectionEnd> ConnectionEndImpl::getConnEndsAs( const MON::Connection& meta, const std::string& strRole, bool bAsFCO, const MON::Aspect& aspect )
02684 {
02685 if ( aspect && aspect.project() != getProject()->getProjectMeta() )
02686 {
02687 MON::Exception exc( "? does not belong to ? of ?!");
02688 exc << aspect.infoString() << getProject()->getProjectMeta().infoString() << getProject()->getInfoString();
02689 ASSERTTHROW( exc);
02690 }
02691
02692
02693 std::set<RoleMeta2> metaRoles;
02694 std::set<MON::ConnectionSpecification> specs;
02695
02696
02697 if ( meta ) {
02698 if ( meta.project() != getProject()->getProjectMeta() )
02699 {
02700 MON::Exception exc( "? does not belong to ? of ?!");
02701 exc << meta.infoString() << getProject()->getProjectMeta().infoString() << getProject()->getInfoString();
02702 ASSERTTHROW( exc);
02703 }
02704 if ( ! meta.isSimple() )
02705 {
02706 MON::Exception exc( "? is not simple!");
02707 exc << meta.infoString();
02708 ASSERTTHROW( exc);
02709 }
02710
02711
02712 bool bFound = false;
02713 for ( int i = 0 ; i < meta.specificationCount() ; i++ ) {
02714 std::set<MON::ConnectionRole> roles = meta.specification( i ).roles();
02715 for ( std::set<MON::ConnectionRole>::iterator it2 = roles.begin() ; it2 != roles.end() ; it2++ )
02716 if ( ( strRole.empty() || strRole == it2->name() ) && it2->isTarget( getFCOHelper()->getFCOMeta() ) ) {
02717 bFound = true;
02718 break;
02719 }
02720 }
02721 if ( ! bFound )
02722 {
02723 if (g_TEST_META_CONFORMANCE_INSIDE_BON)
02724 {
02725 if ( strRole.empty() ) {
02726 MON::Exception exc( "? cannot be target of ?!");
02727 exc << getFCOHelper()->getObjectMeta().infoString() << meta.infoString();
02728 ASSERTTHROW( exc);
02729 }
02730 else {
02731 MON::Exception exc( "? cannot be target of ? with role ?!");
02732 exc << getFCOHelper()->getObjectMeta().infoString() << meta.infoString() << strRole;
02733 ASSERTTHROW( exc);
02734 }
02735 }
02736 else
02737 {
02738 return std::multiset<ConnectionEnd>();
02739 }
02740 }
02741
02742 specs = meta.specifications();
02743 }
02744
02745 else {
02746 bool bFound = false;
02747 std::set<MON::ConnectionRole> roles = getFCOHelper()->getFCOMeta().targetOf();
02748 for ( std::set<MON::ConnectionRole>::iterator it = roles.begin() ; it != roles.end() ; it++ ) {
02749 if ( it->specification().connection().isSimple() ) {
02750 specs.insert( it->specification() );
02751 bFound = true;
02752 }
02753 }
02754
02755 if ( ! bFound )
02756 return std::multiset<ConnectionEnd>();
02757
02758
02759 }
02760
02761 bool bFound = false;
02762 for ( std::set<MON::ConnectionSpecification>::iterator it = specs.begin() ; it != specs.end() ; it++ ) {
02763 std::set<MON::ConnectionRole> roles = it->roles();
02764 RoleVec rVec( 2 );
02765 int iDir = 0;
02766 for ( std::set<MON::ConnectionRole>::iterator it2 = roles.begin() ; it2 != roles.end() ; it2++ ) {
02767 if ( it2->isTarget( getFCOHelper()->getFCOMeta()) && ( strRole.empty() || strRole == it2->name() ) ) {
02768 rVec[ iDir++ ] = it2->name();
02769 bFound = true;
02770 }
02771 else
02772 rVec[ 1 ] = it2->name();
02773 }
02774 if ( iDir > 0 ) {
02775 metaRoles.insert( RoleMeta2( it->connection(), rVec ) );
02776 if ( iDir == 2 ) {
02777 RoleVec rVec2( 2 );
02778 rVec2[ 0 ] = rVec[ 1 ];
02779 rVec2[ 1 ] = rVec[ 0 ];
02780 metaRoles.insert( RoleMeta2( it->connection(), rVec2 ) );
02781 }
02782 }
02783 }
02784
02785 if ( ! bFound )
02786 if ( strRole.empty() ) {
02787 MON::Exception exc( "? cannot be target of MON::Connection!");
02788 exc << getFCOHelper()->getObjectMeta().infoString();
02789 ASSERTTHROW( exc);
02790 }
02791 else {
02792 MON::Exception exc( "? cannot be target of MON::Connection with role ?!");
02793 exc << getFCOHelper()->getObjectMeta().infoString() << strRole;
02794 ASSERTTHROW( exc);
02795 }
02796
02797 std::multiset<ConnectionEnd> setResult;
02798 for ( std::set<RoleMeta2>::iterator itr = metaRoles.begin() ; itr != metaRoles.end() ; itr++ ) {
02799 ConnectionSet conns = getConnectionsI( itr->second[ 0 ], itr->first, ! bAsFCO );
02800 for ( ConnectionSet::iterator itc = conns.begin() ; itc != conns.end() ; itc++ )
02801 setResult.insert( (*itc)->getConnectionEndI( itr->second[ 1 ] ) );
02802 }
02803
02804 if ( aspect ) {
02805 std::multiset<ConnectionEnd>::iterator itce = setResult.begin();
02806 while ( itce != setResult.end() ) {
02807 std::multiset<ConnectionEnd>::iterator itSaved = itce;
02808 itce++;
02809 if ( ! (*itSaved)->getFCOHelper()->isVisible( aspect, true ) )
02810 setResult.erase( itSaved );
02811 }
02812 }
02813 return setResult;
02814 }
02815
02816 std::multiset<ConnectionEnd> ConnectionEndImpl::getConnEndsAs( const std::string& strConnection, const std::string& strRole, bool bAsFCO, const MON::Aspect& aspect )
02817 {
02818 MON::Connection meta;
02819 if ( ! strConnection.empty() ) {
02820 meta = MON::Connection( getProject()->getProjectMeta().findByName( strConnection ) );
02821 if (g_TEST_META_CONFORMANCE_INSIDE_BON)
02822 {
02823 THROW_METAPROJECT_DOES_NOT_HAVE( meta, Connection, strConnection );
02824 }
02825 else
02826 {
02827 if( !meta)
02828 return std::multiset<ConnectionEnd>();
02829 }
02830 }
02831 return getConnEndsAs( meta, strRole, bAsFCO, aspect );
02832 }
02833
02834 std::multiset<ConnectionEnd> ConnectionEndImpl::getInConnEnds( const MON::Connection& meta, bool bAsFCO, const MON::Aspect& aspect )
02835 {
02836 return getConnEndsAs( meta, "dst", bAsFCO, aspect );
02837 }
02838
02839 std::multiset<ConnectionEnd> ConnectionEndImpl::getInConnEnds( const std::string& strConnection, bool bAsFCO, const MON::Aspect& aspect )
02840 {
02841 return getConnEndsAs( strConnection, "dst", bAsFCO, aspect );
02842 }
02843
02844 std::multiset<ConnectionEnd> ConnectionEndImpl::getOutConnEnds( const MON::Connection& meta, bool bAsFCO, const MON::Aspect& aspect )
02845 {
02846 return getConnEndsAs( meta, "src", bAsFCO, aspect );
02847 }
02848
02849 std::multiset<ConnectionEnd> ConnectionEndImpl::getOutConnEnds( const std::string& strConnection, bool bAsFCO, const MON::Aspect& aspect )
02850 {
02851 return getConnEndsAs( strConnection, "src", bAsFCO, aspect );
02852 }
02853
02854 void ConnectionEndImpl::getDirectConnEndsRec( ConnectionEnd& ce, const MON::Connection& meta, const std::string& strRole, bool bAsFCO, std::multiset<ConnectionEnd>& setResult )
02855 {
02856 std::multiset<ConnectionEnd> ends = ce->getConnEndsAs( meta, strRole, bAsFCO );
02857 if ( ends.empty() ) {
02858 setResult.insert( ce );
02859 return;
02860 }
02861 for ( std::multiset<ConnectionEnd>::iterator it = ends.begin() ; it != ends.end() ; it++ ) {
02862 ConnectionEnd ce( *it );
02863 getDirectConnEndsRec( ce, meta, strRole, bAsFCO, setResult );
02864 }
02865 }
02866
02867 std::multiset<ConnectionEnd> ConnectionEndImpl::getDirectConnEnds( const MON::Connection& meta, const std::string& strRole, bool bAsFCO, const MON::Aspect& aspect )
02868 {
02869 THROW_CANNOT_BE_NULL( meta, "MON::Connection" );
02870 THROW_CANNOT_BE_EMPTY( "The role", strRole );
02871 std::multiset<ConnectionEnd> setResult;
02872 ConnectionEnd ce( this );
02873 getDirectConnEndsRec( ce, meta, strRole, bAsFCO, setResult );
02874
02875 if ( aspect ) {
02876 std::multiset<ConnectionEnd>::iterator itce = setResult.begin();
02877 while ( itce != setResult.end() ) {
02878 std::multiset<ConnectionEnd>::iterator itSaved = itce;
02879 itce++;
02880 if ( ! (*itSaved)->getFCOHelper()->isVisible( aspect, true ) )
02881 setResult.erase( itSaved );
02882 }
02883 }
02884 return setResult;
02885 }
02886
02887 std::multiset<ConnectionEnd> ConnectionEndImpl::getDirectConnEnds( const std::string& strConnection, const std::string& strRole, bool bAsFCO, const MON::Aspect& aspect )
02888 {
02889 MON::Connection meta = getProject()->getProjectMeta().findByName( strConnection );
02890 THROW_METAPROJECT_DOES_NOT_HAVE( meta, Connection, strConnection );
02891 return getDirectConnEnds( meta, strRole, bAsFCO, aspect );
02892 }
02893
02894 std::multiset<ConnectionEnd> ConnectionEndImpl::getDirectInConnEnds( const MON::Connection& meta, bool bAsFCO, const MON::Aspect& aspect )
02895 {
02896 return getDirectConnEnds( meta, "dst", bAsFCO, aspect );
02897 }
02898
02899 std::multiset<ConnectionEnd> ConnectionEndImpl::getDirectOutConnEnds( const MON::Connection& meta, bool bAsFCO, const MON::Aspect& aspect )
02900 {
02901 return getDirectConnEnds( meta, "src", bAsFCO, aspect );
02902 }
02903
02904 std::multiset<ConnectionEnd> ConnectionEndImpl::getDirectInConnEnds( const std::string& strConnection, bool bAsFCO, const MON::Aspect& aspect )
02905 {
02906 MON::Connection meta = getProject()->getProjectMeta().findByName( strConnection );
02907 THROW_METAPROJECT_DOES_NOT_HAVE( meta, Connection, strConnection );
02908 return getDirectConnEnds( meta, "dst", bAsFCO, aspect );
02909 }
02910
02911 std::multiset<ConnectionEnd> ConnectionEndImpl::getDirectOutConnEnds( const std::string& strConnection, bool bAsFCO, const MON::Aspect& aspect )
02912 {
02913 MON::Connection meta = getProject()->getProjectMeta().findByName( strConnection );
02914 THROW_METAPROJECT_DOES_NOT_HAVE( meta, Connection, strConnection );
02915 return getDirectConnEnds( meta, "src", bAsFCO, aspect );
02916 }
02917
02918 std::multiset<ConnectionEnd> ConnectionEndImpl::getConnEnds( const MON::Connection& meta, const std::string& strRole, bool bAsFCO, const MON::Aspect& aspect )
02919 {
02920 if ( aspect && aspect.project() != getProject()->getProjectMeta() )
02921 {
02922 MON::Exception exc( "? does not belong to ? of ?!");
02923 exc << aspect.infoString() << getProject()->getProjectMeta().infoString() << getProject()->getInfoString();
02924 ASSERTTHROW( exc);
02925 }
02926
02927 std::set<RoleMeta2> metaRoles;
02928 std::set<MON::ConnectionSpecification> specs;
02929
02930
02931 if ( meta ) {
02932 if ( meta.project() != getProject()->getProjectMeta() )
02933 {
02934 MON::Exception exc( "? does not belong to ? of ?!");
02935 exc << meta.infoString() << getProject()->getProjectMeta().infoString() << getProject()->getInfoString();
02936 ASSERTTHROW( exc);
02937 }
02938 if ( ! meta.isSimple() )
02939 {
02940 MON::Exception exc( "? is not simple!");
02941 exc << meta.infoString();
02942 ASSERTTHROW( exc);
02943 }
02944
02945
02946 bool bFound = false;
02947 for ( int i = 0 ; i < meta.specificationCount() ; i++ ) {
02948 std::set<MON::ConnectionRole> roles = meta.specification( i ).roles();
02949 for ( std::set<MON::ConnectionRole>::iterator it2 = roles.begin() ; it2 != roles.end() ; it2++ )
02950 if ( it2->isTarget( getFCOHelper()->getFCOMeta()) ) {
02951 bFound = true;
02952 break;
02953 }
02954 }
02955 if ( ! bFound )
02956 {
02957 if (g_TEST_META_CONFORMANCE_INSIDE_BON)
02958 {
02959 MON::Exception exc( "? cannot be target of ?!");
02960 exc << getFCOHelper()->getObjectMeta().infoString() << meta.infoString();
02961 ASSERTTHROW( exc);
02962 }
02963 else
02964 {
02965 return std::multiset<ConnectionEnd>();
02966 }
02967 }
02968
02969 specs = meta.specifications();
02970 }
02971
02972 else {
02973 bool bFound = false;
02974 std::set<MON::ConnectionRole> roles = getFCOHelper()->getFCOMeta().targetOf();
02975 for ( std::set<MON::ConnectionRole>::iterator it = roles.begin() ; it != roles.end() ; it++ ) {
02976 if ( it->specification().connection().isSimple() ) {
02977 specs.insert( it->specification() );
02978 bFound = true;
02979 }
02980 }
02981
02982 if ( ! bFound )
02983 return std::multiset<ConnectionEnd>();
02984
02985
02986 }
02987
02988 bool bFound = false;
02989 for ( std::set<MON::ConnectionSpecification>::iterator it = specs.begin() ; it != specs.end() ; it++ ) {
02990 std::set<MON::ConnectionRole> roles = it->roles();
02991 RoleVec rVec( 2 );
02992 int iDir = 0;
02993 for ( std::set<MON::ConnectionRole>::iterator it2 = roles.begin() ; it2 != roles.end() ; it2++ ) {
02994 if ( it2->isTarget( getFCOHelper()->getFCOMeta() ) )
02995 rVec[ iDir++ ] = it2->name();
02996 else
02997 rVec[ 1 ] = it2->name();
02998 }
02999 if ( iDir > 0 ) {
03000 if ( strRole.empty() || strRole == rVec[ 1 ] ) {
03001 bFound = true;
03002 metaRoles.insert( RoleMeta2( it->connection(), rVec ) );
03003 }
03004 if ( iDir == 2 ) {
03005 RoleVec rVec2( 2 );
03006 rVec2[ 0 ] = rVec[ 1 ];
03007 rVec2[ 1 ] = rVec[ 0 ];
03008 if ( strRole.empty() || strRole == rVec2[ 1 ] ) {
03009 bFound = true;
03010 metaRoles.insert( RoleMeta2( it->connection(), rVec2 ) );
03011 }
03012 }
03013 }
03014 }
03015
03016 if ( ! bFound )
03017 if ( strRole.empty() ) {
03018 MON::Exception exc( "? cannot be target of ?!");
03019 exc << getFCOHelper()->getObjectMeta().infoString() << (( meta ) ? meta.infoString() : "MON::Connection");
03020 ASSERTTHROW( exc);
03021 }
03022 else
03023 if ( meta ) {
03024 MON::Exception exc( "? does not have peer with role ?!");
03025 exc << getFCOHelper()->getObjectMeta().infoString() << strRole;
03026 ASSERTTHROW( exc);
03027 }
03028 else {
03029 MON::Exception exc( "? does not have peer with ? and with role ?!");
03030 exc << getFCOHelper()->getObjectMeta().infoString() << meta.infoString() << strRole;
03031 ASSERTTHROW( exc);
03032 }
03033
03034 std::multiset<ConnectionEnd> setResult;
03035 for ( std::set<RoleMeta2>::iterator itr = metaRoles.begin() ; itr != metaRoles.end() ; itr++ ) {
03036 ConnectionSet conns = getConnectionsI( itr->second[ 0 ], itr->first, ! bAsFCO );
03037 for ( ConnectionSet::iterator itc = conns.begin() ; itc != conns.end() ; itc++ )
03038 setResult.insert( (*itc)->getConnectionEndI( itr->second[ 1 ] ) );
03039 }
03040
03041 if ( aspect ) {
03042 std::multiset<ConnectionEnd>::iterator itce = setResult.begin();
03043 while ( itce != setResult.end() ) {
03044 std::multiset<ConnectionEnd>::iterator itSaved = itce;
03045 itce++;
03046 if ( ! (*itSaved)->getFCOHelper()->isVisible( aspect, true ) )
03047 setResult.erase( itSaved );
03048 }
03049 }
03050 return setResult;
03051 }
03052
03053 std::multiset<ConnectionEnd> ConnectionEndImpl::getConnEnds( const std::string& strConnection, const std::string& strRole, bool bAsFCO, const MON::Aspect& aspect )
03054 {
03055 MON::Connection meta;
03056 if ( ! strConnection.empty() ) {
03057 meta = MON::Connection( getProject()->getProjectMeta().findByName( strConnection ) );
03058 if (g_TEST_META_CONFORMANCE_INSIDE_BON)
03059 {
03060 THROW_METAPROJECT_DOES_NOT_HAVE( meta, Connection, strConnection );
03061 }
03062 else
03063 {
03064 if( !meta)
03065 return std::multiset<ConnectionEnd>();
03066 }
03067 }
03068 return getConnEnds( meta, strRole, bAsFCO, aspect );
03069 }
03070
03071
03072
03073
03074 void ConnectionEndImpl::accept( Visitor* pVisitor )
03075 {
03076 if ( isReferencePort() )
03077 ( (ReferencePortImpl*) this)->accept( pVisitor );
03078 else
03079 ( (FCOImpl*) this)->accept( pVisitor );
03080 }
03081
03082
03083
03084
03085
03086
03087
03088 ReferencePortImpl::ReferencePortImpl( ReferenceImpl* pContainer, FCOImpl* pFCO )
03089 : m_pContainer( pContainer ), m_pFCO( pFCO )
03090 {
03091 setProject( (ProjectImpl*) m_pFCO->getProject().getCounted() );
03092 setDisposable( _isAddOn() );
03093 std::set<Util::GenRefCounted*> setAggrs;
03094 setAggrs.insert( dynamic_cast<Util::GenRefCounted*>( pFCO ) );
03095 setAggrs.insert( dynamic_cast<Util::GenRefCounted*>( pContainer ) );
03096 setAggregators( setAggrs );
03097 }
03098
03099 ReferencePortImpl::~ReferencePortImpl()
03100 {
03101 if ( ! m_pProject->isDestructionActive() && ! isDeleted() ) {
03102 m_pFCO->onReleasedAsReferencePort( this, true );
03103 m_pContainer->onReleasedAsPortContainer( m_pFCO, true );
03104 }
03105
03106 m_pFCO = NULL;
03107 m_pContainer = NULL;
03108 }
03109
03110 bool ReferencePortImpl::setDeleted()
03111 {
03112 if ( ConnectionEndImpl::setDeleted() )
03113 return true;
03114
03115 m_pFCO->onReleasedAsReferencePort( this, false );
03116 m_pContainer->onReleasedAsPortContainer( m_pFCO, false );
03117
03118 return false;
03119 }
03120
03121
03122
03123
03124 bool ReferencePortImpl::isReferencePort() const
03125 {
03126 return true;
03127 }
03128
03129 ReferencePortContainer ReferencePortImpl::getContainer() const
03130 {
03131 return m_pContainer->getRefPortContainer();
03132 }
03133
03134 FCO ReferencePortImpl::getFCO() const
03135 {
03136 return m_pFCO;
03137 }
03138
03139 std::string ReferencePortImpl::getInfoString( unsigned short usOptions ) const
03140 {
03141 bool bAll = ( usOptions & Util::IO_All ) ? true : false;
03142 bool bIdent = bAll || ( usOptions & Util::IO_Identifiers );
03143 bool bLine = bAll || ( usOptions & Util::IO_NewLine );
03144 std::string strDelim = ( bLine ) ? "\n" : ", ";
03145
03146 std::string strInfo( "BON::ReferencePort" );
03147 strInfo += ( bLine ) ? " :\n" : " [";
03148
03149 unsigned short usOptions2 = 0;
03150 if ( bIdent )
03151 usOptions2 |= Util::IO_Identifiers;
03152 if ( bAll || ( usOptions & Util::IO_ID ) )
03153 usOptions2 |= Util::IO_ID;
03154 if ( bAll || ( usOptions & Util::IO_Meta ) )
03155 usOptions2 |= Util::IO_Meta;
03156 if ( bAll || ( usOptions & Util::IO_Path ) )
03157 usOptions2 |= Util::IO_Path;
03158
03159 if ( bIdent )
03160 strInfo += "fco: ";
03161 strInfo += m_pFCO->getInfoString( usOptions2 ) + strDelim;
03162
03163 if ( bIdent )
03164 strInfo += "container: ";
03165 strInfo += m_pContainer->getInfoString( usOptions2 );
03166
03167 if ( ! bLine )
03168 strInfo += "]";
03169
03170 return strInfo;
03171 }
03172
03173
03174
03175
03176 void ReferencePortImpl::getDescendantPortsI( std::set<Reference>& setVisited, std::set<ReferencePort>& setPorts ) const
03177 {
03178 if ( setVisited.find( m_pContainer ) == setVisited.end() ) {
03179 setVisited.insert( m_pContainer );
03180
03181 std::set<Reference> refs = m_pContainer->getReferredBy();
03182 for ( std::set<Reference>::iterator it = refs.begin() ; it != refs.end() ; it++ ) {
03183 ReferencePort port = (*it)->getRefPortContainer()->getReferencePort( m_pFCO );
03184 setPorts.insert( port );
03185 dynamic_cast<ReferencePortImpl*>( port.getCounted() )->getDescendantPortsI( setVisited, setPorts );
03186 }
03187 }
03188 }
03189
03190
03191
03192
03193 void ReferencePortImpl::accept( Visitor* pVisitor )
03194 {
03195 pVisitor->visitReferencePort( ReferencePort( this ) );
03196 }
03197
03198
03199
03200
03201 ReferencePort ReferencePortImpl::getParentPort() const
03202 {
03203 Reference ref( m_pContainer->getReferred() );
03204 return ( ref ) ? ref->getRefPortContainer()->getReferencePort( m_pFCO ) : NULL;
03205 }
03206
03207 std::set<ReferencePort> ReferencePortImpl::getChildPorts() const
03208 {
03209 std::set<Reference> refs = m_pContainer->getReferredBy();
03210 std::set<ReferencePort> ports;
03211 for ( std::set<Reference>::iterator it = refs.begin() ; it != refs.end() ; it++ )
03212 ports.insert( (*it)->getRefPortContainer()->getReferencePort( m_pFCO ) );
03213 return ports;
03214 }
03215
03216 std::set<ReferencePort> ReferencePortImpl::getDescendantPorts() const
03217 {
03218 std::set<Reference> setVisited;
03219 std::set<ReferencePort> setPorts;
03220 getDescendantPortsI( setVisited, setPorts );
03221 return setPorts;
03222 }
03223
03224
03225
03226
03227
03228
03229
03230 FCOImpl::FCOImpl()
03231 : ObjectImpl(), m_bAllParentModels( false ), m_pType( NULL ), m_bAllTypeFCOs( false ), m_bAllInstanceFCOs( false ), m_bAllSubTypeFCOs( false ), m_bAllSets( false ), m_bAllReferences( false ), m_bAllAttributes( false ), m_bAllRefPorts( false ), m_pTIObject( NULL )
03232 {
03233 m_parentModel.first = MON::Model();
03234 m_parentModel.second = NULL;
03235 }
03236
03237 void FCOImpl::doInitialize( ProjectImpl* pProject )
03238 {
03239 setProject( pProject );
03240 }
03241
03242 FCOImpl* FCOImpl::attachI( IMgaFCO* spFCO, ProjectImpl* pProject, const MON::Object& meta )
03243 {
03244 FCOImpl* pFCO = NULL;
03245 CComQIPtr<IMgaAtom> spAtom = spFCO;
03246 if ( spAtom )
03247 pFCO = AtomImpl::attachI( spAtom, pProject, meta );
03248 else {
03249 CComQIPtr<IMgaModel> spModel = spFCO;
03250 if ( spModel )
03251 pFCO = ModelImpl::attachI( spModel, pProject, meta );
03252 else {
03253 CComQIPtr<IMgaSet> spSet = spFCO;
03254 if ( spSet )
03255 pFCO = SetImpl::attachI( spSet, pProject, meta );
03256 else {
03257 CComQIPtr<IMgaReference> spReference = spFCO;
03258 if ( spReference )
03259 pFCO = ReferenceImpl::attachI( spReference, pProject, meta );
03260 else {
03261 CComQIPtr<IMgaConnection> spConnection = spFCO;
03262 if ( spConnection )
03263 pFCO = ConnectionImpl::attachI( spConnection, pProject, meta );
03264 else {
03265 ASSERTTHROW( Util::Exception( "Unprocessed Object Type!" ) );
03266 }
03267 }
03268 }
03269 }
03270 }
03271
03272 return pFCO;
03273 }
03274
03275
03276
03277
03278
03279
03280
03281
03282 void FCOImpl::attachIPost( FCOImpl* pFCO )
03283 {
03284 if ( pFCO && ! pFCO->m_pTIObject && pFCO->getStatus() == OST_Exists ) {
03285 if ( pFCO->isInstance() )
03286 pFCO->m_pTIObject = new InstanceImpl( pFCO );
03287 else
03288 pFCO->m_pTIObject = new TypeImpl( pFCO );
03289 }
03290 }
03291
03292 FCO FCOImpl::attach( IMgaFCO* spFCO )
03293 {
03294 return attachI( spFCO );
03295 }
03296
03297 FCOImpl::~FCOImpl()
03298 {
03299 if ( ! ObjectImpl::m_pProject->isDestructionActive() && ! isDeleted() ) {
03300 if ( m_parentModel.second )
03301 m_parentModel.second->onReleasedAsFCOParent( this, true );
03302
03303 for ( ManyReferenceLink::iterator itR1 = m_references.begin() ; itR1 != m_references.end() ; itR1++ )
03304 for ( ReferenceSet::iterator itR2 = itR1->second.second.begin() ; itR2 != itR1->second.second.end() ; itR2++ )
03305 (*itR2)->onReleasedAsReference( this, true );
03306
03307 for ( ManySetLink::iterator itS1 = m_sets.begin() ; itS1 != m_sets.end() ; itS1++ )
03308 for ( SetSet::iterator itS2 = itS1->second.second.begin() ; itS2 != itS1->second.second.end() ; itS2++ )
03309 (*itS2)->onReleasedAsSet( this, true );
03310
03311
03312 ReferencePortSet ports = m_refPorts;
03313 for ( ReferencePortSet::iterator it = ports.begin() ; it != ports.end() ; it++ )
03314 (*it)->setDeleted();
03315 }
03316
03317 for ( ManyAttributeLink::iterator it = m_attributes.begin() ; it != m_attributes.end() ; ++it )
03318 delete it->second;
03319 if ( m_pTIObject )
03320 delete m_pTIObject;
03321
03322 m_parentModel.first = MON::Model();
03323 m_parentModel.second = NULL;
03324 m_pTIObject = NULL;
03325 m_attributes.clear();
03326 m_references.clear();
03327 m_sets.clear();
03328 m_refPorts.clear();
03329 m_storedRefWrappers.clear();
03330 }
03331
03332 bool FCOImpl::setDeleted()
03333 {
03334 if ( ObjectImpl::setDeleted() )
03335 return true;
03336 ConnectionEndImpl::setDeleted();
03337
03338 if ( m_parentModel.second )
03339 m_parentModel.second->onReleasedAsFCOParent( this, false );
03340
03341 for ( ManyReferenceLink::iterator itR1 = m_references.begin() ; itR1 != m_references.end() ; itR1++ )
03342 for ( ReferenceSet::iterator itR2 = itR1->second.second.begin() ; itR2 != itR1->second.second.end() ; itR2++ )
03343 (*itR2)->onReleasedAsReference( this, false );
03344
03345 for ( ManySetLink::iterator itS1 = m_sets.begin() ; itS1 != m_sets.end() ; itS1++ )
03346 for ( SetSet::iterator itS2 = itS1->second.second.begin() ; itS2 != itS1->second.second.end() ; itS2++ )
03347 (*itS2)->onReleasedAsSet( this, false );
03348
03349 ReferencePortSet ports = m_refPorts;
03350 for ( ReferencePortSet::iterator it = ports.begin() ; it != ports.end() ; it++ )
03351 (*it)->setDeleted();
03352 return false;
03353 }
03354
03355
03356
03357
03358 Project FCOImpl::getProject() const
03359 {
03360 return ObjectImpl::getProject();
03361 }
03362
03363 FCOPtr FCOImpl::getFCOI() const
03364 {
03365 CComQIPtr<IMgaFCO> spFCO = getObjectI().p;
03366 return spFCO.p;
03367 }
03368
03369 MON::FCO FCOImpl::getFCOMeta() const
03370 {
03371 return getObjectMeta();
03372 }
03373
03374 bool FCOImpl::isReferencePort() const
03375 {
03376 return false;
03377 }
03378
03379 bool FCOImpl::isInstance() const
03380 {
03381 VARIANT_BOOL vbInstance;
03382 COMCHECK2( getFCOI(), getFCOI()->get_IsInstance( &vbInstance ) );
03383 return vbInstance == VARIANT_TRUE;
03384 }
03385 MON::Containment FCOImpl::getRole()
03386 {
03387 getParentModel();
03388 return _getMetaRole( getFCOI() );
03389 }
03390
03391 bool FCOImpl::isPort( const MON::Aspect& meta )
03392 {
03393 if ( meta )
03394 THROW_METAPROJECT_BELONG( meta );
03395
03396 Model parm = getParentModel();
03397 if ( m_parentModel.first ) {
03398 if ( meta ) {
03399 std::set<MON::Aspect> aspects = m_parentModel.second->getModelMeta().aspects();
03400 if ( aspects.find( meta ) == aspects.end() )
03401 return false;
03402 }
03403 std::set<MON::ContainmentPart> parts = getRole().parts();
03404 for ( std::set<MON::ContainmentPart>::iterator it2 = parts.begin() ; it2 != parts.end() ; ++it2 )
03405 if ( it2->isLinked() && ( ! meta || meta == it2->aspect() ) )
03406 return true;
03407 }
03408 return false;
03409 }
03410
03411 bool FCOImpl::isPort( const std::string& strAspect )
03412 {
03413 MON::Aspect meta;
03414 if ( ! strAspect.empty() ) {
03415
03416
03417
03418 getParentModel();
03419 if ( m_parentModel.first ) {
03420 std::set<MON::Aspect> aspects = m_parentModel.second->getModelMeta().aspects();
03421 for( std::set<MON::Aspect>::const_iterator i = aspects.begin(); i != aspects.end(); ++i)
03422 if ( i->name() == strAspect)
03423 meta = *i;
03424 }
03425 }
03426 return isPort( meta );
03427 }
03428
03429 bool FCOImpl::isVisible( const MON::Aspect& meta, bool bAsContained )
03430 {
03431 THROW_CANNOT_BE_NULL( meta, "MON::Aspect" );
03432 THROW_METAPROJECT_BELONG( meta );
03433 getParentModel();
03434 if ( m_parentModel.first ) {
03435 if ( meta ) {
03436 std::set<MON::Aspect> aspects = m_parentModel.second->getModelMeta().aspects();
03437 if ( aspects.find( meta ) == aspects.end() )
03438 return false;
03439 }
03440
03441 std::set<MON::Containment> containments;
03442 if ( bAsContained )
03443 containments.insert( getRole());
03444
03445
03446 else
03447 containments = getFCOMeta().parentContainments();
03448
03449 for ( std::set<MON::Containment>::iterator it = containments.begin() ; it != containments.end() ; ++it )
03450 {
03451 std::set<MON::ContainmentPart> parts = it->parts();;
03452 for ( std::set<MON::ContainmentPart>::iterator it2 = parts.begin() ; it2 != parts.end() ; ++it2 )
03453 if ( meta == it2->aspect() )
03454 return true;
03455 }
03456 }
03457 return false;
03458 }
03459
03460 bool FCOImpl::isVisible( const std::string& strAspect, bool bAsContained )
03461 {
03462
03463
03464
03465
03466
03467 MON::Aspect meta;
03468
03469 getParentModel();
03470 if ( m_parentModel.first ) {
03471 std::set<MON::Aspect> aspects = m_parentModel.second->getModelMeta().aspects();
03472 for( std::set<MON::Aspect>::const_iterator i = aspects.begin(); i != aspects.end(); ++i)
03473 if ( i->name() == strAspect)
03474 meta = *i;
03475 }
03476
03477 return (meta)?isVisible( meta, bAsContained):false;
03478 }
03479
03480 std::string FCOImpl::getInfoString( const std::set<Util::InfoOption>& setOptions ) const
03481 {
03482 return ObjectImpl::getInfoString( setOptions );
03483 }
03484
03485
03486
03487
03488 ReferencePortSet FCOImpl::getRefPortRefsI()
03489 {
03490 if ( ! m_bAllRefPorts ) {
03491 m_bAllRefPorts = true;
03492 ModelImpl* pModel = getParentModelI();
03493 if ( pModel ) {
03494 ReferenceSet setRefs = ( (FCOImpl*) pModel )->getReferencesI();
03495 for ( ReferenceSet::iterator it = setRefs.begin() ; it != setRefs.end() ; ++it )
03496 (*it)->getRefPort( this );
03497 }
03498 }
03499 return m_refPorts;
03500 }
03501
03502 AttributeImpl* FCOImpl::getAttributeI( const MON::Attribute& meta )
03503 {
03504 if ( ! m_bAllAttributes ) {
03505 m_bAllAttributes = true;
03506 Util::ComPtr<IMgaAttributes> spAttributes;
03507 COMCHECK2( getFCOI(), getFCOI()->get_Attributes( spAttributes.Addr() ) );
03508 MGACOLL_ITERATE( IMgaAttribute, spAttributes.p ) {
03509 MON::AttributePtr spMeta;
03510 COMCHECK2( MGACOLL_ITER, MGACOLL_ITER->get_Meta( spMeta.Addr() ) );
03511 MON::Attribute metaIter( spMeta );
03512 m_attributes.insert( ManyAttributeLink::value_type( metaIter, AttributeImpl::attachI( MGACOLL_ITER, this, metaIter ) ) );
03513 } MGACOLL_ITERATE_END;
03514 }
03515 return m_attributes[ meta ];
03516 }
03517
03518 ModelImpl* FCOImpl::getParentModelI( const MON::Model& meta )
03519 {
03520
03521 if ( m_parentModel.first )
03522 return ( ! meta || meta == m_parentModel.first ) ? m_parentModel.second : NULL;
03523 if ( m_bAllParentModels )
03524 return NULL;
03525
03526
03527 ObjectPtr spObject;
03528 COMCHECK2( getObjectI(), getObjectI()->GetParent( spObject.Addr() ) );
03529 CComQIPtr<IMgaModel> spModel = spObject;
03530
03531
03532 if ( ! spModel ) {
03533 m_bAllParentModels = true;
03534 return NULL;
03535 }
03536
03537
03538 if ( ! meta || meta.ref() == _getMetaRef( spModel ) ) {
03539 m_parentModel.first = ( meta ) ? meta : MON::Model( getProject()->getProjectMeta().findByName( _getMetaName( spModel ) ) );
03540 m_parentModel.second = ModelImpl::attachI( spModel, ObjectImpl::m_pProject, m_parentModel.first );
03541 m_parentModel.second->onRetrievedAsFCOParent( this, false );
03542 if ( ! meta )
03543 m_bAllParentModels = true;
03544 }
03545 return m_parentModel.second;
03546 }
03547
03548 bool FCOImpl::isSetsRetrieved( const MON::Set& meta )
03549 {
03550 ManySetLink::iterator it = m_sets.find( meta );
03551 if ( it != m_sets.end() ) {
03552 if ( it->second.first )
03553 return true;
03554 it->second.first = true;
03555 return false;
03556 }
03557 m_sets[ meta ] = SetSetPair( true, SetSet() );
03558 return false;
03559 }
03560
03561 void FCOImpl::getSets( std::set<SetPtr>& setSPSets )
03562 {
03563 Util::ComPtr<IMgaFCOs> spSets;
03564 COMCHECK2( getFCOI(), getFCOI()->get_MemberOfSets( spSets.Addr() ) );
03565 MGACOLL_ITERATE( IMgaFCO, spSets.p ) {
03566 CComQIPtr<IMgaSet> spSet = MGACOLL_ITER;
03567 setSPSets.insert( spSet.p );
03568 } MGACOLL_ITERATE_END;
03569 }
03570
03571 void FCOImpl::getSets( const MON::Set& meta, std::set<SetPtr>& setSPSets, bool bErase )
03572 {
03573 std::set<SetPtr>::iterator it = setSPSets.begin();
03574 while ( it != setSPSets.end() ) {
03575 std::set<SetPtr>::iterator itSaved = it;
03576 it++;
03577 if ( _getMetaRef( *itSaved ) == meta.ref() ) {
03578 SetImpl* pSet = SetImpl::attachI( *itSaved, ObjectImpl::m_pProject, meta );
03579 if ( m_sets[ meta ].second.find( pSet ) == m_sets[ meta ].second.end() ) {
03580 m_sets[ meta ].second.insert( pSet );
03581 pSet->onRetrievedAsSet( this, false );
03582 }
03583 if ( bErase )
03584 setSPSets.erase( itSaved );
03585 }
03586 }
03587 }
03588
03589 SetSet FCOImpl::getSetsI( const MON::Set& meta )
03590 {
03591
03592 if ( meta ) {
03593 if ( ! isSetsRetrieved( meta ) ) {
03594 std::set<SetPtr> setSPSets;
03595 getSets( setSPSets );
03596 getSets( meta, setSPSets, false );
03597 }
03598 return m_sets[ meta ].second;
03599 }
03600
03601
03602 if ( ! m_bAllSets ) {
03603 m_bAllSets= true;
03604 std::set<SetPtr> setSPSets;
03605 getSets( setSPSets );
03606 std::set<MON::Set> setSets = getFCOMeta().memberOf();
03607 for ( std::set<MON::Set>::iterator it = setSets.begin() ; it != setSets.end() ; it++ ) {
03608 if ( ! isSetsRetrieved( *it ) )
03609 getSets( *it, setSPSets, true );
03610 }
03611 }
03612
03613
03614 SetSet setSets;
03615 for ( ManySetLink::iterator it = m_sets.begin() ; it != m_sets.end() ; it++ )
03616 setSets.insert( it->second.second.begin(), it->second.second.end() );
03617 return setSets;
03618 }
03619
03620 bool FCOImpl::isReferencesRetrieved( const MON::Reference& meta )
03621 {
03622 ManyReferenceLink::iterator it = m_references.find( meta );
03623 if ( it != m_references.end() ) {
03624 if ( it->second.first )
03625 return true;
03626 it->second.first = true;
03627 return false;
03628 }
03629 m_references[ meta ] = ReferenceSetPair( true, ReferenceSet() );
03630 return false;
03631 }
03632
03633 void FCOImpl::getReferences( std::set<ReferencePtr>& setSPReferences )
03634 {
03635 Util::ComPtr<IMgaFCOs> spReferences;
03636 COMCHECK2( getFCOI(), getFCOI()->get_ReferencedBy( spReferences.Addr() ) );
03637 MGACOLL_ITERATE( IMgaFCO, spReferences.p ) {
03638 CComQIPtr<IMgaReference> spReference = MGACOLL_ITER;
03639 setSPReferences.insert( spReference.p );
03640 } MGACOLL_ITERATE_END;
03641 }
03642
03643 void FCOImpl::getReferences( const MON::Reference& meta, std::set<ReferencePtr>& setSPReferences, bool bErase )
03644 {
03645 std::set<ReferencePtr>::iterator it = setSPReferences.begin();
03646 while ( it != setSPReferences.end() ) {
03647 std::set<ReferencePtr>::iterator itSaved = it;
03648 it++;
03649 if ( _getMetaRef( *itSaved ) == meta.ref() ) {
03650 ReferenceImpl* pReference = ReferenceImpl::attachI( *itSaved, ObjectImpl::m_pProject, meta );
03651 if ( m_references[ meta ].second.find( pReference ) == m_references[ meta ].second.end() ) {
03652 m_references[ meta ].second.insert( pReference );
03653 pReference->onRetrievedAsReference( this, false );
03654 }
03655 if ( bErase )
03656 setSPReferences.erase( itSaved );
03657 }
03658 }
03659 }
03660
03661 ReferenceSet FCOImpl::getReferencesI( const MON::Reference& meta )
03662 {
03663
03664 if ( meta ) {
03665 if ( ! isReferencesRetrieved( meta ) ) {
03666 std::set<ReferencePtr> setSPReferences;
03667 getReferences( setSPReferences );
03668 getReferences( meta, setSPReferences, false );
03669 }
03670 return m_references[ meta ].second;
03671 }
03672
03673
03674 if ( ! m_bAllReferences ) {
03675 m_bAllReferences = true;
03676 std::set<ReferencePtr> setSPReferences;
03677 getReferences( setSPReferences );
03678 std::set<MON::Reference> setRefs = getFCOMeta().referencedBy();
03679 for ( std::set<MON::Reference>::iterator it = setRefs.begin() ; it != setRefs.end() ; it++ ) {
03680 if ( ! isReferencesRetrieved( *it ) )
03681 getReferences( *it, setSPReferences, true );
03682 }
03683 }
03684
03685
03686 ReferenceSet setReferences;
03687 for ( ManyReferenceLink::iterator it = m_references.begin() ; it != m_references.end() ; it++ )
03688 setReferences.insert( it->second.second.begin(), it->second.second.end() );
03689 return setReferences;
03690 }
03691
03692 FCOImpl* FCOImpl::getType()
03693 {
03694 if ( m_bAllTypeFCOs )
03695 return m_pType;
03696 m_bAllTypeFCOs = true;
03697 FCOPtr spFCO;
03698 VARIANT_BOOL vbInstance;
03699 COMCHECK2( getFCOI(), getFCOI()->get_IsInstance( &vbInstance ) );
03700 if (vbInstance) {
03701 COMCHECK2( getFCOI(), getFCOI()->get_Type( spFCO.Addr() ) );
03702 }
03703 else
03704 {
03705 COMCHECK2( getFCOI(), getFCOI()->get_BaseType( spFCO.Addr() ) );
03706 }
03707
03708 if ( spFCO ) {
03709 m_pType = FCOImpl::attachI( spFCO, ObjectImpl::m_pProject, getObjectMeta() );
03710 m_pType->onRetrievedAsType( this, false );
03711 }
03712 return m_pType;
03713 }
03714
03715 FCOSet FCOImpl::getDerivedFCOs( bool bInstance )
03716 {
03717 if ( bInstance && ! m_bAllInstanceFCOs || ! bInstance && ! m_bAllSubTypeFCOs ) {
03718 Util::ComPtr<IMgaFCOs> spFCOs;
03719 COMCHECK2( getFCOI(), getFCOI()->get_DerivedObjects( spFCOs.Addr() ) );
03720 MGACOLL_ITERATE( IMgaFCO, spFCOs.p ) {
03721 VARIANT_BOOL vbInstance;
03722 COMCHECK2( MGACOLL_ITER, MGACOLL_ITER->get_IsInstance( &vbInstance ) );
03723 if ( bInstance && vbInstance || ! bInstance && ! vbInstance ) {
03724 FCOImpl* pFCO = FCOImpl::attachI( MGACOLL_ITER, ObjectImpl::m_pProject, getObjectMeta() );
03725 if ( bInstance )
03726 m_setInstances.insert( pFCO );
03727 else
03728 m_setSubTypes.insert( pFCO );
03729 pFCO->onRetrievedAsDerived( this, false );
03730 }
03731 } MGACOLL_ITERATE_END;
03732 }
03733 if ( bInstance )
03734 m_bAllInstanceFCOs = true;
03735 else
03736 m_bAllSubTypeFCOs = true;
03737 return ( bInstance ) ? m_setInstances : m_setSubTypes;
03738 }
03739
03740
03741
03742
03743 bool FCOImpl::onRetrievedAsType( FCOImpl* pFCO, bool bCheckAll )
03744 {
03745 if ( pFCO->isInstance() ) {
03746 if ( bCheckAll && ! m_bAllInstanceFCOs )
03747 return false;
03748 m_setInstances.insert( pFCO );
03749 return true;
03750 }
03751 else {
03752 if ( bCheckAll && ! m_bAllSubTypeFCOs )
03753 return false;
03754 m_setSubTypes.insert( pFCO );
03755 return true;
03756 }
03757 }
03758
03759 void FCOImpl::onReleasedAsType( FCOImpl* pFCO, bool bOnlyFreeMemory )
03760 {
03761 if ( pFCO->isInstance() ) {
03762 m_setInstances.erase( pFCO );
03763 if ( bOnlyFreeMemory )
03764 m_bAllInstanceFCOs = false;
03765 }
03766 else {
03767 m_setSubTypes.erase( pFCO );
03768 if ( bOnlyFreeMemory )
03769 m_bAllSubTypeFCOs = false;
03770 }
03771 }
03772
03773 bool FCOImpl::onRetrievedAsDerived( FCOImpl* pFCO, bool bCheckAll )
03774 {
03775 m_bAllTypeFCOs = true;
03776 m_pType = pFCO;
03777 return true;
03778 }
03779
03780 void FCOImpl::onReleasedAsDerived( FCOImpl* pFCO, bool bOnlyFreeMemory )
03781 {
03782 m_bAllTypeFCOs = false;
03783 m_pType = NULL;
03784 }
03785
03786 bool FCOImpl::onRetrievedAsModelChild( ModelImpl* pModel, bool bCheckAll )
03787 {
03788 m_bAllParentModels = true;
03789 m_parentModel.first = pModel->getModelMeta();
03790 m_parentModel.second = pModel;
03791 return true;
03792 }
03793
03794 void FCOImpl::onReleasedAsModelChild( ModelImpl* pFolder, bool bOnlyFreeMemory )
03795 {
03796 m_bAllParentModels = false;
03797 m_parentModel.first = MON::Model();
03798 m_parentModel.second = NULL;
03799 }
03800
03801 bool FCOImpl::onRetrievedAsMember( SetImpl* pSet, bool bCheckAll )
03802 {
03803 ManySetLink::iterator it = m_sets.find( pSet->getSetMeta() );
03804 if ( it == m_sets.end() ) {
03805 if ( bCheckAll )
03806 return false;
03807 m_sets[ pSet->getSetMeta() ] = SetSetPair( false, SetSet() );
03808 }
03809 if ( ! bCheckAll || bCheckAll && m_sets[ pSet->getSetMeta() ].first ) {
03810 m_sets[ pSet->getSetMeta() ].second.insert( pSet );
03811 return true;
03812 }
03813 return false;
03814 }
03815
03816 void FCOImpl::onReleasedAsMember( SetImpl* pSet, bool bOnlyFreeMemory )
03817 {
03818 ManySetLink::iterator it = m_sets.find( pSet->getSetMeta() );
03819 if ( it != m_sets.end() ) {
03820 m_sets[ pSet->getSetMeta() ].second.erase( pSet );
03821 if ( bOnlyFreeMemory && m_sets[ pSet->getSetMeta() ].first ) {
03822 m_sets[ pSet->getSetMeta() ].first = false;
03823 m_bAllSets = false;
03824 }
03825 }
03826 }
03827
03828 bool FCOImpl::onRetrievedAsReferred( ReferenceImpl* pReference, bool bCheckAll )
03829 {
03830 ManyReferenceLink::iterator it = m_references.find( pReference->getReferenceMeta() );
03831 if ( it == m_references.end() ) {
03832 if ( bCheckAll )
03833 return false;
03834 m_references[ pReference->getReferenceMeta() ] = ReferenceSetPair( false, ReferenceSet() );
03835 }
03836 if ( ! bCheckAll || bCheckAll && m_references[ pReference->getReferenceMeta() ].first ) {
03837 m_references[ pReference->getReferenceMeta() ].second.insert( pReference );
03838 return true;
03839 }
03840 return false;
03841 }
03842
03843 void FCOImpl::onReleasedAsReferred( ReferenceImpl* pReference, bool bOnlyFreeMemory )
03844 {
03845 ManyReferenceLink::iterator it = m_references.find( pReference->getReferenceMeta() );
03846 if ( it != m_references.end() ) {
03847 m_references[ pReference->getReferenceMeta() ].second.erase( pReference );
03848 if ( bOnlyFreeMemory && m_references[ pReference->getReferenceMeta() ].first ) {
03849 m_references[ pReference->getReferenceMeta() ].first = false;
03850 m_bAllReferences = false;
03851 }
03852 }
03853 }
03854
03855 bool FCOImpl::onRetrievedAsReferencePort( ReferencePortImpl* pPort, bool bCheckAll )
03856 {
03857 if ( bCheckAll && ! m_bAllRefPorts )
03858 return false;
03859 m_refPorts.insert( pPort );
03860 return true;
03861 }
03862
03863 void FCOImpl::onReleasedAsReferencePort( ReferencePortImpl* pPort, bool bOnlyFreeMemory )
03864 {
03865 m_refPorts.erase( pPort );
03866 if ( bOnlyFreeMemory )
03867 m_bAllRefPorts = false;
03868 }
03869
03870 void FCOImpl::eventPerformedI( const Event& event )
03871 {
03872 ObjectImpl::eventPerformedI( event );
03873 switch ( event.getType() ) {
03874 case MON::OET_ObjectCreated :
03875 onObjectCreated();
03876 break;
03877 case MON::OET_DescendantCreated :
03878 onObjectDerived( NULL );
03879 break;
03880 case MON::OET_ObjectMoved :
03881 onObjectMoved( NULL, NULL );
03882 break;
03883 case MON::OET_ObjectReferenced :
03884 onFCOReferenced( NULL );
03885 break;
03886 case MON::OET_ObjectReleased :
03887 onFCOUnreferenced( NULL );
03888 break;
03889 case MON::OET_ObjectIncluded :
03890 onFCOIncluded( NULL );
03891 break;
03892 case MON::OET_ObjectExcluded :
03893 onFCOExcluded( NULL );
03894 break;
03895 }
03896 }
03897
03898 void FCOImpl::onObjectCreated()
03899 {
03900 FCO( this->getType() );
03901 if (getParentModelI())
03902 {
03903 ReferenceSet references = getParentModelI()->getReferencesI();
03904 for ( ReferenceSet::iterator it = references.begin() ; it != references.end() ; ++it )
03905 {
03906 (**it).m_bAllChildPorts = false;
03907 }
03908 }
03909
03910 try {
03911 std::set<ReferencePort> rps = getReferencePorts();
03912 for( std::set<ReferencePort>::const_iterator it = rps.begin(); it != rps.end(); ++it)
03913 {
03914 Reference ref = (*it)->getContainer()->getReference();
03915 m_storedRefWrappers.insert( ref);
03916 }
03917 rps.clear();
03918
03919 } catch(...) {
03920 bool b = true;
03921 b = !b;
03922 ASSERT(0);
03923 }
03924
03925
03926 ObjectPtr spObject;
03927 COMCHECK2( getObjectI(), getObjectI()->GetParent( spObject.Addr() ) );
03928 Model model( ObjectImpl::attachI( spObject, (ProjectImpl*) getProject().getCounted() ) );
03929 if ( model )
03930 model->onChildAdded( this );
03931
03932 }
03933
03934 void FCOImpl::onObjectDerived( FCOImpl* pFCO )
03935 {
03936 if ( ! _isAddOn() ) {
03937 if ( pFCO ) {
03938 if ( onRetrievedAsType( pFCO, true ) )
03939 pFCO->onRetrievedAsDerived( this, false );
03940 }
03941 else {
03942 m_bAllSubTypeFCOs = false;
03943 m_bAllInstanceFCOs = false;
03944 }
03945 }
03946 }
03947
03948 void FCOImpl::onObjectMoved( ObjectImpl* pOldParent, ObjectImpl* pNewParent )
03949 {
03950 if ( pOldParent && pNewParent ) {
03951 if ( pOldParent->getStereotype() == OT_Model )
03952 dynamic_cast<ModelImpl*>( pOldParent )->onChildRemoved( this );
03953 if ( pNewParent->getStereotype() == OT_Model )
03954 dynamic_cast<ModelImpl*>( pNewParent )->onChildAdded( this );
03955 return;
03956 }
03957 }
03958
03959 void FCOImpl::onFCOReferenced( ReferenceImpl* pReference )
03960 {
03961 if ( pReference ) {
03962 if ( onRetrievedAsReferred( pReference, true ) )
03963 pReference->onRetrievedAsReference( this, false );
03964 return;
03965 }
03966 }
03967
03968 void FCOImpl::onFCOUnreferenced( ReferenceImpl* pReference )
03969 {
03970 if ( pReference ) {
03971 onReleasedAsReferred( pReference, false );
03972 pReference->onReleasedAsReference( this, false );
03973 return;
03974 }
03975 }
03976
03977 void FCOImpl::onFCOIncluded( SetImpl* pSet )
03978 {
03979 if ( pSet ) {
03980 if ( onRetrievedAsMember( pSet, true ) )
03981 pSet->onRetrievedAsSet( this, false );
03982 return;
03983 }
03984 }
03985
03986 void FCOImpl::onFCOExcluded( SetImpl* pSet )
03987 {
03988 if ( pSet ) {
03989 onReleasedAsMember( pSet, false );
03990 pSet->onReleasedAsSet( this, false );
03991 return;
03992 }
03993 }
03994
03995
03996
03997
03998 TypeInhObject FCOImpl::getTypeInhObject() const
03999 {
04000 return m_pTIObject;
04001 }
04002
04003 Object FCOImpl::getParent()
04004 {
04005 Object object = ObjectImpl::getParent();
04006 if ( object )
04007 return object;
04008 return getParentModel();
04009 }
04010
04011 std::set<ReferencePort> FCOImpl::getReferencePorts( const MON::Aspect& meta )
04012 {
04013 if ( meta )
04014 THROW_METAPROJECT_BELONG( meta );
04015
04016 std::set<ReferencePort> setResult;
04017 Model parent = getParentModel();
04018 if ( ! parent )
04019 return setResult;
04020
04021 if ( meta ) {
04022 THROW_METAPROJECT_BELONG( meta );
04023 if ( ! parent->getModelMeta().hasAspect( meta ) || ! getRole().isVisibleIn( meta ) )
04024 return setResult;
04025 }
04026
04027 setCopy<ReferencePort,ReferencePortImpl>( getRefPortRefsI(), setResult );
04028
04029 if ( meta ) {
04030 std::set<ReferencePort>::iterator it2 = setResult.begin();
04031 while ( it2 != setResult.end() ) {
04032 std::set<ReferencePort>::iterator itSaved = it2;
04033 it2++;
04034 MON::Containment role = (*itSaved)->getContainer()->getReference()->getRole();
04035 if ( role && ! role.isVisibleIn( meta ) )
04036 setResult.erase( itSaved );
04037 }
04038 }
04039
04040 return setResult;
04041 }
04042
04043 Model FCOImpl::getParentModel( const MON::Model& meta )
04044 {
04045 if ( meta ) {
04046 THROW_METAPROJECT_BELONG( meta );
04047 if ( ! getFCOMeta().isModelParent( meta ) )
04048 {
04049 MON::Exception exc( "? cannot be parent of ?!");
04050 exc << meta.infoString() << getObjectMeta().infoString();
04051 ASSERTTHROW( exc);
04052 }
04053 }
04054 return getParentModelI( meta );
04055 }
04056
04057 Model FCOImpl::getParentModel( const std::string& strModel )
04058 {
04059 MON::Model meta;
04060 if ( ! strModel.empty() ) {
04061 meta = MON::Model( getProject()->getProjectMeta().findByName( strModel ) );
04062 THROW_METAPROJECT_DOES_NOT_HAVE( meta, Model, strModel );
04063 }
04064 return getParentModel( meta );
04065 }
04066
04067 Model FCOImpl::getParentModelAs( const std::string& strRole )
04068 {
04069 if ( strRole.empty() )
04070 return getParentModel();
04071
04072 MON::Containment role;
04073 std::set<MON::Containment> roles = getFCOMeta().parentContainments();
04074 for ( std::set<MON::Containment>::iterator it = roles.begin() ; it != roles.end() ; it++ )
04075 if ( it->name() == strRole || it->name() == ObjectImpl::m_pProject->prefixWNmsp( strRole)) {
04076 role = *it;
04077 break;
04078 }
04079
04080 if ( ! role )
04081 {
04082 MON::Exception exc( "? cannot be child in MON::Model with containment role of ?!");
04083 exc << getObjectMeta().infoString() << strRole;
04084 ASSERTTHROW( exc);
04085 }
04086
04087 ModelImpl* pModel = getParentModelI( role.child() );
04088 return ( pModel && pModel->getRole() == role ) ? pModel : NULL;
04089 }
04090
04091 std::set<Set> FCOImpl::getMemberOf( const MON::Set& meta, const MON::Aspect& aspect )
04092 {
04093 if ( aspect )
04094 THROW_METAPROJECT_BELONG( aspect );
04095
04096 if ( meta ) {
04097 THROW_METAPROJECT_BELONG( meta );
04098 if ( ! getFCOMeta().isMemberOf( meta ) )
04099 {
04100 MON::Exception exc( "? cannot be member of ?!");
04101 exc << getObjectMeta().infoString() << meta.infoString();
04102 ASSERTTHROW( exc);
04103 }
04104 }
04105 std::set<Set> setResult;
04106 setCopy<Set,SetImpl>( getSetsI( meta ), setResult );
04107 return filterByAspect<Set>( setResult, aspect );
04108 }
04109
04110 std::set<Set> FCOImpl::getMemberOf( const std::string& strSet, const MON::Aspect& aspect )
04111 {
04112 MON::Set meta;
04113 if ( ! strSet.empty() ) {
04114 meta = MON::Set( getProject()->getProjectMeta().findByName( strSet ) );
04115 THROW_METAPROJECT_DOES_NOT_HAVE( meta, Set, strSet );
04116 }
04117 return getMemberOf( meta, aspect );
04118 }
04119
04120 std::set<Reference> FCOImpl::getReferredBy( const MON::Reference& meta )
04121 {
04122 if ( meta ) {
04123 THROW_METAPROJECT_BELONG( meta );
04124 if ( ! getFCOMeta().isReferencedBy( meta ) )
04125 {
04126 MON::Exception exc( "? cannot be referenced by ?!");
04127 exc << getObjectMeta().infoString() << meta.infoString();
04128 ASSERTTHROW( exc);
04129 }
04130 }
04131 std::set<Reference> setResult;
04132 setCopy<Reference,ReferenceImpl>( getReferencesI( meta ), setResult );
04133 return setResult;
04134 }
04135
04136 std::set<Reference> FCOImpl::getReferredBy( const std::string& strReference )
04137 {
04138 MON::Reference meta;
04139 if ( ! strReference.empty() ) {
04140 meta = MON::Reference( getProject()->getProjectMeta().findByName( strReference ) );
04141 THROW_METAPROJECT_DOES_NOT_HAVE( meta, Reference, strReference );
04142 }
04143 return getReferredBy( meta );
04144 }
04145
04146 std::set<Attribute> FCOImpl::getAttributes()
04147 {
04148 std::set<Attribute> attributes;
04149 std::set<MON::Attribute> metaattributes = getFCOMeta().attributes();
04150 for ( std::set<MON::Attribute>::iterator it = metaattributes.begin() ; it != metaattributes.end() ; it++ )
04151 attributes.insert( getAttributeI( *it ) );
04152 return attributes;
04153 }
04154
04155 Attribute FCOImpl::getAttribute( const MON::Attribute& meta )
04156 {
04157 THROW_CANNOT_BE_NULL( meta, "MON::Attribute" );
04158 THROW_METAPROJECT_BELONG( meta );
04159
04160 std::set<MON::Attribute> attributes = getFCOMeta().attributes();
04161 if ( attributes.find( meta ) == attributes.end() )
04162 {
04163 MON::Exception exc( "? is not associated with ?!");
04164 exc << meta.infoString() << getObjectMeta().infoString();
04165 ASSERTTHROW( exc);
04166 }
04167
04168 return getAttributeI( meta );
04169 }
04170
04171 Attribute FCOImpl::getAttribute( const std::string& strName )
04172 {
04173 MON::Attribute meta;
04174 if ( ! strName.empty() ) {
04175 std::set<MON::Attribute> attributes = getFCOMeta().attributes();
04176 for ( std::set<MON::Attribute>::iterator it = attributes.begin() ; it != attributes.end() ; it++ )
04177 if ( it->name() == strName )
04178 return getAttributeI( *it );
04179 }
04180 return NULL;
04181 }
04182
04183 FCO FCOImpl::copy( const Folder& parent )
04184 {
04185 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
04186 THROW_PROJECT_BELONG( parent );
04187
04188 if ( ! parent->getFolderMeta().isObjectChild( getObjectMeta() ) )
04189 {
04190 MON::Exception exc( "? cannot be parent of ?!");
04191 exc << parent->getObjectMeta().infoString() << getObjectMeta().infoString();
04192 ASSERTTHROW( exc);
04193 }
04194
04195 FCOsPtr spInSet;
04196 FCOsPtr spOutSet;
04197 BONCOMTHROW( spInSet.CoCreateInstance( L"Mga.MgaFCOs" ) );
04198 COMCHECK2( spInSet, spInSet->Append( getFCOI() ) );
04199 FCOPtr spFCO;
04200 COMCHECK2( parent->getFolderI(), parent->getFolderI()->CopyFCOs( spInSet, spOutSet.Addr() ) );
04201 COMCHECK2( spOutSet, spOutSet->get_Item( 1, spFCO.Addr() ) );
04202 FCOImpl* pFCO = FCOImpl::attachI( spFCO, (ProjectImpl*) getProject().getCounted(), getObjectMeta() );
04203 if ( getProject()->isAutoCommit() )
04204 getProject()->commit();
04205 if ( ! _isAddOn() ) {
04206 pFCO->eventPerformedI( Event( MON::OET_ObjectCreated, pFCO ) );
04207 eventPerformedI( Event( MON::OET_DescendantCreated, pFCO ) );
04208 }
04209 return pFCO;
04210 }
04211
04212 FCO FCOImpl::move( const Folder& parent )
04213 {
04214 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
04215 THROW_PROJECT_BELONG( parent );
04216
04217 if ( getParent() == parent )
04218 return this;
04219
04220 if ( ! parent->getFolderMeta().isObjectChild( getObjectMeta() ) )
04221 {
04222 MON::Exception exc( "? cannot be parent of ?!");
04223 exc << parent->getObjectMeta().infoString() << getObjectMeta().infoString();
04224 ASSERTTHROW( exc);
04225 }
04226
04227 Model m = getParent();
04228 Folder f = getParent();
04229 if ( m )
04230 m->onChildRemoved( this );
04231 else if ( f )
04232 f->onChildRemoved( this );
04233
04234 FCOsPtr spInSet;
04235 FCOsPtr spOutSet;
04236 BONCOMTHROW( spInSet.CoCreateInstance( L"Mga.MgaFCOs" ) );
04237 COMCHECK2( spInSet, spInSet->Append( getFCOI() ) );
04238
04239 COMCHECK2( parent->getFolderI(), parent->getFolderI()->MoveFCOs( spInSet, spOutSet.Addr() ) );
04240 FCOPtr spFCO;
04241 COMCHECK2( spOutSet, spOutSet->get_Item( 1, spFCO.Addr() ) );
04242 if ( getProject()->isAutoCommit() )
04243 getProject()->commit();
04244 return FCOImpl::attachI( spFCO, (ProjectImpl*) getProject().getCounted(), getObjectMeta() );
04245 }
04246
04247 FCO FCOImpl::copy( const Model& parent, const std::string strRole )
04248 {
04249 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
04250 THROW_PROJECT_BELONG( parent );
04251
04252 MON::Containment role;
04253 std::set<MON::Containment> roles = parent->getModelMeta().childContainments();
04254 for ( std::set<MON::Containment>::iterator it = roles.begin() ; it != roles.end() ; it++ )
04255 if ( it->child() == getObjectMeta() && ( strRole.empty() || strRole == it->name() ) ) {
04256 if ( role )
04257 {
04258 MON::Exception exc( "Role must be specified! ? can consist ? with multiple roles!");
04259 exc << parent->getObjectMeta().infoString() << getObjectMeta().infoString();
04260 ASSERTTHROW( exc);
04261 }
04262 role = *it;
04263 }
04264 if ( ! role ) {
04265 if ( strRole.empty() )
04266 {
04267 MON::Exception exc( "? cannot be parent of ?!");
04268 exc << parent->getObjectMeta().infoString() << getObjectMeta().infoString();
04269 ASSERTTHROW( exc);
04270 }
04271 MON::Exception exc( "? cannot be parent of ? with role [ ? ]!");
04272 exc << parent->getObjectMeta().infoString() << getObjectMeta().infoString() << strRole;
04273 ASSERTTHROW( exc);
04274 }
04275
04276 FCOsPtr spInSet;
04277 BONCOMTHROW( spInSet.CoCreateInstance( L"Mga.MgaFCOs" ) );
04278 COMCHECK2( spInSet, spInSet->Append( getFCOI() ) );
04279 Util::ComPtr<IMgaMetaRoles> spRoles;
04280 BONCOMTHROW( spRoles.CoCreateInstance( L"Mga.MgaMetaRoles" ) );
04281 COMCHECK2( spRoles, spRoles->Append( role.getContainmentI() ) );
04282 FCOsPtr spOutSet;
04283 COMCHECK2( parent->getModelI(), parent->getModelI()->CopyFCOs( spInSet, spRoles, spOutSet.Addr() ) );
04284 FCOPtr spFCO;
04285 COMCHECK2( spOutSet, spOutSet->get_Item( 1, spFCO.Addr() ) );
04286
04287 FCOImpl* pFCO = FCOImpl::attachI( spFCO, (ProjectImpl*) getProject().getCounted(), getObjectMeta() );
04288 if ( getProject()->isAutoCommit() )
04289 getProject()->commit();
04290 if ( ! _isAddOn() ) {
04291 pFCO->eventPerformedI( Event( MON::OET_ObjectCreated, pFCO ) );
04292 eventPerformedI( Event( MON::OET_DescendantCreated, pFCO ) );
04293 }
04294 return pFCO;
04295 }
04296
04297 FCO FCOImpl::move( const Model& parent, const std::string strRole )
04298 {
04299 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
04300 THROW_PROJECT_BELONG( parent );
04301
04302 MON::Containment role;
04303 std::set<MON::Containment> roles = parent->getModelMeta().childContainments();
04304 for ( std::set<MON::Containment>::iterator it = roles.begin() ; it != roles.end() ; it++ )
04305 if ( it->child() == getObjectMeta() && ( strRole.empty() || strRole == it->name() ) ) {
04306 if ( role )
04307 {
04308 MON::Exception exc( "Role must be specified! ? can consist ? with multiple roles!");
04309 exc << parent->getObjectMeta().infoString() << getObjectMeta().infoString();
04310 ASSERTTHROW( exc);
04311 }
04312 role = *it;
04313 }
04314 if ( ! role ) {
04315 if ( strRole.empty() )
04316 {
04317 MON::Exception exc( "? cannot be parent of ?!");
04318 exc << parent->getObjectMeta().infoString() << getObjectMeta().infoString();
04319 ASSERTTHROW( exc);
04320 }
04321 MON::Exception exc( "? cannot be parent of ? with role [ ? ]!");
04322 exc << parent->getObjectMeta().infoString() << getObjectMeta().infoString() << strRole;
04323 ASSERTTHROW( exc);
04324 }
04325
04326 if ( getParent() == parent && role == getRole() )
04327 return this;
04328 Model m = getParent();
04329 Folder f = getParent();
04330 if ( m )
04331 m->onChildRemoved( this );
04332 else if ( f )
04333 f->onChildRemoved( this );
04334
04335 FCOsPtr spInSet;
04336 BONCOMTHROW( spInSet.CoCreateInstance( L"Mga.MgaFCOs" ) );
04337 COMCHECK2( spInSet, spInSet->Append( getFCOI() ) );
04338 Util::ComPtr<IMgaMetaRoles> spRoles;
04339 BONCOMTHROW( spRoles.CoCreateInstance( L"Mga.MgaMetaRoles" ) );
04340 COMCHECK2( spRoles, spRoles->Append( role.getContainmentI() ) );
04341 FCOsPtr spOutSet;
04342 COMCHECK2( parent->getModelI(), parent->getModelI()->MoveFCOs( spInSet, spRoles, spOutSet.Addr() ) );
04343 FCOPtr spFCO;
04344 COMCHECK2( spOutSet, spOutSet->get_Item( 1, spFCO.Addr() ) );
04345 if ( getProject()->isAutoCommit() )
04346 getProject()->commit();
04347
04348 return FCOImpl::attachI( spFCO, (ProjectImpl*) getProject().getCounted(), getObjectMeta() );
04349 }
04350
04351
04352
04353
04354 void FCOImpl::accept( Visitor* pVisitor )
04355 {
04356 switch ( getStereotype() ) {
04357 case OT_Model :
04358 dynamic_cast<ModelImpl*>( this )->accept( pVisitor );
04359 break;
04360 case OT_Atom :
04361 dynamic_cast<AtomImpl*>( this )->accept( pVisitor );
04362 break;
04363 case OT_Set :
04364 dynamic_cast<SetImpl*>( this )->accept( pVisitor );
04365 break;
04366 case OT_Reference :
04367 dynamic_cast<ReferenceImpl*>( this )->accept( pVisitor );
04368 break;
04369 case OT_Connection :
04370 dynamic_cast<ConnectionImpl*>( this )->accept( pVisitor );
04371 break;
04372 }
04373 }
04374
04375 FCORegistryNode FCOImpl::getRegistry() const
04376 {
04377 return ObjectImpl::getRegistry();
04378 }
04379
04380
04381
04382
04383
04384
04385
04386 AttributeImpl::AttributeImpl( IMgaAttribute* spAttribute, FCOImpl* pFCO, const MON::Attribute& meta )
04387 : Util::GenRefCounted( false, pFCO ), m_spAttribute( spAttribute ), m_pFCO( pFCO ), m_meta( meta )
04388 {
04389 }
04390
04391 AttributeImpl* AttributeImpl::attachI( IMgaAttribute* spAttribute, FCOImpl* pFCO, const MON::Attribute& meta )
04392 {
04393 return new AttributeImpl( spAttribute, pFCO, meta );
04394 }
04395
04396 AttributeImpl::~AttributeImpl()
04397 {
04398 m_pFCO = NULL;
04399 m_spAttribute = NULL;
04400 m_meta = NULL;
04401 }
04402
04403 bool AttributeImpl::setDeleted()
04404 {
04405 return isDeleted();
04406 }
04407
04408 void AttributeImpl::checkTypes( const Util::Variant& value, bool bExc ) const
04409 {
04410 if ( bExc && ! value.isUndefined() ) {
04411 switch ( getAttributeMeta().valueType() ) {
04412 case MON::AT_Boolean :
04413 if ( value.type() != Util::Variant::VT_Boolean )
04414 {
04415 Exception exc( "Type mismatch! ? is typed as Boolean!");
04416 exc << getAttributeMeta().infoString();
04417 ASSERTTHROW( exc);
04418 }
04419 case MON::AT_String :
04420 if ( value.type() != Util::Variant::VT_String )
04421 {
04422 Exception exc( "Type mismatch! ? is typed as String!");
04423 exc << getAttributeMeta().infoString();
04424 ASSERTTHROW( exc);
04425 }
04426 case MON::AT_Integer :
04427 if ( value.type() != Util::Variant::VT_Integer )
04428 {
04429 Exception exc( "Type mismatch! ? is typed as Integer!");
04430 exc << getAttributeMeta().infoString();
04431 ASSERTTHROW( exc);
04432 }
04433 case MON::AT_Real :
04434 if ( value.type() != Util::Variant::VT_Double )
04435 {
04436 Exception exc( "Type mismatch! ? is typed as Real!");
04437 exc << getAttributeMeta().infoString();
04438 ASSERTTHROW( exc);
04439 }
04440 case MON::AT_Enumeration :
04441 if ( value.type() != Util::Variant::VT_String )
04442 {
04443 Exception exc( "Type mismatch! ? is typed as Enumeration!");
04444 exc << getAttributeMeta().infoString();
04445 ASSERTTHROW( exc);
04446 }
04447 std::vector<MON::Attribute::NameValue> items = getAttributeMeta().enumItems();
04448 for ( int i = 0 ; i < items.size() ; i++ )
04449 if ( items[ i ].first == (std::string) value )
04450 return;
04451 Exception exc( "Type mismatch! ? which is typed Enumeration has no Item called ?!");
04452 exc << getAttributeMeta().infoString() << (std::string) value;
04453 ASSERTTHROW( exc);
04454 }
04455 }
04456 }
04457
04458 Util::Variant AttributeImpl::checkTypes( Util::Variant::Type eType, const Util::Variant& value, bool bExc ) const
04459 {
04460 if ( bExc && ! value.isUndefined() && eType != value.type() ) {
04461 std::string strType;
04462 switch ( getAttributeMeta().valueType() ) {
04463 case MON::AT_Boolean :
04464 strType = "Boolean"; break;
04465 case MON::AT_String :
04466 strType = "String"; break;
04467 case MON::AT_Integer :
04468 strType = "Integer"; break;
04469 case MON::AT_Real :
04470 strType = "Real"; break;
04471 case MON::AT_Enumeration :
04472 strType = "Enumeration"; break;
04473 }
04474 Exception exc( "Type mismatch! ? is typed as ?!");
04475 exc << getAttributeMeta().infoString() << strType;
04476 ASSERTTHROW( exc);
04477 }
04478 return value;
04479 }
04480
04481
04482
04483
04484 Project AttributeImpl::getProject() const
04485 {
04486 return m_pFCO->getProject();
04487 }
04488
04489 FCO AttributeImpl::getFCO() const
04490 {
04491 return m_pFCO;
04492 }
04493
04494 AttributePtr AttributeImpl::getAttributeI() const
04495 {
04496 return m_spAttribute;
04497 }
04498
04499 const MON::Attribute& AttributeImpl::getAttributeMeta() const
04500 {
04501 return m_meta;
04502 }
04503
04504 AttributeStatus AttributeImpl::getStatus() const
04505 {
04506 long lStatus;
04507 COMCHECK2( m_spAttribute, m_spAttribute->get_Status( &lStatus ) );
04508 return lStatus;
04509 }
04510
04511 Util::Variant AttributeImpl::getValue() const
04512 {
04513 CComVariant objValue;
04514 COMCHECK2( m_spAttribute, m_spAttribute->get_Value( &objValue ) );
04515 if ( objValue.vt == VT_EMPTY || objValue.vt == VT_ERROR )
04516 return Util::Variant();
04517
04518 switch ( m_meta.valueType() ) {
04519 case MON::AT_Boolean :
04520 return objValue.boolVal == VARIANT_TRUE;
04521 case MON::AT_Integer :
04522 return objValue.lVal;
04523 case MON::AT_Real :
04524 return objValue.dblVal;
04525 case MON::AT_String :
04526 case MON::AT_Enumeration :
04527 return Util::Copy( CComBSTR( objValue.bstrVal ) );
04528 }
04529 ASSERTTHROW( Util::Exception( "Invalid control path!" ) );
04530 }
04531
04532 void AttributeImpl::setValue( const Util::Variant& value, bool bTypeTolerant )
04533 {
04534 checkTypes( value, ! bTypeTolerant );
04535 if ( value.isUndefined() ) {
04536 COMCHECK2( m_spAttribute, m_spAttribute->Clear() );
04537 }
04538 else {
04539 switch ( m_meta.valueType() ) {
04540 case MON::AT_Boolean :
04541 COMCHECK2( m_spAttribute, m_spAttribute->put_BoolValue( (bool) value ) );
04542 break;
04543 case MON::AT_Integer :
04544 COMCHECK2( m_spAttribute, m_spAttribute->put_IntValue( (long) value ) );
04545 break;
04546 case MON::AT_Real :
04547 COMCHECK2( m_spAttribute, m_spAttribute->put_FloatValue( (double) value ) );
04548 break;
04549 case MON::AT_String :
04550 case MON::AT_Enumeration :
04551 COMCHECK2( m_spAttribute, m_spAttribute->put_StringValue( Util::Copy( (std::string) value ) ) );
04552 break;
04553 }
04554 }
04555 if ( getProject()->isAutoCommit() )
04556 getProject()->commit();
04557 }
04558
04559 long AttributeImpl::getIntegerValue( bool bTypeTolerant ) const
04560 {
04561 return (long) checkTypes( Util::Variant::VT_Integer, getValue(), ! bTypeTolerant );
04562 }
04563
04564 void AttributeImpl::setIntegerValue( long lValue, bool bTypeTolerant )
04565 {
04566 checkTypes( Util::Variant( lValue ), ! bTypeTolerant );
04567 setValue( Util::Variant( lValue ) );
04568 }
04569
04570 bool AttributeImpl::getBooleanValue( bool bTypeTolerant ) const
04571 {
04572 return (bool) checkTypes( Util::Variant::VT_Boolean, getValue(), ! bTypeTolerant );
04573 }
04574
04575 void AttributeImpl::setBooleanValue( bool bValue, bool bTypeTolerant )
04576 {
04577 checkTypes( Util::Variant( bValue ), ! bTypeTolerant );
04578 setValue( Util::Variant( bValue ) );
04579 }
04580
04581 double AttributeImpl::getRealValue( bool bTypeTolerant ) const
04582 {
04583 return (double) checkTypes( Util::Variant::VT_Double, getValue(), ! bTypeTolerant );
04584 }
04585
04586 void AttributeImpl::setRealValue( double dValue, bool bTypeTolerant )
04587 {
04588 checkTypes( Util::Variant( dValue ), ! bTypeTolerant );
04589 setValue( Util::Variant( dValue ) );
04590 }
04591
04592 std::string AttributeImpl::getStringValue( bool bTypeTolerant ) const
04593 {
04594 return (std::string) checkTypes( Util::Variant::VT_String, getValue(), ! bTypeTolerant );
04595 }
04596
04597 void AttributeImpl::setStringValue( const std::string& strValue, bool bTypeTolerant )
04598 {
04599 checkTypes( Util::Variant( strValue ), ! bTypeTolerant );
04600 setValue( Util::Variant( strValue ) );
04601 }
04602
04603 bool AttributeImpl::isUndefined() const
04604 {
04605 return getValue().isUndefined();
04606 }
04607
04608 void AttributeImpl::clear()
04609 {
04610 setValue( Util::Variant() );
04611 }
04612
04613
04614
04615
04616
04617
04618
04619 AtomImpl::AtomImpl()
04620 : FCOImpl()
04621 {
04622 }
04623
04624 AtomImpl* AtomImpl::attachI( IMgaAtom* spAtom, ProjectImpl* pProject, const MON::Object& meta )
04625 {
04626
04627 if ( ! spAtom )
04628 return NULL;
04629
04630
04631 pProject = _getProject( spAtom, pProject );
04632 ObjectImpl* pObject = find( pProject, spAtom );
04633 if ( pObject )
04634 return dynamic_cast<AtomImpl*>( pObject );
04635
04636
04637 pObject = getEx( spAtom, OT_Atom, meta );
04638 if ( ! pObject )
04639 pObject = new AtomImpl();
04640 pObject->doInitialize( spAtom, pProject, meta );
04641 dynamic_cast<FCOImpl*>( pObject )->doInitialize( pProject );
04642 pObject->initialize();
04643
04644 AtomImpl* ai = dynamic_cast<AtomImpl*>( pObject );
04645 attachIPost( ai);
04646 return ai;
04647 }
04648
04649 Atom AtomImpl::attach( IMgaAtom* spAtom )
04650 {
04651 return attachI( spAtom );
04652 }
04653
04654 Atom AtomImpl::create( const Folder& parent, const MON::Atom& meta )
04655 {
04656 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
04657 return parent->createChildObjectI( meta, MON::OT_Atom );
04658 }
04659
04660 Atom AtomImpl::create( const Folder& parent, const std::string& strAtom )
04661 {
04662 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
04663 MON::Atom meta;
04664 if ( ! strAtom.empty() ) {
04665 meta = parent->getProject()->getProjectMeta().findByName( strAtom );
04666 if ( ! meta )
04667 {
04668 MON::Exception exc( "MON::Atom [ ? ] does not exist in ? of ?!");
04669 exc << strAtom << parent->getProject()->getProjectMeta().infoString() << parent->getProject()->getInfoString();
04670 ASSERTTHROW( exc);
04671 }
04672 }
04673 return create( parent, meta );
04674 }
04675
04676 Atom AtomImpl::create( const Folder& parent, const Atom& baseType, bool bAsInstance )
04677 {
04678 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
04679 return dynamic_cast<AtomImpl*>( parent->createChildFCOI( baseType, bAsInstance, MON::OT_Atom ) );
04680 }
04681
04682 Atom AtomImpl::create( const Model& parent, const MON::Atom& meta, const std::string& strRole )
04683 {
04684 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
04685 return dynamic_cast<AtomImpl*>( parent->createChildFCOI( meta, strRole, MON::OT_Atom ) );
04686 }
04687
04688 Atom AtomImpl::create( const Model& parent, const std::string& strAtom, const std::string& strRole )
04689 {
04690 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
04691 MON::Atom meta;
04692 if ( ! strAtom.empty() ) {
04693 meta = parent->getProject()->getProjectMeta().findByName( strAtom );
04694 if ( ! meta )
04695 {
04696 MON::Exception exc( "MON::Atom [ ? ] does not exist in ? of ?!");
04697 exc << strAtom << parent->getProject()->getProjectMeta().infoString() << parent->getProject()->getInfoString();
04698 ASSERTTHROW( exc);
04699 }
04700 }
04701 return create( parent, meta, strRole );
04702 }
04703
04704 Atom AtomImpl::create( const Model& parent, const Atom& baseType, bool bAsInstance, const std::string& strRole )
04705 {
04706 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
04707 return dynamic_cast<AtomImpl*>( parent->createChildFCOI( baseType, bAsInstance, strRole, MON::OT_Atom ) );
04708 }
04709
04710 Atom AtomImpl::createAs( const Model& parent, const std::string& strRole )
04711 {
04712 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
04713 return dynamic_cast<AtomImpl*>( parent->createChildFCOI( strRole, MON::OT_Atom ) );
04714 }
04715
04716 AtomImpl::~AtomImpl()
04717 {
04718 }
04719
04720
04721
04722
04723 ObjectType AtomImpl::getStereotype() const
04724 {
04725 return OT_Atom;
04726 }
04727
04728 AtomPtr AtomImpl::getAtomI() const
04729 {
04730 CComQIPtr<IMgaAtom> spAtom = getObjectI().p;
04731 return spAtom.p;
04732 }
04733
04734 MON::Atom AtomImpl::getAtomMeta() const
04735 {
04736 return getObjectMeta();
04737 }
04738
04739 std::string AtomImpl::getInfoString( unsigned short usOptions ) const
04740 {
04741 bool bAll = ( usOptions & Util::IO_All ) ? true : false;
04742 bool bLine = bAll || ( usOptions & Util::IO_NewLine );
04743
04744 std::string strInfo = getInfoStringHelper( usOptions, "Atom" );
04745 if ( ! ( usOptions & Util::IO_NewLine ) && ! ( usOptions & Util::IO_All ) )
04746 strInfo += "]";
04747
04748 return strInfo;
04749 }
04750
04751
04752
04753
04754 void AtomImpl::accept( Visitor* pVisitor )
04755 {
04756 pVisitor->visitAtom( Atom( this ) );
04757 }
04758
04759 FCOExRegistryNode AtomImpl::getRegistry() const
04760 {
04761 return FCOImpl::getRegistry();
04762 }
04763
04764
04765
04766
04767
04768
04769
04770 ModelImpl::ModelImpl()
04771 : FCOImpl(), m_bAllChildFCOs( false )
04772 {
04773 }
04774
04775 ModelImpl* ModelImpl::attachI( IMgaModel* spModel, ProjectImpl* pProject, const MON::Object& meta )
04776 {
04777
04778 if ( ! spModel )
04779 return NULL;
04780
04781
04782 pProject = _getProject( spModel, pProject );
04783 ObjectImpl* pObject = find( pProject, spModel );
04784 if ( pObject )
04785 return dynamic_cast<ModelImpl*>( pObject );
04786
04787
04788 pObject = getEx( spModel, OT_Model, meta );
04789 if ( ! pObject )
04790 pObject = new ModelImpl();
04791 pObject->doInitialize( spModel, pProject, meta );
04792 dynamic_cast<FCOImpl*>( pObject )->doInitialize( pProject );
04793 pObject->initialize();
04794
04795 ModelImpl* mi = dynamic_cast<ModelImpl*>( pObject );
04796 attachIPost( mi);
04797 return mi;
04798 }
04799
04800 Model ModelImpl::attach( IMgaModel* spModel )
04801 {
04802 return attachI( spModel );
04803 }
04804
04805 Model ModelImpl::create( const Folder& parent, const MON::Model& meta )
04806 {
04807 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
04808 return parent->createChildObjectI( meta, MON::OT_Model );
04809 }
04810
04811 Model ModelImpl::create( const Folder& parent, const std::string& strModel )
04812 {
04813 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
04814 MON::Model meta;
04815 if ( ! strModel.empty() ) {
04816 meta = parent->getProject()->getProjectMeta().findByName( strModel );
04817 if ( ! meta )
04818 {
04819 MON::Exception exc( "MON::Model [ ? ] does not exist in ? of ?!");
04820 exc << strModel << parent->getProject()->getProjectMeta().infoString() << parent->getProject()->getInfoString();
04821 ASSERTTHROW( exc);
04822 }
04823 }
04824 return create( parent, meta );
04825 }
04826
04827 Model ModelImpl::create( const Folder& parent, const Model& baseType, bool bAsInstance )
04828 {
04829 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
04830 return dynamic_cast<ModelImpl*>( parent->createChildFCOI( baseType, bAsInstance, MON::OT_Model ) );
04831 }
04832
04833 Model ModelImpl::create( const Model& parent, const MON::Model& meta, const std::string& strRole )
04834 {
04835 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
04836 return dynamic_cast<ModelImpl*>( parent->createChildFCOI( meta, strRole, MON::OT_Model ) );
04837 }
04838
04839 Model ModelImpl::create( const Model& parent, const std::string& strModel, const std::string& strRole )
04840 {
04841 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
04842 MON::Model meta;
04843 if ( ! strModel.empty() ) {
04844 meta = parent->getProject()->getProjectMeta().findByName( strModel );
04845 if ( ! meta )
04846 {
04847 MON::Exception exc( "MON::Model [ ? ] does not exist in ? of ?!");
04848 exc << strModel << parent->getProject()->getProjectMeta().infoString() << parent->getProject()->getInfoString();
04849 ASSERTTHROW( exc);
04850 }
04851 }
04852 return create( parent, meta, strRole );
04853 }
04854
04855 Model ModelImpl::create( const Model& parent, const Model& baseType, bool bAsInstance, const std::string& strRole )
04856 {
04857 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
04858 return dynamic_cast<ModelImpl*>( parent->createChildFCOI( baseType, bAsInstance, strRole, MON::OT_Model ) );
04859 }
04860
04861 Model ModelImpl::createAs( const Model& parent, const std::string& strRole )
04862 {
04863 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
04864 return dynamic_cast<ModelImpl*>( parent->createChildFCOI( strRole, MON::OT_Model ) );
04865 }
04866
04867 ModelImpl::~ModelImpl()
04868 {
04869 if ( ! ObjectImpl::m_pProject->isDestructionActive() && ! isDeleted() ) {
04870 for ( ManyFCOLink::iterator it1 = m_childFCOs.begin() ; it1 != m_childFCOs.end() ; it1++ )
04871 for ( FCOSet::iterator it2 = it1->second.second.begin() ; it2 != it1->second.second.end() ; it2++ )
04872 (*it2)->onReleasedAsModelChild( this, true );
04873 }
04874 m_childFCOs.clear();
04875 }
04876
04877 bool ModelImpl::setDeleted()
04878 {
04879 if ( FCOImpl::setDeleted() )
04880 return true;
04881 if ( ! _isAddOn() ) {
04882 for ( ManyFCOLink::iterator it1 = m_childFCOs.begin() ; it1 != m_childFCOs.end() ; it1++ )
04883 for ( FCOSet::iterator it2 = it1->second.second.begin() ; it2 != it1->second.second.end() ; it2++ )
04884 (*it2)->onReleasedAsModelChild( this, true );
04885 }
04886 return false;
04887 }
04888
04889
04890
04891
04892 ObjectType ModelImpl::getStereotype() const
04893 {
04894 return OT_Model;
04895 }
04896
04897 ModelPtr ModelImpl::getModelI() const
04898 {
04899 CComQIPtr<IMgaModel> spModel = getObjectI().p;
04900 return spModel.p;
04901 }
04902
04903 MON::Model ModelImpl::getModelMeta() const
04904 {
04905 return getObjectMeta();
04906 }
04907
04908 std::string ModelImpl::getInfoString( unsigned short usOptions ) const
04909 {
04910 bool bAll = ( usOptions & Util::IO_All ) ? true : false;
04911 bool bLine = bAll || ( usOptions & Util::IO_NewLine );
04912
04913 std::string strInfo = getInfoStringHelper( usOptions, "Model" );
04914 if ( ! ( usOptions & Util::IO_NewLine ) && ! ( usOptions & Util::IO_All ) )
04915 strInfo += "]";
04916
04917 return strInfo;
04918 }
04919
04920
04921
04922
04923 bool ModelImpl::isChildFCOsRetrieved( const MON::FCO& meta )
04924 {
04925 ManyFCOLink::iterator it = m_childFCOs.find( meta );
04926 if ( it != m_childFCOs.end() ) {
04927 if ( it->second.first )
04928 return true;
04929 it->second.first = true;
04930 return false;
04931 }
04932 m_childFCOs[ meta ] = FCOSetPair( true, FCOSet() );
04933 return false;
04934 }
04935
04936 void ModelImpl::getChildFCOs( std::set<FCOPtr>& setSPFCOs )
04937 {
04938 Util::ComPtr<IMgaFCOs> spFCOs;
04939 COMCHECK2( getModelI(), getModelI()->get_ChildFCOs( spFCOs.Addr() ) );
04940 MGACOLL_ITERATE( IMgaFCO, spFCOs.p ) {
04941 setSPFCOs.insert( MGACOLL_ITER );
04942 } MGACOLL_ITERATE_END;
04943 }
04944
04945 void ModelImpl::getChildFCOs( const MON::FCO& meta, std::set<FCOPtr>& setSPFCOs, bool bErase )
04946 {
04947 std::set<FCOPtr>::iterator it = setSPFCOs.begin();
04948 while ( it != setSPFCOs.end() ) {
04949 std::set<FCOPtr>::iterator itSaved = it;
04950 it++;
04951 if ( _getMetaRef( *itSaved ) == meta.ref() ) {
04952 FCOImpl* pFCO = FCOImpl::attachI( *itSaved, ObjectImpl::m_pProject, meta );
04953 if ( m_childFCOs[ meta ].second.find( pFCO ) == m_childFCOs[ meta ].second.end() ) {
04954 m_childFCOs[ meta ].second.insert( pFCO );
04955 pFCO->onRetrievedAsModelChild( this, false );
04956 }
04957 if ( bErase )
04958 setSPFCOs.erase( itSaved );
04959 }
04960 }
04961 }
04962
04963 FCOSet ModelImpl::getChildFCOsI( const MON::FCO& meta )
04964 {
04965
04966 if ( meta ) {
04967 if ( ! isChildFCOsRetrieved( meta ) ) {
04968 std::set<FCOPtr> setSPFCOs;
04969 getChildFCOs( setSPFCOs );
04970 getChildFCOs( meta, setSPFCOs, false );
04971 }
04972 return m_childFCOs[ meta ].second;
04973 }
04974
04975
04976 if ( ! m_bAllChildFCOs ) {
04977 m_bAllChildFCOs = true;
04978 std::set<FCOPtr> setSPFCOs;
04979 getChildFCOs( setSPFCOs );
04980 std::set<MON::FCO> setFCOs = getModelMeta().childFCOs();
04981 for ( std::set<MON::FCO>::iterator it = setFCOs.begin() ; it != setFCOs.end() ; it++ ) {
04982 if ( ! isChildFCOsRetrieved( *it ) )
04983 getChildFCOs( *it, setSPFCOs, true );
04984 }
04985 }
04986
04987
04988 FCOSet setFCOs;
04989 for ( ManyFCOLink::iterator it = m_childFCOs.begin() ; it != m_childFCOs.end() ; it++ )
04990 setFCOs.insert( it->second.second.begin(), it->second.second.end() );
04991 return setFCOs;
04992 }
04993
04994 FCOImpl* ModelImpl::createChildFCOI( const std::string& strRole, MON::ObjectType eType )
04995 {
04996 MON::Containment role;
04997 std::set<MON::Containment> metas = getModelMeta().childContainments();
04998 if ( strRole.empty() ) {
04999 for ( std::set<MON::Containment>::iterator it = metas.begin() ; it != metas.end() ; it++ ) {
05000 if ( it->child().type() == eType ) {
05001 if ( role )
05002 {
05003 MON::Exception exc( "strRole cannot be an empty string because ? can contain more than one MON::Containment with child ?!");
05004 exc << getObjectMeta().infoString() << toString( eType );
05005 ASSERTTHROW( exc);
05006 }
05007 role = *it;
05008 }
05009 }
05010 if ( ! role )
05011 {
05012 MON::Exception exc( "? does not have ? as child!");
05013 exc << getObjectMeta().infoString() << toString( eType );
05014 ASSERTTHROW( exc);
05015 }
05016 }
05017 else {
05018 for ( std::set<MON::Containment>::iterator it = metas.begin() ; it != metas.end() ; it++ ) {
05019 if ( ( it->name() == strRole || it->name() == ObjectImpl::m_pProject->prefixWNmsp( strRole)) && it->child().type() == eType ) {
05020 role = *it;
05021 break;
05022 }
05023 }
05024 if ( ! role )
05025 {
05026 MON::Exception exc( "? does not have ? as child with containment role [ ? ]!");
05027 exc << getObjectMeta().infoString() << toString( eType ) << strRole;
05028 ASSERTTHROW( exc);
05029 }
05030 }
05031
05032 FCOPtr spFCO;
05033 COMCHECK2( getModelI(), getModelI()->CreateChildObject( role.getContainmentI(), spFCO.Addr() ) );
05034 FCOImpl* pFCO = FCOImpl::attachI( spFCO, (ProjectImpl*) getProject().getCounted(), role.child() );
05035 if ( getProject()->isAutoCommit() )
05036 getProject()->commit();
05037 if ( ! _isAddOn() )
05038 pFCO->eventPerformedI( Event( MON::OET_ObjectCreated, pFCO ) );
05039 return pFCO;
05040 }
05041
05042 FCOImpl* ModelImpl::createChildFCOI( const MON::FCO& meta, const std::string& strRole, MON::ObjectType eType )
05043 {
05044 if ( ! meta )
05045 return createChildFCOI( strRole, eType );
05046
05047 THROW_METAPROJECT_BELONG( meta );
05048 MON::Containment role;
05049 std::set<MON::Containment> metas = getModelMeta().childContainments();
05050 for ( std::set<MON::Containment>::iterator it = metas.begin() ; it != metas.end() ; it++ ) {
05051 if ( it->child() == meta ) {
05052 if ( strRole.empty() ) {
05053 if ( role )
05054 {
05055 MON::Exception exc( "strRole cannot be an empty string because ? can contain ? as child with more than one MON::Containment!");
05056 exc << getObjectMeta().infoString() << meta.infoString();
05057 ASSERTTHROW( exc);
05058 }
05059 role = *it;
05060 }
05061 else {
05062 role = *it;
05063 break;
05064 }
05065 }
05066 }
05067
05068 if ( ! role )
05069 {
05070 MON::Exception exc( "? does not have ? as child!");
05071 exc << getObjectMeta().infoString() << meta.infoString();
05072 ASSERTTHROW( exc);
05073 }
05074
05075 FCOPtr spFCO;
05076 COMCHECK2( getModelI(), getModelI()->CreateChildObject( role.getContainmentI(), spFCO.Addr() ) );
05077 FCOImpl* pFCO = FCOImpl::attachI( spFCO, (ProjectImpl*) getProject().getCounted(), meta );
05078 if ( getProject()->isAutoCommit() )
05079 getProject()->commit();
05080 if ( ! _isAddOn() )
05081 pFCO->eventPerformedI( Event( MON::OET_ObjectCreated, pFCO ) );
05082 return pFCO;
05083 }
05084
05085 FCOImpl* ModelImpl::createChildFCOI( const BON::FCO& fco, bool bAsInstance, const std::string& strRole, MON::ObjectType eType )
05086 {
05087 THROW_CANNOT_BE_NULL( fco, "BON::" + toString( eType, false ) );
05088 THROW_PROJECT_BELONG( fco );
05089
05090 MON::Containment role;
05091 std::set<MON::Containment> metas = getModelMeta().childContainments();
05092 for ( std::set<MON::Containment>::iterator it = metas.begin() ; it != metas.end() ; it++ ) {
05093 if ( it->child() == fco->getFCOMeta() ) {
05094 if ( strRole.empty() ) {
05095 if ( role )
05096 {
05097 MON::Exception exc( "strRole cannot be an empty string because ? can contain ? as child with more than one MON::Containment!");
05098 exc << getObjectMeta().infoString() << fco->getObjectMeta().infoString();
05099 ASSERTTHROW( exc);
05100 }
05101 role = *it;
05102 }
05103 else {
05104 role = *it;
05105 break;
05106 }
05107 }
05108 }
05109
05110 if ( ! role )
05111 {
05112 MON::Exception exc( "? does not have ? as child!");
05113 exc << getObjectMeta().infoString() << fco->getObjectMeta().infoString();
05114 ASSERTTHROW( exc);
05115 }
05116
05117 FCOPtr spFCO;
05118 COMCHECK2( getModelI(), getModelI()->DeriveChildObject( fco->getFCOI(), role.getContainmentI(), ( bAsInstance ) ? VARIANT_TRUE : VARIANT_FALSE, spFCO.Addr() ) );
05119 FCOImpl* pFCO = FCOImpl::attachI( spFCO, (ProjectImpl*) getProject().getCounted(), fco->getFCOMeta() );
05120 if ( getProject()->isAutoCommit() )
05121 getProject()->commit();
05122 if ( ! _isAddOn() ) {
05123 pFCO->eventPerformedI( Event( MON::OET_ObjectCreated, pFCO ) );
05124 fco->eventPerformedI( Event( MON::OET_DescendantCreated, fco ) );
05125 }
05126 return pFCO;
05127 }
05128
05129
05130
05131
05132 bool ModelImpl::onRetrievedAsFCOParent( FCOImpl* pFCO, bool bCheckAll )
05133 {
05134 ManyFCOLink::iterator it = m_childFCOs.find( pFCO->getFCOMeta() );
05135 if ( it == m_childFCOs.end() ) {
05136 if ( bCheckAll )
05137 return false;
05138 m_childFCOs[ pFCO->getFCOMeta() ] = FCOSetPair( false, FCOSet() );
05139 }
05140 if ( ! bCheckAll || bCheckAll && m_childFCOs[ pFCO->getFCOMeta() ].first ) {
05141 m_childFCOs[ pFCO->getFCOMeta() ].second.insert( pFCO );
05142 return true;
05143 }
05144 return false;
05145 }
05146
05147 void ModelImpl::onReleasedAsFCOParent( FCOImpl* pFCO, bool bOnlyFreeMemory )
05148 {
05149 ManyFCOLink::iterator it = m_childFCOs.find( pFCO->getFCOMeta() );
05150 if ( it != m_childFCOs.end() ) {
05151 m_childFCOs[ pFCO->getFCOMeta() ].second.erase( pFCO );
05152 if ( bOnlyFreeMemory && m_childFCOs[ pFCO->getFCOMeta() ].first ) {
05153 m_childFCOs[ pFCO->getFCOMeta() ].first = false;
05154 m_bAllChildFCOs = false;
05155 }
05156 }
05157 }
05158
05159 void ModelImpl::eventPerformedI( const Event& event )
05160 {
05161 FCOImpl::eventPerformedI( event );
05162 switch ( event.getType() ) {
05163 case MON::OET_ChildAdded :
05164 onChildAdded( NULL );
05165 break;
05166 case MON::OET_ChildLost :
05167 onChildRemoved( NULL );
05168 break;
05169 case MON::OET_DescendantCreated :
05170 onObjectDerived( NULL );
05171 break;
05172 }
05173 }
05174
05175 void ModelImpl::onChildAdded( FCOImpl* pChild )
05176 {
05177 if ( pChild ) {
05178 if ( onRetrievedAsFCOParent( pChild, false ) )
05179 pChild->onRetrievedAsModelChild( this, false );
05180 }
05181 }
05182
05183 void ModelImpl::onChildRemoved( FCOImpl* pChild )
05184 {
05185 if ( pChild ) {
05186 onReleasedAsFCOParent( pChild, false );
05187 pChild->onReleasedAsModelChild( this, false );
05188 }
05189 }
05190
05191 void ModelImpl::onObjectDerived( FCOImpl* pFCO )
05192 {
05193 if ( ! _isAddOn() ) {
05194 for ( ManyFCOLink::iterator it = m_childFCOs.begin() ; it != m_childFCOs.end() ; it++ )
05195 for ( FCOSet::iterator it2 = it->second.second.begin() ; it2 != it->second.second.end() ; it2++ )
05196 (*it2)->eventPerformedI( Event( MON::OET_DescendantCreated, *it2 ) );
05197 }
05198 }
05199
05200
05201
05202
05203 std::set<FCO> ModelImpl::getChildFCOs( const MON::FCO& meta, const MON::Aspect& aspect )
05204 {
05205 if ( aspect )
05206 THROW_METAPROJECT_BELONG( aspect );
05207
05208 if ( meta ) {
05209 THROW_METAPROJECT_BELONG( meta );
05210 if ( ! getModelMeta().isFCOChild( meta ) )
05211 {
05212 MON::Exception exc( "? cannot be child of ?!");
05213 exc << meta.infoString() << getObjectMeta().infoString();
05214 ASSERTTHROW( exc);
05215 }
05216 }
05217 std::set<FCO> setResult;
05218 setCopy<FCO,FCOImpl>( getChildFCOsI( meta ), setResult );
05219 return filterByAspect<FCO>( setResult, aspect );
05220 }
05221
05222 std::set<FCO> ModelImpl::getChildFCOs( const std::string& strFCO, const MON::Aspect& aspect )
05223 {
05224 MON::FCO meta;
05225 if ( ! strFCO.empty() ) {
05226 meta = MON::FCO( getProject()->getProjectMeta().findByName( strFCO ) );
05227 THROW_METAPROJECT_DOES_NOT_HAVE( meta, FCO, strFCO );
05228 }
05229 return getChildFCOs( meta, aspect );
05230 }
05231
05232 std::set<FCO> ModelImpl::getChildFCOsAs( const std::string& strRole, const MON::Aspect& aspect )
05233 {
05234 if ( strRole.empty() )
05235 return getChildFCOs( MON::FCO(), aspect );
05236
05237 if ( aspect )
05238 THROW_METAPROJECT_BELONG( aspect );
05239
05240 MON::Containment role;
05241 std::set<MON::Containment> roles = getModelMeta().childContainments();
05242 for ( std::set<MON::Containment>::iterator it = roles.begin() ; it != roles.end() ; it++ )
05243 if ( strRole == it->name() || ObjectImpl::m_pProject->prefixWNmsp( strRole) == it->name()) {
05244 role = *it;
05245 break;
05246 }
05247
05248 if ( ! role )
05249 {
05250 MON::Exception exc( "? cannot be has containment role ?!");
05251 exc << getObjectMeta().infoString() << strRole;
05252 ASSERTTHROW( exc);
05253 }
05254
05255 std::set<FCO> setResult;
05256 setCopy<FCO,FCOImpl>( getChildFCOsI( role.child() ), setResult );
05257
05258 std::set<FCO>::iterator it2 = setResult.begin();
05259 while ( it2 != setResult.end() ) {
05260 std::set<FCO>::iterator itSaved = it2;
05261 it2++;
05262 if ( (*itSaved)->getRole() != role )
05263 setResult.erase( itSaved );
05264 }
05265
05266 return filterByAspect<FCO>( setResult, aspect );
05267 }
05268
05269 std::set<Atom> ModelImpl::getChildAtoms( const MON::Aspect& aspect )
05270 {
05271 if ( aspect )
05272 THROW_METAPROJECT_BELONG( aspect );
05273
05274 std::set<Atom> setResult;
05275 std::set<MON::Atom> metas = getModelMeta().childAtoms();
05276 for ( std::set<MON::Atom>::iterator it = metas.begin() ; it != metas.end() ; ++it )
05277 setCastCopy<Atom,FCOImpl,AtomImpl>( getChildFCOsI( *it ), setResult );
05278 return filterByAspect<Atom>( setResult, aspect );
05279 }
05280
05281 std::set<Model> ModelImpl::getChildModels( const MON::Aspect& aspect )
05282 {
05283 if ( aspect )
05284 THROW_METAPROJECT_BELONG( aspect );
05285
05286 std::set<Model> setResult;
05287 std::set<MON::Model> metas = getModelMeta().childModels();
05288 for ( std::set<MON::Model>::iterator it = metas.begin() ; it != metas.end() ; ++it )
05289 setCastCopy<Model,FCOImpl,ModelImpl>( getChildFCOsI( *it ), setResult );
05290 return filterByAspect<Model>( setResult, aspect );
05291 }
05292
05293 std::set<Set> ModelImpl::getChildSets( const MON::Aspect& aspect )
05294 {
05295 if ( aspect )
05296 THROW_METAPROJECT_BELONG( aspect );
05297
05298 std::set<Set> setResult;
05299 std::set<MON::Set> metas = getModelMeta().childSets();
05300 for ( std::set<MON::Set>::iterator it = metas.begin() ; it != metas.end() ; ++it )
05301 setCastCopy<Set,FCOImpl,SetImpl>( getChildFCOsI( *it ), setResult );
05302 return filterByAspect<Set>( setResult, aspect );
05303 }
05304
05305 std::set<Reference> ModelImpl::getChildReferences( const MON::Aspect& aspect )
05306 {
05307 if ( aspect )
05308 THROW_METAPROJECT_BELONG( aspect );
05309
05310 std::set<Reference> setResult;
05311 std::set<MON::Reference> metas = getModelMeta().childReferences();
05312 for ( std::set<MON::Reference>::iterator it = metas.begin() ; it != metas.end() ; ++it )
05313 setCastCopy<Reference,FCOImpl,ReferenceImpl>( getChildFCOsI( *it ), setResult );
05314 return filterByAspect<Reference>( setResult, aspect );
05315 }
05316
05317 std::set<Connection> ModelImpl::getChildConnections( const MON::Aspect& aspect )
05318 {
05319 if ( aspect )
05320 THROW_METAPROJECT_BELONG( aspect );
05321
05322 std::set<Connection> setResult;
05323 std::set<MON::Connection> metas = getModelMeta().childConnections();
05324 for ( std::set<MON::Connection>::iterator it = metas.begin() ; it != metas.end() ; ++it )
05325 setCastCopy<Connection,FCOImpl,ConnectionImpl>( getChildFCOsI( *it ), setResult );
05326 return filterByAspect<Connection>( setResult, aspect );
05327 }
05328
05329 FCO ModelImpl::findByPath( const std::string& strPath, const std::string& strDelimiter, bool bReverseOrder )
05330 {
05331 std::string strPath2;
05332 std::string strName;
05333 size_t iPos = ( bReverseOrder ) ? strPath.rfind( strDelimiter ) : strPath.find( strDelimiter );
05334 if ( iPos == std::string::npos ) {
05335 strName = strPath;
05336 strPath2 = "";
05337 }
05338 else {
05339 if ( bReverseOrder && iPos + strDelimiter.length() == strPath.length() )
05340 strPath2 = strPath.substr( 0, iPos );
05341 if ( ! bReverseOrder && iPos == 0 )
05342 strPath2 = strPath.substr( iPos + strDelimiter.length() );
05343 iPos = ( bReverseOrder ) ? strPath2.rfind( strDelimiter ) : strPath2.find( strDelimiter );
05344 if ( iPos == std::string::npos ) {
05345 strName = strPath2;
05346 strPath2 = "";
05347 }
05348 else {
05349 strName = ( bReverseOrder ) ? strPath2.substr( iPos ) : strPath2.substr( 0, iPos );
05350 strPath2 = ( bReverseOrder ) ? strPath2.substr( 0, iPos ) : strPath2.substr( iPos );
05351 }
05352 }
05353
05354 std::set<FCO> objects = getChildFCOs();
05355 for ( std::set<FCO>::iterator it = objects.begin() ; it != objects.end() ; it++ )
05356 if ( strName == (*it)->getName() ) {
05357 if ( strPath2.empty() )
05358 return *it;
05359 else {
05360 if ( (*it)->getStereotype() == OT_Model ) {
05361 FCO o = Model( *it )->findByPath( strPath2, strDelimiter, bReverseOrder );
05362 if ( o )
05363 return o;
05364 }
05365 }
05366 }
05367 return NULL;
05368 }
05369
05370 std::set<FCO> ModelImpl::findByKind( const MON::Object& meta )
05371 {
05372 if ( ! meta )
05373 ASSERTTHROW( Exception( "MON::Object cannot be null!" ) );
05374 if ( meta.project() != this->getObjectMeta().project() )
05375 {
05376 MON::Exception exc( "? does not belong to ? of ?!");
05377 exc << meta.infoString() << this->getObjectMeta().project().infoString() << getInfoString().c_str();
05378 ASSERTTHROW( exc);
05379 }
05380 if ( meta.type() < MON::OT_Model || meta.type() > MON::OT_Set )
05381 {
05382 Exception exc( "Type of ? can be only MON::FCO!");
05383 exc << meta.infoString();
05384 ASSERTTHROW( exc );
05385 }
05386
05387 return findByKindHlp( MON::FCO( meta));
05388 }
05389
05390 std::set<FCO> ModelImpl::findByKind( const std::string& strKind )
05391 {
05392 MON::Object meta = this->getObjectMeta().project().findByName( strKind );
05393 if ( ! meta )
05394 {
05395 MON::Exception exc( "MON::FCO [ ? ] does not exist in ? of ?!");
05396 exc << strKind.c_str() << strKind.c_str() << this->getObjectMeta().project().infoString().c_str() << getInfoString().c_str();
05397 ASSERTTHROW( exc );
05398 }
05399 if ( meta.type() < MON::OT_Model || meta.type() > MON::OT_Set )
05400 {
05401 Exception exc( "? is not MON::FCO!");
05402 exc << meta.infoString().c_str();
05403 ASSERTTHROW( exc );
05404 }
05405
05406 return findByKindHlp( MON::FCO( meta));
05407 }
05408
05409 std::set<FCO> ModelImpl::findByKindHlp( const MON::FCO& meta )
05410 {
05411 std::set<FCO> bigResult = getChildFCOs( meta);
05412 std::set<Model> children = getChildModels();
05413 for( std::set<Model>::iterator it = children.begin(); it != children.end(); ++it)
05414 {
05415 std::set<FCO> res = (*it)->findByKindHlp( meta);
05416 bigResult.insert( res.begin(), res.end());
05417 }
05418
05419 return bigResult;
05420 }
05421
05422
05423
05424
05425 void ModelImpl::accept( Visitor* pVisitor )
05426 {
05427 FCOSet children = getChildFCOsI();
05428 for ( FCOSet::iterator it = children.begin() ; it != children.end() ; it++ )
05429 (*it)->accept( pVisitor );
05430 pVisitor->visitModel( Model( this ) );
05431 }
05432
05433 ModelRegistryNode ModelImpl::getRegistry() const
05434 {
05435 return FCOImpl::getRegistry();
05436 }
05437
05438
05439
05440
05441
05442
05443
05444 SetImpl::SetImpl()
05445 : FCOImpl(), m_bAllMemberFCOs( false )
05446 {
05447 }
05448
05449 SetImpl* SetImpl::attachI( IMgaSet* spSet, ProjectImpl* pProject, const MON::Object& meta )
05450 {
05451
05452 if ( ! spSet )
05453 return NULL;
05454
05455
05456 pProject = _getProject( spSet, pProject );
05457 ObjectImpl* pObject = find( pProject, spSet );
05458 if ( pObject )
05459 return dynamic_cast<SetImpl*>( pObject );
05460
05461
05462 pObject = getEx( spSet, OT_Set, meta );
05463 if ( ! pObject )
05464 pObject = new SetImpl();
05465 pObject->doInitialize( spSet, pProject, meta );
05466 dynamic_cast<FCOImpl*>( pObject )->doInitialize( pProject );
05467 pObject->initialize();
05468
05469 SetImpl* si = dynamic_cast<SetImpl*>( pObject );
05470 attachIPost( si);
05471 return si;
05472 }
05473
05474 Set SetImpl::attach( IMgaSet* spSet )
05475 {
05476 return attachI( spSet );
05477 }
05478
05479 Set SetImpl::create( const Folder& parent, const MON::Set& meta )
05480 {
05481 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
05482 return parent->createChildObjectI( meta, MON::OT_Set );
05483 }
05484
05485 Set SetImpl::create( const Folder& parent, const std::string& strSet )
05486 {
05487 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
05488 MON::Set meta;
05489 if ( ! strSet.empty() ) {
05490 meta = parent->getProject()->getProjectMeta().findByName( strSet );
05491 if ( ! meta )
05492 {
05493 MON::Exception exc( "MON::Set [ ? ] does not exist in ? of ?!");
05494 exc << strSet << parent->getProject()->getProjectMeta().infoString() << parent->getProject()->getInfoString();
05495 ASSERTTHROW( exc);
05496 }
05497 }
05498 return create( parent, meta );
05499 }
05500
05501 Set SetImpl::create( const Folder& parent, const Set& baseType, bool bAsInstance )
05502 {
05503 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
05504 return dynamic_cast<SetImpl*>( parent->createChildFCOI( baseType, bAsInstance, MON::OT_Set ) );
05505 }
05506
05507 Set SetImpl::create( const Model& parent, const MON::Set& meta, const std::string& strRole )
05508 {
05509 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
05510 return dynamic_cast<SetImpl*>( parent->createChildFCOI( meta, strRole, MON::OT_Set ) );
05511 }
05512
05513 Set SetImpl::create( const Model& parent, const std::string& strSet, const std::string& strRole )
05514 {
05515 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
05516 MON::Set meta;
05517 if ( ! strSet.empty() ) {
05518 meta = parent->getProject()->getProjectMeta().findByName( strSet );
05519 if ( ! meta )
05520 {
05521 MON::Exception exc( "MON::Set [ ? ] does not exist in ? of ?!");
05522 exc << strSet << parent->getProject()->getProjectMeta().infoString() << parent->getProject()->getInfoString();
05523 ASSERTTHROW( exc);
05524 }
05525 }
05526 return create( parent, meta, strRole );
05527 }
05528
05529 Set SetImpl::create( const Model& parent, const Set& baseType, bool bAsInstance, const std::string& strRole )
05530 {
05531 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
05532 return dynamic_cast<SetImpl*>( parent->createChildFCOI( baseType, bAsInstance, strRole, MON::OT_Set ) );
05533 }
05534
05535 Set SetImpl::createAs( const Model& parent, const std::string& strRole )
05536 {
05537 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
05538 return dynamic_cast<SetImpl*>( parent->createChildFCOI( strRole, MON::OT_Set ) );
05539 }
05540
05541 SetImpl::~SetImpl()
05542 {
05543 if ( ! ObjectImpl::m_pProject->isDestructionActive() && ! isDeleted() ) {
05544 for ( ManyFCOLink::iterator it1 = m_memberFCOs.begin() ; it1 != m_memberFCOs.end() ; it1++ )
05545 for ( FCOSet::iterator it2 = it1->second.second.begin() ; it2 != it1->second.second.end() ; it2++ )
05546 (*it2)->onReleasedAsMember( this, true );
05547 }
05548
05549 m_memberFCOs.clear();
05550 }
05551
05552 bool SetImpl::setDeleted()
05553 {
05554 if ( FCOImpl::setDeleted() )
05555 return true;
05556
05557 for ( ManyFCOLink::iterator it1 = m_memberFCOs.begin() ; it1 != m_memberFCOs.end() ; it1++ )
05558 for ( FCOSet::iterator it2 = it1->second.second.begin() ; it2 != it1->second.second.end() ; it2++ )
05559 (*it2)->onReleasedAsMember( this, false);
05560 return false;
05561 }
05562
05563
05564
05565
05566 ObjectType SetImpl::getStereotype() const
05567 {
05568 return OT_Set;
05569 }
05570
05571 SetPtr SetImpl::getSetI() const
05572 {
05573 CComQIPtr<IMgaSet> spSet = getObjectI().p;
05574 return spSet.p;
05575 }
05576
05577 MON::Set SetImpl::getSetMeta() const
05578 {
05579 return getObjectMeta();
05580 }
05581
05582 std::string SetImpl::getInfoString( unsigned short usOptions ) const
05583 {
05584 bool bAll = ( usOptions & Util::IO_All ) ? true : false;
05585 bool bLine = bAll || ( usOptions & Util::IO_NewLine );
05586
05587 std::string strInfo = getInfoStringHelper( usOptions, "Set" );
05588 if ( ! ( usOptions & Util::IO_NewLine ) && ! ( usOptions & Util::IO_All ) )
05589 strInfo += "]";
05590
05591 return strInfo;
05592 }
05593
05594
05595
05596
05597 bool SetImpl::isMemberFCOsRetrieved( const MON::FCO& meta )
05598 {
05599 ManyFCOLink::iterator it = m_memberFCOs.find( meta );
05600 if ( it != m_memberFCOs.end() ) {
05601 if ( it->second.first )
05602 return true;
05603 it->second.first = true;
05604 return false;
05605 }
05606 m_memberFCOs[ meta ] = FCOSetPair( true, FCOSet() );
05607 return false;
05608 }
05609
05610 void SetImpl::getMemberFCOs( std::set<FCOPtr>& setSPFCOs )
05611 {
05612 Util::ComPtr<IMgaFCOs> spFCOs;
05613 COMCHECK2( getSetI(), getSetI()->get_Members( spFCOs.Addr() ) );
05614 MGACOLL_ITERATE( IMgaFCO, spFCOs.p ) {
05615 setSPFCOs.insert( MGACOLL_ITER );
05616 } MGACOLL_ITERATE_END;
05617 }
05618
05619 void SetImpl::getMemberFCOs( const MON::FCO& meta, std::set<FCOPtr>& setSPFCOs, bool bErase )
05620 {
05621 std::set<FCOPtr>::iterator it = setSPFCOs.begin();
05622 while ( it != setSPFCOs.end() ) {
05623 std::set<FCOPtr>::iterator itSaved = it;
05624 it++;
05625 if ( _getMetaRef( *itSaved ) == meta.ref() ) {
05626 FCOImpl* pFCO = FCOImpl::attachI( *itSaved, ObjectImpl::m_pProject, meta );
05627 if ( m_memberFCOs[ meta ].second.find( pFCO ) == m_memberFCOs[ meta ].second.end() ) {
05628 m_memberFCOs[ meta ].second.insert( pFCO );
05629 pFCO->onRetrievedAsMember( this, false );
05630 }
05631 if ( bErase )
05632 setSPFCOs.erase( itSaved );
05633 }
05634 }
05635 }
05636
05637 FCOSet SetImpl::getMemberFCOsI( const MON::FCO& meta )
05638 {
05639
05640 if ( meta ) {
05641 if ( ! isMemberFCOsRetrieved( meta ) ) {
05642 std::set<FCOPtr> setSPFCOs;
05643 getMemberFCOs( setSPFCOs );
05644 getMemberFCOs( meta, setSPFCOs, false );
05645 }
05646 return m_memberFCOs[ meta ].second;
05647 }
05648
05649
05650 if ( ! m_bAllMemberFCOs ) {
05651 m_bAllMemberFCOs = true;
05652 std::set<FCOPtr> setSPFCOs;
05653 getMemberFCOs( setSPFCOs );
05654 std::set<MON::Containment> setMembers = getSetMeta().memberRoles();
05655 for ( std::set<MON::Containment>::iterator it = setMembers.begin() ; it != setMembers.end() ; it++ ) {
05656 if ( ! isMemberFCOsRetrieved( it->child() ) )
05657 getMemberFCOs( it->child(), setSPFCOs, true );
05658 }
05659 }
05660
05661
05662 FCOSet setFCOs;
05663 for ( ManyFCOLink::iterator it = m_memberFCOs.begin() ; it != m_memberFCOs.end() ; it++ )
05664 setFCOs.insert( it->second.second.begin(), it->second.second.end() );
05665 return setFCOs;
05666 }
05667
05668 void SetImpl::addMemberI( const BON::FCO& fco )
05669 {
05670 FCOImpl* pMember = dynamic_cast<FCOImpl*>( fco.getCounted() );
05671 COMCHECK2( getSetI(), getSetI()->AddMember( pMember->getFCOI() ) );
05672 if ( getProject()->isAutoCommit() )
05673 getProject()->commit();
05674 if ( ! _isAddOn() )
05675 pMember->eventPerformedI( Event( MON::OET_ObjectIncluded, this ) );
05676 }
05677
05678 void SetImpl::removeMemberI( const BON::FCO& fco )
05679 {
05680 FCOImpl* pMember = dynamic_cast<FCOImpl*>( fco.getCounted() );
05681 COMCHECK2( getSetI(), getSetI()->RemoveMember( pMember->getFCOI() ) );
05682 if ( getProject()->isAutoCommit() )
05683 getProject()->commit();
05684 if ( ! _isAddOn() )
05685 pMember->eventPerformedI( Event( MON::OET_ObjectExcluded, this ) );
05686 }
05687
05688
05689
05690
05691 bool SetImpl::onRetrievedAsSet( FCOImpl* pFCO, bool bCheckAll )
05692 {
05693 ManyFCOLink::iterator it = m_memberFCOs.find( pFCO->getFCOMeta() );
05694 if ( it == m_memberFCOs.end() ) {
05695 if ( bCheckAll )
05696 return false;
05697 m_memberFCOs[ pFCO->getFCOMeta() ] = FCOSetPair( false, FCOSet() );
05698 }
05699 if ( bCheckAll && ! m_memberFCOs[ pFCO->getFCOMeta() ].first )
05700 return false;
05701 m_memberFCOs[ pFCO->getFCOMeta() ].second.insert( pFCO );
05702 return true;
05703 }
05704
05705 void SetImpl::onReleasedAsSet( FCOImpl* pFCO, bool bOnlyMemoryFree )
05706 {
05707 ManyFCOLink::iterator it = m_memberFCOs.find( pFCO->getFCOMeta() );
05708 if ( it != m_memberFCOs.end() ) {
05709 m_memberFCOs[ pFCO->getFCOMeta() ].second.erase( pFCO );
05710 if ( bOnlyMemoryFree && m_memberFCOs[ pFCO->getFCOMeta() ].first ) {
05711 m_memberFCOs[ pFCO->getFCOMeta() ].first = false;
05712 m_bAllMemberFCOs = false;
05713 }
05714 }
05715 }
05716
05717 void SetImpl::eventPerformedI( const Event& event )
05718 {
05719 FCOImpl::eventPerformedI( event );
05720 switch ( event.getType() ) {
05721 case MON::OET_RelationChanged :
05722 onRelationChanged();
05723 break;
05724 }
05725 }
05726
05727 void SetImpl::onRelationChanged()
05728 {
05729
05730 for ( ManyFCOLink::iterator it1 = m_memberFCOs.begin() ; it1 != m_memberFCOs.end() ; it1++ )
05731 for ( FCOSet::iterator it2 = it1->second.second.begin() ; it2 != it1->second.second.end() ; it2++ )
05732 (*it2)->onReleasedAsMember( this, false );
05733 m_memberFCOs.clear();
05734 m_bAllMemberFCOs = false;
05735
05736 }
05737
05738
05739
05740
05741 std::set<FCO> SetImpl::getMembers( const MON::FCO& meta, const MON::Aspect& aspect )
05742 {
05743 if ( aspect )
05744 THROW_METAPROJECT_BELONG( aspect );
05745
05746 if ( meta ) {
05747 THROW_METAPROJECT_BELONG( meta );
05748 if ( ! getSetMeta().isMember( meta ) )
05749 {
05750 MON::Exception exc( "? cannot be member of ?!");
05751 exc << meta.infoString() << getObjectMeta().infoString();
05752 ASSERTTHROW( exc);
05753 }
05754 }
05755 std::set<FCO> setResult;
05756 setCopy<FCO,FCOImpl>( getMemberFCOsI( meta ), setResult );
05757 return filterByAspect<FCO>( setResult, aspect );
05758 }
05759
05760 std::set<FCO> SetImpl::getMembers( const std::string& strFCO, const MON::Aspect& aspect )
05761 {
05762 MON::FCO meta;
05763 if ( ! strFCO.empty() ) {
05764 meta = MON::FCO( getProject()->getProjectMeta().findByName( strFCO ) );
05765 THROW_METAPROJECT_DOES_NOT_HAVE( meta, FCO, strFCO );
05766 }
05767 return getMembers( meta, aspect );
05768 }
05769
05770 void SetImpl::addMember( const BON::FCO& fco )
05771 {
05772 THROW_CANNOT_BE_NULL( fco, "BON::FCO" );
05773 THROW_PROJECT_BELONG( fco );
05774
05775 MON::Containment role = fco->getRole();
05776 if ( role ) {
05777 if ( ! getSetMeta().isMember( role ) )
05778 {
05779 MON::Exception exc( "? with ? cannot be member of ?!");
05780 exc << fco->getObjectMeta().infoString() << role.infoString() << getObjectMeta().infoString();
05781 ASSERTTHROW( exc);
05782 }
05783 addMemberI( fco );
05784 return;
05785 }
05786
05787 std::set<MON::Containment> roles = getSetMeta().memberRoles();
05788 for ( std::set<MON::Containment>::iterator it = roles.begin() ; it != roles.end() ; it++ )
05789 if ( it->child() == fco->getFCOMeta() ) {
05790 addMemberI( fco );
05791 return;
05792 }
05793 MON::Exception exc( "? cannot be member of ?!");
05794 exc << fco->getObjectMeta().infoString() << getObjectMeta().infoString();
05795 ASSERTTHROW( exc);
05796 }
05797
05798 void SetImpl::removeMember( const BON::FCO& fco )
05799 {
05800 THROW_CANNOT_BE_NULL( fco, "BON::FCO" );
05801 THROW_PROJECT_BELONG( fco );
05802
05803 MON::Containment role = fco->getRole();
05804 if ( role ) {
05805 if ( ! getSetMeta().isMember( role ) )
05806 {
05807 MON::Exception exc( "? with ? cannot be member of ?!");
05808 exc << fco->getObjectMeta().infoString() << role.infoString() << getObjectMeta().infoString();
05809 ASSERTTHROW( exc);
05810 }
05811 removeMemberI( fco );
05812 return;
05813 }
05814
05815 std::set<MON::Containment> roles = getSetMeta().memberRoles();
05816 for ( std::set<MON::Containment>::iterator it = roles.begin() ; it != roles.end() ; it++ )
05817 if ( it->child() == fco->getFCOMeta() ) {
05818 removeMemberI( fco );
05819 return;
05820 }
05821
05822 MON::Exception exc( "? cannot be member of ?!");
05823 exc << fco->getObjectMeta().infoString() << getObjectMeta().infoString();
05824 ASSERTTHROW( exc);
05825 }
05826
05827
05828
05829
05830 void SetImpl::accept( Visitor* pVisitor )
05831 {
05832 pVisitor->visitSet( Set( this ) );
05833 }
05834
05835 FCOExRegistryNode SetImpl::getRegistry() const
05836 {
05837 return FCOImpl::getRegistry();
05838 }
05839
05840
05841
05842
05843
05844
05845
05846 ReferenceImpl::ReferenceImpl()
05847 : FCOImpl(), m_bAllReferredFCOs( false ), m_bAllChildPorts( false )
05848 {
05849 m_referredFCO.first = MON::FCO();
05850 m_referredFCO.second = NULL;
05851 m_pContainer = new ReferencePortContainerImpl( this );
05852 }
05853
05854 ReferenceImpl* ReferenceImpl::attachI( IMgaReference* spReference, ProjectImpl* pProject, const MON::Object& meta )
05855 {
05856
05857 if ( ! spReference )
05858 return NULL;
05859
05860
05861 pProject = _getProject( spReference, pProject );
05862 ObjectImpl* pObject = find( pProject, spReference );
05863 if ( pObject )
05864 return dynamic_cast<ReferenceImpl*>( pObject );
05865
05866
05867 pObject = getEx( spReference, OT_Reference, meta );
05868 if ( ! pObject )
05869 pObject = new ReferenceImpl();
05870 pObject->doInitialize( spReference, pProject, meta );
05871 dynamic_cast<FCOImpl*>( pObject )->doInitialize( pProject );
05872 pObject->initialize();
05873
05874 ReferenceImpl* ri = dynamic_cast<ReferenceImpl*>( pObject );
05875 attachIPost( ri);
05876 return ri;
05877 }
05878
05879 Reference ReferenceImpl::attach( IMgaReference* spReference )
05880 {
05881 return attachI( spReference );
05882 }
05883
05884 Reference ReferenceImpl::create( const Folder& parent, const MON::Reference& meta )
05885 {
05886 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
05887 return parent->createChildObjectI( meta, MON::OT_Reference );
05888 }
05889
05890 Reference ReferenceImpl::create( const Folder& parent, const std::string& strReference )
05891 {
05892 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
05893 MON::Reference meta;
05894 if ( ! strReference.empty() ) {
05895 meta = parent->getProject()->getProjectMeta().findByName( strReference );
05896 if ( ! meta )
05897 {
05898 MON::Exception exc( "MON::Reference [ ? ] does not exist in ? of ?!");
05899 exc << strReference << parent->getProject()->getProjectMeta().infoString() << parent->getProject()->getInfoString();
05900 ASSERTTHROW( exc);
05901 }
05902 }
05903 return create( parent, meta );
05904 }
05905
05906 Reference ReferenceImpl::create( const Folder& parent, const Reference& baseType, bool bAsInstance )
05907 {
05908 THROW_CANNOT_BE_NULL( parent, "BON::Folder" );
05909 return dynamic_cast<ReferenceImpl*>( parent->createChildFCOI( baseType, bAsInstance, MON::OT_Reference ) );
05910 }
05911
05912 Reference ReferenceImpl::create( const Model& parent, const MON::Reference& meta, const std::string& strRole )
05913 {
05914 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
05915 return dynamic_cast<ReferenceImpl*>( parent->createChildFCOI( meta, strRole, MON::OT_Reference ) );
05916 }
05917
05918 Reference ReferenceImpl::create( const Model& parent, const std::string& strReference, const std::string& strRole )
05919 {
05920 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
05921 MON::Reference meta;
05922 if ( ! strReference.empty() ) {
05923 meta = parent->getProject()->getProjectMeta().findByName( strReference );
05924 if ( ! meta )
05925 {
05926 MON::Exception exc( "MON::Reference [ ? ] does not exist in ? of ?!");
05927 exc << strReference << parent->getProject()->getProjectMeta().infoString() << parent->getProject()->getInfoString();
05928 ASSERTTHROW( exc);
05929 }
05930 }
05931 return create( parent, meta, strRole );
05932 }
05933
05934 Reference ReferenceImpl::create( const Model& parent, const Reference& baseType, bool bAsInstance, const std::string& strRole )
05935 {
05936 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
05937 return dynamic_cast<ReferenceImpl*>( parent->createChildFCOI( baseType, bAsInstance, strRole, MON::OT_Reference ) );
05938 }
05939
05940 Reference ReferenceImpl::createAs( const Model& parent, const std::string& strRole )
05941 {
05942 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
05943 return dynamic_cast<ReferenceImpl*>( parent->createChildFCOI( strRole, MON::OT_Reference ) );
05944 }
05945
05946 ReferenceImpl::~ReferenceImpl()
05947 {
05948 if ( ! ObjectImpl::m_pProject->isDestructionActive() && ! isDeleted() ) {
05949 if ( m_referredFCO.second )
05950 m_referredFCO.second->onReleasedAsReferred( this, true );
05951 }
05952
05953 ManyPortLink ports = m_childPorts;
05954 m_childPorts.clear();
05955 for ( ManyPortLink::iterator it = ports.begin() ; it != ports.end() ; it++ )
05956 delete it->second;
05957
05958 delete m_pContainer;
05959
05960 m_referredFCO.first = MON::FCO();
05961 m_referredFCO.second = NULL;
05962 m_pContainer = NULL;
05963 }
05964
05965 bool ReferenceImpl::setDeleted()
05966 {
05967 if ( FCOImpl::setDeleted() )
05968 return true;
05969
05970 if ( m_referredFCO.second )
05971 m_referredFCO.second->onReleasedAsReferred( this, false );
05972
05973 ManyPortLink ports = m_childPorts;
05974 m_childPorts.clear();
05975 for ( ManyPortLink::iterator it = ports.begin() ; it != ports.end() ; it++ )
05976 it->second->setDeleted();
05977
05978 return false;
05979 }
05980
05981
05982
05983
05984 ObjectType ReferenceImpl::getStereotype() const
05985 {
05986 return OT_Reference;
05987 }
05988
05989 ReferencePtr ReferenceImpl::getReferenceI() const
05990 {
05991 CComQIPtr<IMgaReference> spReference = getObjectI().p;
05992 return spReference.p;
05993 }
05994
05995 MON::Reference ReferenceImpl::getReferenceMeta() const
05996 {
05997 return getObjectMeta();
05998 }
05999
06000 std::string ReferenceImpl::getInfoString( unsigned short usOptions ) const
06001 {
06002 bool bAll = ( usOptions & Util::IO_All ) ? true : false;
06003 bool bIdent = bAll || ( usOptions & Util::IO_Identifiers );
06004 bool bLine = bAll || ( usOptions & Util::IO_NewLine );
06005 std::string strDelim = ( bLine ) ? "\n" : ", ";
06006
06007 std::string strInfo = getInfoStringHelper( usOptions, "Reference" );
06008 if ( bAll || ( usOptions & Util::IO_Specific ) ) {
06009 strInfo += strDelim;
06010 if ( bIdent )
06011 strInfo += "referred: ";
06012 FCO referred = ( (ReferenceImpl* ) this)->getReferred();
06013 if ( ! referred )
06014 strInfo += "null";
06015 else {
06016 unsigned short usOptions2 = 0;
06017 if ( bIdent )
06018 usOptions2 |= Util::IO_Identifiers;
06019 if ( bAll || ( usOptions & Util::IO_ID ) )
06020 usOptions2 |= Util::IO_ID;
06021 if ( bAll || ( usOptions & Util::IO_Meta ) )
06022 usOptions2 |= Util::IO_Meta;
06023 if ( bAll || ( usOptions & Util::IO_Path ) )
06024 usOptions2 |= Util::IO_Path;
06025 strInfo += referred->getInfoString( usOptions2 );
06026 }
06027 }
06028
06029 if ( ! bLine )
06030 strInfo += "]";
06031
06032 return strInfo;
06033 }
06034
06035
06036
06037
06038 FCOImpl* ReferenceImpl::getReferredFCOI( const MON::FCO& meta )
06039 {
06040
06041 if ( m_referredFCO.first )
06042 return ( ! meta || meta == m_referredFCO.first ) ? m_referredFCO.second : NULL;
06043 if ( m_bAllReferredFCOs )
06044 return NULL;
06045
06046
06047 FCOPtr spFCO;
06048 COMCHECK2( getReferenceI(), getReferenceI()->get_Referred( spFCO.Addr() ) );
06049
06050 if ( spFCO.p && ( ! meta || _getMetaRef( spFCO ) == meta.ref() ) ) {
06051 m_referredFCO.first = ( meta ) ? meta : MON::FCO( getProject()->getProjectMeta().findByName( _getMetaName( spFCO ) ) );
06052 m_referredFCO.second = FCOImpl::attachI( spFCO, ObjectImpl::m_pProject, m_referredFCO.first );
06053 m_referredFCO.second->onRetrievedAsReferred( this, false );
06054 }
06055 if ( ! meta )
06056 m_bAllReferredFCOs = true;
06057
06058 return m_referredFCO.second;
06059 }
06060
06061 void ReferenceImpl::setReferredFCOI( const BON::FCO& fco )
06062 {
06063 COMCHECK2( getReferenceI(), getReferenceI()->put_Referred( fco->getFCOI() ) );
06064 }
06065
06066 bool ReferenceImpl::createRefPort( FCOImpl* pFCO )
06067 {
06068 ManyPortLink::iterator it = m_childPorts.find( pFCO );
06069 if ( it == m_childPorts.end() ) {
06070 if ( pFCO->isPort() ) {
06071 ReferencePortImpl* pPort = new ReferencePortImpl( this, pFCO );
06072 m_childPorts[ pFCO ] = pPort;
06073 pFCO->onRetrievedAsReferencePort( pPort, false );
06074 return true;
06075 }
06076 return false;
06077 }
06078 return true;
06079 }
06080
06081 ReferencePortSet ReferenceImpl::getRefPorts()
06082 {
06083 if ( ! m_bAllChildPorts ) {
06084 m_bAllChildPorts = true;
06085
06086 CComQIPtr<IMgaReference> spRef = getReferenceI().p;
06087 FCOPtr spFCO;
06088 do {
06089 FCOPtr spFCO_temp;
06090 COMCHECK2( spRef, spRef->get_Referred( spFCO_temp.Addr() ) );
06091 spFCO = spFCO_temp;
06092 } while ( spRef = spFCO.p );
06093
06094 Util::ComPtr<IMgaFCOs> spFCOs;
06095 COMCHECK2( CComQIPtr<IMgaModel>( spFCO.p ), CComQIPtr<IMgaModel>( spFCO.p )->get_ChildFCOs( spFCOs.Addr() ) );
06096 MGACOLL_ITERATE( IMgaFCO, spFCOs.p ) {
06097 createRefPort( FCOImpl::attachI( MGACOLL_ITER, ObjectImpl::m_pProject ) );
06098 } MGACOLL_ITERATE_END;
06099 }
06100
06101 ReferencePortSet setResult;
06102 for ( ManyPortLink::iterator it = m_childPorts.begin() ; it != m_childPorts.end() ; ++it )
06103 setResult.insert( it->second );
06104 return setResult;
06105 }
06106
06107 ReferencePortImpl* ReferenceImpl::getRefPort( FCOImpl* pFCO )
06108 {
06109 getRefPorts();
06110 ManyPortLink::iterator it = m_childPorts.find( pFCO );
06111 return ( it == m_childPorts.end() ) ? NULL : m_childPorts[ pFCO ];
06112 }
06113
06114
06115
06116
06117 bool ReferenceImpl::onRetrievedAsReference( FCOImpl* pFCO, bool bCheckAll )
06118 {
06119 m_bAllReferredFCOs = true;
06120 m_referredFCO.first = pFCO->getFCOMeta();
06121 m_referredFCO.second = pFCO;
06122 return true;
06123 }
06124
06125 void ReferenceImpl::onReleasedAsReference( FCOImpl* pFCO, bool bOnlyFreeMemory )
06126 {
06127 m_referredFCO.first = MON::FCO();
06128 m_referredFCO.second = NULL;
06129 m_bAllReferredFCOs = false;
06130 }
06131
06132 void ReferenceImpl::onReleasedAsPortContainer( FCOImpl* pFCO, bool bOnlyMemoryFree )
06133 {
06134 m_childPorts.erase( pFCO );
06135 if ( bOnlyMemoryFree )
06136 m_bAllChildPorts = false;
06137 }
06138
06139 void ReferenceImpl::eventPerformedI( const Event& event )
06140 {
06141 FCOImpl::eventPerformedI( event );
06142 switch ( event.getType() ) {
06143 case MON::OET_RelationChanged :
06144 onRelationChanged();
06145 break;
06146 }
06147 }
06148
06149 void ReferenceImpl::onRelationChanged()
06150 {
06151
06152 if ( m_referredFCO.second )
06153 m_referredFCO.second ->onReleasedAsReferred( this, false );
06154 m_referredFCO.first = MON::FCO();
06155 m_referredFCO.second = NULL;
06156
06157 ManyPortLink ports = m_childPorts;
06158 m_childPorts.clear();
06159 for ( ManyPortLink::iterator it = ports.begin() ; it != ports.end() ; it++ )
06160 it->second->setDeleted();
06161 m_bAllChildPorts = false;
06162
06163 }
06164
06165
06166
06167
06168 FCO ReferenceImpl::getReferred( const MON::FCO& meta )
06169 {
06170 if ( meta ) {
06171 THROW_METAPROJECT_BELONG( meta );
06172
06173 if (g_TEST_META_CONFORMANCE_INSIDE_BON && !getReferenceMeta().isReferenced(meta))
06174 {
06175 MON::Exception exc( "? cannot be referenced by ?!");
06176 exc << meta.infoString() << getObjectMeta().infoString();
06177 ASSERTTHROW( exc);
06178 }
06179 }
06180 return getReferredFCOI( meta );
06181 }
06182
06183 FCO ReferenceImpl::getReferred( const std::string& strFCO )
06184 {
06185 MON::FCO meta;
06186 if ( ! strFCO.empty() ) {
06187 meta = MON::FCO( getProject()->getProjectMeta().findByName( strFCO ) );
06188 THROW_METAPROJECT_DOES_NOT_HAVE( meta, FCO, strFCO );
06189 }
06190 return getReferred( meta );
06191 }
06192
06193 void ReferenceImpl::setReferred( const FCO& fco )
06194 {
06195 if ( fco ) {
06196 THROW_PROJECT_BELONG( fco );
06197
06198 if (g_TEST_META_CONFORMANCE_INSIDE_BON)
06199 {
06200
06201 MON::FCO meta = fco->getFCOMeta();
06202 if ( ! getReferenceMeta().isReferenced( meta ) )
06203 {
06204 MON::Exception exc( "? cannot be referenced by ?!");
06205 exc << fco->getObjectMeta().infoString() << getObjectMeta().infoString();
06206 ASSERTTHROW( exc);
06207 }
06208
06209
06210
06211
06212
06213
06214
06215
06216
06217
06218
06219
06220
06221
06222
06223
06224
06225
06226
06227
06228
06229 }
06230 }
06231 if ( ! _isAddOn() ) {
06232 if ( m_referredFCO.second )
06233 m_referredFCO.second->eventPerformedI( Event( MON::OET_ObjectReleased, m_referredFCO.second ) );
06234 if ( fco )
06235 fco->eventPerformedI( Event( MON::OET_ObjectReferenced, fco ) );
06236 }
06237 setReferredFCOI( fco );
06238 if ( getProject()->isAutoCommit() )
06239 getProject()->commit();
06240 }
06241
06242 ReferencePortContainer ReferenceImpl::getRefPortContainer()
06243 {
06244 FCO fco = getReferred();
06245 Reference ref = fco;
06246 while ( ref ) {
06247 fco = ref->getReferred();
06248 ref = fco;
06249 }
06250 return ( Model( fco ) ) ? m_pContainer : NULL;
06251 }
06252
06253
06254
06255
06256 void ReferenceImpl::accept( Visitor* pVisitor )
06257 {
06258 if ( Model( getReferred() ) ) {
06259 ReferencePortSet ports = getRefPorts();
06260 for ( ReferencePortSet::iterator it = ports.begin() ; it != ports.end() ; it++ )
06261 (*it)->accept( pVisitor );
06262 }
06263 pVisitor->visitReference( Reference( this ) );
06264 }
06265
06266 FCOExRegistryNode ReferenceImpl::getRegistry() const
06267 {
06268 return FCOImpl::getRegistry();
06269 }
06270
06271
06272
06273
06274
06275
06276
06277 ConnectionImpl::ConnectionImpl()
06278 : FCOImpl(), m_bAllEnds( false )
06279 {
06280 }
06281
06282 ConnectionImpl* ConnectionImpl::attachI( IMgaConnection* spConnection, ProjectImpl* pProject, const MON::Object& meta )
06283 {
06284
06285 if ( ! spConnection )
06286 return NULL;
06287
06288
06289 pProject = _getProject( spConnection, pProject );
06290 ObjectImpl* pObject = find( pProject, spConnection );
06291 if ( pObject )
06292 return dynamic_cast<ConnectionImpl*>( pObject );
06293
06294
06295 pObject = getEx( spConnection, OT_Connection, meta );
06296 if ( ! pObject )
06297 pObject = new ConnectionImpl();
06298 pObject->doInitialize( spConnection, pProject, meta );
06299 dynamic_cast<FCOImpl*>( pObject )->doInitialize( pProject );
06300 pObject->initialize();
06301
06302 ConnectionImpl* ci = dynamic_cast<ConnectionImpl*>( pObject );
06303 attachIPost( ci);
06304 return ci;
06305 }
06306
06307 Connection ConnectionImpl::attach( IMgaConnection* spConnection )
06308 {
06309 return attachI( spConnection );
06310 }
06311
06312 Connection ConnectionImpl::create( const Model& parent, const std::set<Connection::Pair>& ends, const MON::Connection& meta, const std::string& strRole )
06313 {
06314 if ( ! meta )
06315 return createAs( parent, ends, strRole );
06316
06317 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
06318 if ( meta.project() != parent->getProject()->getProjectMeta() )
06319 {
06320 MON::Exception exc( "? does not belong to ? of ?!");
06321 exc << meta.infoString() << parent->getProject()->getProjectMeta().infoString() << parent->getProject()->getInfoString();
06322 ASSERTTHROW( exc);
06323 }
06324
06325 MON::Containment role;
06326 std::set<MON::Containment> metas = parent->getModelMeta().childContainments();
06327 for ( std::set<MON::Containment>::iterator it = metas.begin() ; it != metas.end() ; it++ ) {
06328 if ( it->child() == meta ) {
06329 if ( strRole.empty() ) {
06330 if ( role )
06331 {
06332 MON::Exception exc( "strRole cannot be an empty string because ? can contain ? as child with more than one MON::Containment!");
06333 exc << parent->getObjectMeta().infoString() << meta.infoString();
06334 ASSERTTHROW( exc);
06335 }
06336 role = *it;
06337 }
06338 else {
06339 role = *it;
06340 break;
06341 }
06342 }
06343 }
06344
06345 if ( ! role )
06346 {
06347 MON::Exception exc( "? does not have ? as child!");
06348 exc << parent->getObjectMeta().infoString() << meta.infoString();
06349 ASSERTTHROW( exc);
06350 }
06351
06352 return createI( parent, role, ends );
06353 }
06354
06355 Connection ConnectionImpl::create( const Model& parent, const std::set<Connection::Pair>& ends, const std::string& strConnection, const std::string& strRole )
06356 {
06357 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
06358 MON::Connection meta;
06359 if ( ! strConnection.empty() ) {
06360 meta = parent->getProject()->getProjectMeta().findByName( strConnection );
06361 if ( ! meta )
06362 {
06363 MON::Exception exc( "MON::Connection [ ? ] does not exist in ? of ?!");
06364 exc << strConnection << parent->getProject()->getProjectMeta().infoString() << parent->getProject()->getInfoString();
06365 ASSERTTHROW( exc);
06366 }
06367 }
06368 return create( parent, ends, meta, strRole );
06369 }
06370
06371 Connection ConnectionImpl::create( const Model& parent, const ConnectionEnd& srcEnd, const ConnectionEnd& dstEnd, const MON::Connection& meta, const std::string& strRole )
06372 {
06373 std::set<Connection::Pair> ends;
06374 ends.insert( Connection::Pair( "src", srcEnd ) );
06375 ends.insert( Connection::Pair( "dst", dstEnd ) );
06376 return create( parent, ends, meta, strRole );
06377 }
06378
06379 Connection ConnectionImpl::create( const Model& parent, const ConnectionEnd& srcEnd, const ConnectionEnd& dstEnd, const std::string& strConnection, const std::string& strRole )
06380 {
06381 std::set<Connection::Pair> ends;
06382 ends.insert( Connection::Pair( "src", srcEnd ) );
06383 ends.insert( Connection::Pair( "dst", dstEnd ) );
06384 return create( parent, ends, strConnection, strRole );
06385 }
06386
06387 Connection ConnectionImpl::createAs( const Model& parent, const std::set<Connection::Pair>& ends, const std::string& strRole )
06388 {
06389 THROW_CANNOT_BE_NULL( parent, "BON::Model" );
06390
06391 MON::Containment role;
06392 std::set<MON::Containment> metas = parent->getModelMeta().childContainments();
06393 if ( strRole.empty() ) {
06394 for ( std::set<MON::Containment>::iterator it = metas.begin() ; it != metas.end() ; it++ ) {
06395 if ( it->child().type() == MON::OT_Connection ) {
06396 if ( role )
06397 {
06398 MON::Exception exc( "strRole cannot be an empty string because ? can contain more than one MON::Containment with child MON::Connection!");
06399 exc << parent->getObjectMeta().infoString();
06400 ASSERTTHROW( exc);
06401 }
06402 role = *it;
06403 }
06404 }
06405 if ( ! role )
06406 {
06407 MON::Exception exc( "? does not have MON::Connection as child!");
06408 exc << parent->getObjectMeta().infoString();
06409 ASSERTTHROW( exc);
06410 }
06411 }
06412 else {
06413 for ( std::set<MON::Containment>::iterator it = metas.begin() ; it != metas.end() ; it++ ) {
06414 if ( (it->name() == strRole || it->name() == parent->getProject()->prefixWNmsp( strRole)) && it->child().type() == MON::OT_Connection ) {
06415 role = *it;
06416 break;
06417 }
06418 }
06419 if ( ! role )
06420 {
06421 MON::Exception exc( "? does not have MON::Connection as child with containment role [ ? ]!");
06422 exc << parent->getObjectMeta().infoString() << strRole;
06423 ASSERTTHROW( exc);
06424 }
06425 }
06426
06427 return createI( parent, role, ends );
06428 }
06429
06430 Connection ConnectionImpl::createAs( const Model& parent, const ConnectionEnd& srcEnd, const ConnectionEnd& dstEnd, const std::string& strRole )
06431 {
06432 std::set<Connection::Pair> ends;
06433 ends.insert( Connection::Pair( "src", srcEnd ) );
06434 ends.insert( Connection::Pair( "dst", dstEnd ) );
06435 return createAs( parent, ends, strRole );
06436 }
06437
06438 ConnectionImpl::~ConnectionImpl()
06439 {
06440 if ( ! ObjectImpl::m_pProject->isDestructionActive() && ! isDeleted() ) {
06441 for ( ManyFCOLink::iterator it = m_ends.begin() ; it != m_ends.end() ; it++ )
06442 it->second->onReleasedAsConnectionEnd( this, it->first.first, false );
06443 }
06444
06445 m_ends.clear();
06446 m_refWrappers.clear();
06447 m_fcoWrappers.clear();
06448 }
06449
06450 bool ConnectionImpl::setDeleted()
06451 {
06452 if ( FCOImpl::setDeleted() )
06453 return true;
06454
06455 for ( ManyFCOLink::iterator it = m_ends.begin() ; it != m_ends.end() ; it++ )
06456 it->second->onReleasedAsConnectionEnd( this, it->first.first, false );
06457 return false;
06458 }
06459
06460
06461
06462
06463 ObjectType ConnectionImpl::getStereotype() const
06464 {
06465 return OT_Connection;
06466 }
06467
06468 ConnectionPtr ConnectionImpl::getConnectionI() const
06469 {
06470 CComQIPtr<IMgaConnection> spConnection = getObjectI().p;
06471 return spConnection.p;
06472 }
06473
06474 MON::Connection ConnectionImpl::getConnectionMeta() const
06475 {
06476 return getObjectMeta();
06477 }
06478
06479 std::string ConnectionImpl::getInfoString( unsigned short usOptions ) const
06480 {
06481 bool bAll = ( usOptions & Util::IO_All ) ? true : false;
06482 bool bIdent = bAll || ( usOptions & Util::IO_Identifiers );
06483 bool bLine = bAll || ( usOptions & Util::IO_NewLine );
06484 std::string strDelim = ( bLine ) ? "\n" : ", ";
06485
06486 std::string strInfo = getInfoStringHelper( usOptions, "Connection" );
06487 if ( bAll || ( usOptions & Util::IO_Specific ) ) {
06488 ( (ConnectionImpl*) this )->getConnEnds();
06489
06490 unsigned short usOptions2 = 0;
06491 if ( bIdent )
06492 usOptions2 |= Util::IO_Identifiers;
06493 if ( bAll || ( usOptions & Util::IO_ID ) )
06494 usOptions2 |= Util::IO_ID;
06495 if ( bAll || ( usOptions & Util::IO_Meta ) )
06496 usOptions2 |= Util::IO_Meta;
06497 if ( bAll || ( usOptions & Util::IO_Path ) )
06498 usOptions2 |= Util::IO_Path;
06499
06500 for ( ManyFCOLink::const_iterator it = m_ends.begin() ; it != m_ends.end() ; it++ ) {
06501 strInfo += strDelim;
06502 if ( bIdent )
06503 strInfo += it->first.first + ": ";
06504 strInfo += it->second->getInfoString( usOptions2 );
06505 }
06506 }
06507
06508 if ( ! bLine )
06509 strInfo += "]";
06510
06511 return strInfo;
06512 }
06513
06514
06515
06516
06517 ConnectionEndImpl* ConnectionImpl::getConnectionEndI( const std::string& strRole, const MON::FCO& meta )
06518 {
06519 if ( ! m_bAllEnds ) {
06520 m_bAllEnds = true;
06521 Util::ComPtr<IMgaConnPoints> spCPs;
06522 COMCHECK2( getConnectionI(), getConnectionI()->get_ConnPoints( spCPs.Addr() ) );
06523 MGACOLL_ITERATE( IMgaConnPoint, spCPs.p ) {
06524 CComBSTR bstrRole;
06525 COMCHECK2( MGACOLL_ITER, MGACOLL_ITER->get_ConnRole( &bstrRole ) );
06526 FCOPtr spTarget;
06527 COMCHECK2( MGACOLL_ITER, MGACOLL_ITER->get_Target( spTarget.Addr() ) );
06528 MON::Connection::Pair key( Util::Copy( bstrRole ), MON::FCO( getProject()->getProjectMeta().findByName( _getMetaName( spTarget ) ) ) );
06529 if ( m_ends.find( key ) == m_ends.end() ) {
06530 ConnectionEndImpl* pCE = ConnectionEndImpl::attachI( MGACOLL_ITER, ObjectImpl::m_pProject, key.second );
06531 m_ends[ key ] = pCE;
06532 if( !pCE) ASSERT(0);
06533 else pCE->onRetrievedAsConnectionEnd( this, Util::Copy( bstrRole ), false );
06534 }
06535 } MGACOLL_ITERATE_END;
06536 }
06537
06538 for ( ManyFCOLink::iterator it = m_ends.begin() ; it != m_ends.end() ; ++it )
06539 if ( ( strRole.empty() || strRole == it->first.first ) && ( ! meta || meta == it->first.second ) )
06540 return it->second;
06541 return NULL;
06542 }
06543
06544 ConnectionImpl* ConnectionImpl::createI( const Model& parent, const MON::Containment& meta, const std::set<Connection::Pair>& ends )
06545 {
06546 if ( ! MON::Connection( meta.child() ).isSimple() )
06547 {
06548 MON::Exception exc( "? is not simple. Not binary MON::Connections are supported!");
06549 exc << meta.child().infoString();
06550 ASSERTTHROW( exc);
06551 }
06552
06553 std::map<std::string, FCOsPtr> mapRefSeqs;
06554 std::map<std::string,FCO> mapEnds;
06555
06556 std::set<Connection::Pair>::const_iterator it;
06557 for ( it = ends.begin() ; it != ends.end() ; it++ ) {
06558 THROW_CANNOT_BE_NULL( it->second, "BON::ConnectionEnd" );
06559 if ( parent->getProject() != it->second->getProject() )
06560 {
06561 BON::Exception exc( "? does not belong to ?!");
06562 exc << it->second->getInfoString() << parent->getProject()->getInfoString();
06563 ASSERTTHROW( exc);
06564 }
06565
06566 mapRefSeqs[ it->first ] = FCOsPtr();
06567 if ( it->second->isReferencePort() ) {
06568 ReferencePort port( it->second );
06569 mapEnds[ it->first ] = port->getFCO();
06570 Reference ref = port->getContainer()->getReference();
06571 while ( ref ) {
06572 COMCHECK2( ref->getFCOI(), ref->getFCOI()->CreateCollection( mapRefSeqs[ it->first ].Addr() ) );
06573 ref = ref->getReferred();
06574 }
06575 }
06576 else {
06577 mapEnds[ it->first ] = it->second;
06578 }
06579 }
06580
06581 std::set<MON::ConnectionRole> roles = MON::Connection( meta.child() ).specification( 0 ).roles();
06582 if ( roles.size() != mapEnds.size() )
06583 {
06584 Exception exc( "Number of MON::ConnectionEnds of ? is ?, not ?");
06585 exc << meta.infoString() << (long) roles.size() << (long) mapEnds.size();
06586 ASSERTTHROW( exc);
06587 }
06588
06589 std::set<MON::ConnectionRole>::iterator itR;
06590 for ( itR = roles.begin() ; itR != roles.end() ; itR++ )
06591 if ( mapEnds.find( itR->name() ) == mapEnds.end() )
06592 {
06593 Exception exc( "BON::ConnectionEnd of ? at role [ ? ] is unspecified.");
06594 exc << meta.infoString() << itR->name();
06595 ASSERTTHROW( exc);
06596 }
06597
06598 if (g_TEST_META_CONFORMANCE_INSIDE_BON)
06599 {
06600 bool bOK = false;
06601 for ( int i = 0 ; i < MON::Connection( meta.child() ).specificationCount() && ! bOK ; i++ ) {
06602 bOK = true;
06603 roles = MON::Connection( meta.child() ).specification( i ).roles();
06604 for ( itR = roles.begin() ; itR != roles.end() ; itR++ ) {
06605 if ( ! itR->isTarget( mapEnds[ itR->name() ]->getRole() ) ) {
06606 bOK = false;
06607 break;
06608 }
06609 }
06610 }
06611
06612 if ( ! bOK ) {
06613 std::vector<std::string> vecParams;
06614 std::string strEx;
06615 for ( it = ends.begin() ; it != ends.end() ; it++ ) {
06616 if ( ends.begin() != it )
06617 strEx += ", ";
06618 strEx += "? with role [ ? ]";
06619 vecParams.push_back( it->second->getInfoString() );
06620 vecParams.push_back( it->first );
06621 }
06622 strEx += " cannot be connected with ?!";
06623 ASSERTTHROW( MON::Exception( strEx, vecParams ) );
06624 }
06625
06626 }
06627
06628 FCOPtr spFCO;
06629 COMCHECK2( parent->getModelI(), parent->getModelI()->CreateSimpleConn( meta.getContainmentI(), mapEnds[ "src" ]->getFCOI(), mapEnds[ "dst" ]->getFCOI(), mapRefSeqs[ "src" ], mapRefSeqs[ "dst" ], spFCO.Addr() ) );
06630 ConnectionImpl* pConnection = ConnectionImpl::attachI( CComQIPtr<IMgaConnection>( spFCO.p ), (ProjectImpl*) parent->getProject().getCounted(), meta.child() );
06631 if ( pConnection->getProject()->isAutoCommit() )
06632 pConnection->getProject()->commit();
06633 if ( ! _isAddOn() )
06634 pConnection->eventPerformedI( Event( MON::OET_ObjectCreated, pConnection ) );
06635 return pConnection;
06636 }
06637
06638
06639
06640
06641 bool ConnectionImpl::onRetrievedAsConnection( ConnectionEndImpl* pCE, const std::string& strRole, bool bCheckAll )
06642 {
06643 if ( ! m_bAllEnds && bCheckAll )
06644 return false;
06645 m_ends[ MON::Connection::Pair( strRole, pCE->getFCOHelper()->getFCOMeta() ) ] = pCE;
06646 return true;
06647 }
06648
06649 void ConnectionImpl::onReleasedAsConnection( ConnectionEndImpl* pCE, const std::string& strRole, bool bOnlyFreeMemory )
06650 {
06651 for ( ManyFCOLink::iterator it = m_ends.begin() ; it != m_ends.end() ; it++ )
06652 if ( it->first.first == strRole ) {
06653 m_ends.erase( it );
06654 break;
06655 }
06656 m_bAllEnds = false;
06657 }
06658
06659 void ConnectionImpl::eventPerformedI( const Event& event )
06660 {
06661 FCOImpl::eventPerformedI( event );
06662 switch ( event.getType() ) {
06663 case MON::OET_ObjectCreated :
06664 onObjectCreated();
06665 break;
06666 }
06667 }
06668
06669 void ConnectionImpl::onObjectCreated()
06670 {
06671 std::multiset<ConnectionEnd> ss = getConnEnds();
06672 for( std::multiset<ConnectionEnd>::const_iterator it = ss.begin(); it != ss.end(); ++it)
06673 {
06674 ReferencePort rpi( *it);
06675 if( rpi)
06676 {
06677 Reference the_ref = rpi->getContainer()->getReference();
06678 m_refWrappers.insert( the_ref );
06679 FCO the_target = rpi->getFCO();
06680 m_fcoWrappers.insert( the_target);
06681 }
06682 }
06683 }
06684
06685
06686
06687
06688 std::multiset<ConnectionEnd> ConnectionImpl::getConnEnds( const MON::FCO& meta )
06689 {
06690 if ( meta )
06691 THROW_METAPROJECT_BELONG( meta );
06692
06693 std::set<std::string> theRoles;
06694
06695 bool bFound = false;
06696 for ( int i = 0 ; i < getConnectionMeta().specificationCount() ; i++ ) {
06697 std::set<MON::ConnectionRole> roles = getConnectionMeta().specification( i ).roles();
06698 for ( std::set<MON::ConnectionRole>::iterator it = roles.begin() ; it != roles.end() ; it++ ) {
06699 if ( ! meta || it->isTarget( meta ) ) {
06700 bFound = true;
06701 theRoles.insert( it->name() );
06702 }
06703 }
06704 }
06705
06706 if ( ! bFound )
06707 {
06708 MON::Exception exc( "? cannot be target of ?!");
06709 exc << meta.infoString() << getObjectMeta().infoString();
06710 ASSERTTHROW( exc);
06711 }
06712
06713 std::multiset<ConnectionEnd> setResult;
06714 for ( std::set<std::string>::iterator it = theRoles.begin() ; it != theRoles.end() ; it++ ) {
06715 ConnectionEndImpl* pEnd = getConnectionEndI( *it, meta );
06716 if ( pEnd )
06717 setResult.insert( pEnd );
06718 }
06719
06720 return setResult;
06721 }
06722
06723 std::multiset<ConnectionEnd> ConnectionImpl::getConnEnds( const std::string& strFCO )
06724 {
06725 MON::FCO meta;
06726 if ( ! strFCO.empty() ) {
06727 meta = MON::FCO( getProject()->getProjectMeta().findByName( strFCO ) );
06728 THROW_METAPROJECT_DOES_NOT_HAVE( meta, FCO, strFCO );
06729 }
06730 return getConnEnds( meta );
06731 }
06732
06733 ConnectionEnd ConnectionImpl::getConnEnd( const std::string& strRole, const MON::FCO& meta )
06734 {
06735 THROW_CANNOT_BE_EMPTY( "Role", strRole );
06736 if ( meta )
06737 THROW_METAPROJECT_BELONG( meta );
06738
06739 if (g_TEST_META_CONFORMANCE_INSIDE_BON)
06740 {
06741 bool bRoleFound = false;
06742 bool bFound = false;
06743 for ( int i = 0 ; i < getConnectionMeta().specificationCount() ; i++ ) {
06744 std::set<MON::ConnectionRole> roles = getConnectionMeta().specification( i ).roles();
06745 for ( std::set<MON::ConnectionRole>::iterator it = roles.begin() ; it != roles.end() ; it++ ) {
06746 if ( strRole == it->name() ) {
06747 bRoleFound = true;
06748 if ( ! meta || it->isTarget( meta ) ) {
06749 bFound = true;
06750 break;
06751 }
06752 }
06753 }
06754 if ( bFound )
06755 break;
06756 }
06757
06758 if ( ! bRoleFound )
06759 {
06760 MON::Exception exc( "? cannot be has role ?!");
06761 exc << getObjectMeta().infoString() << strRole.c_str();
06762 ASSERTTHROW( exc);
06763 }
06764 if ( ! bFound )
06765 {
06766 MON::Exception exc( "? cannot be target of ? with role ?!");
06767 exc << meta.infoString() << getObjectMeta().infoString() << strRole;
06768 ASSERTTHROW( exc);
06769 }
06770
06771 }
06772
06773 return getConnectionEndI( strRole, meta );
06774 }
06775
06776 ConnectionEnd ConnectionImpl::getConnEnd( const std::string& strRole, const std::string& strFCO )
06777 {
06778 MON::FCO meta;
06779 if ( ! strFCO.empty() ) {
06780 meta = MON::FCO( getProject()->getProjectMeta().findByName( strFCO ) );
06781 THROW_METAPROJECT_DOES_NOT_HAVE( meta, FCO, strFCO );
06782 }
06783 return getConnEnd( strRole, meta );
06784 }
06785
06786 ConnectionEnd ConnectionImpl::getSrc( const MON::FCO& meta )
06787 {
06788 if ( ! getConnectionMeta().isSimple() )
06789 {
06790 MON::Exception exc( "? is not simple!");
06791 exc << getObjectMeta().infoString();
06792 ASSERTTHROW( exc);
06793 }
06794 return getConnEnd( "src", meta );
06795 }
06796
06797 ConnectionEnd ConnectionImpl::getSrc( const std::string& strFCO )
06798 {
06799 if ( ! getConnectionMeta().isSimple() )
06800 {
06801 MON::Exception exc( "? is not simple!");
06802 exc << getObjectMeta().infoString();
06803 ASSERTTHROW( exc);
06804 }
06805 return getConnEnd( "src", strFCO );
06806 }
06807
06808 ConnectionEnd ConnectionImpl::getDst( const MON::FCO& meta )
06809 {
06810 if ( ! getConnectionMeta().isSimple() )
06811 {
06812 MON::Exception exc( "? is not simple!");
06813 exc << getObjectMeta().infoString();
06814 ASSERTTHROW( exc);
06815 }
06816 return getConnEnd( "dst", meta );
06817 }
06818
06819 ConnectionEnd ConnectionImpl::getDst( const std::string& strFCO )
06820 {
06821 if ( ! getConnectionMeta().isSimple() )
06822 {
06823 MON::Exception exc( "? is not simple!");
06824 exc << getObjectMeta().infoString();
06825 ASSERTTHROW( exc);
06826 }
06827 return getConnEnd( "dst", strFCO );
06828 }
06829
06830
06831
06832
06833 void ConnectionImpl::accept( Visitor* pVisitor )
06834 {
06835 pVisitor->visitConnection( Connection( this ) );
06836 }
06837
06838 ConnectionRegistryNode ConnectionImpl::getRegistry() const
06839 {
06840 return FCOImpl::getRegistry();
06841 }
06842
06843
06844
06845
06846
06847
06848
06849 ReferencePortContainerImpl::ReferencePortContainerImpl( ReferenceImpl* pReference )
06850 : Util::GenRefCounted( false, pReference ), m_pReference( pReference )
06851 {
06852 }
06853
06854 Project ReferencePortContainerImpl::getProject() const
06855 {
06856 return m_pReference->getProject();
06857 }
06858
06859 Reference ReferencePortContainerImpl::getReference() const
06860 {
06861 return m_pReference;
06862 }
06863
06864 std::set<ReferencePort> ReferencePortContainerImpl::getReferencePorts()
06865 {
06866 std::set<ReferencePort> setResult;
06867 setCopy<ReferencePort,ReferencePortImpl>( m_pReference->getRefPorts(), setResult );
06868 return setResult;
06869 }
06870
06871 ReferencePort ReferencePortContainerImpl::getReferencePort( const FCO& fco )
06872 {
06873 THROW_CANNOT_BE_NULL( fco, "BON::FCO" );
06874 THROW_PROJECT_BELONG( fco )
06875 return m_pReference->getRefPort( dynamic_cast<FCOImpl*>( fco.getCounted() ) );
06876 }
06877
06878
06879
06880
06881
06882
06883
06884 TypeInhObjectImpl::TypeInhObjectImpl( FCOImpl* pFCO )
06885 : Util::GenRefCounted( false, pFCO ), m_pFCO( pFCO )
06886 {
06887 }
06888
06889 bool TypeInhObjectImpl::setDeleted()
06890 {
06891 return isDeleted();
06892 }
06893
06894 Project TypeInhObjectImpl::getProject() const
06895 {
06896 return m_pFCO->getProject();
06897 }
06898
06899 FCO TypeInhObjectImpl::getFCO() const
06900 {
06901 return m_pFCO;
06902 }
06903
06904 bool TypeInhObjectImpl::isInstance() const
06905 {
06906 return m_pFCO->isInstance();
06907 }
06908
06909 Type TypeInhObjectImpl::getType()
06910 {
06911 FCOImpl* pFCO = m_pFCO->getType();
06912 return ( pFCO ) ? pFCO->getTypeInhObject() : Type( NULL );
06913 }
06914
06915
06916
06917
06918
06919
06920
06921 InstanceImpl::InstanceImpl( FCOImpl* pFCO )
06922 : TypeInhObjectImpl( pFCO )
06923 {
06924 }
06925
06926
06927
06928
06929
06930
06931
06932 TypeImpl::TypeImpl( FCOImpl* pFCO )
06933 : TypeInhObjectImpl( pFCO )
06934 {
06935 }
06936
06937 std::set<Type> TypeImpl::getSubTypes()
06938 {
06939 FCOSet fcos = m_pFCO->getDerivedFCOs( false );
06940 std::set<Type> setResult;
06941 for ( FCOSet::iterator it = fcos.begin() ; it != fcos.end() ; it++ )
06942 setResult.insert( (*it)->getTypeInhObject() );
06943 return setResult;
06944 }
06945
06946 std::set<Instance> TypeImpl::getInstance()
06947 {
06948 FCOSet fcos = m_pFCO->getDerivedFCOs( true );
06949 std::set<Instance> setResult;
06950 for ( FCOSet::iterator it = fcos.begin() ; it != fcos.end() ; it++ )
06951 setResult.insert( (*it)->getTypeInhObject() );
06952 return setResult;
06953 }
06954
06955 std::set<TypeInhObject> TypeImpl::getDerivedObjects()
06956 {
06957 std::set<TypeInhObject> setResult;
06958 FCOSet fcos1 = m_pFCO->getDerivedFCOs( false );
06959 FCOSet fcos2 = m_pFCO->getDerivedFCOs( true );
06960
06961 FCOSet::iterator it;
06962 for ( it = fcos1.begin() ; it != fcos1.end() ; it++ )
06963 setResult.insert( (*it)->getTypeInhObject() );
06964 for ( it = fcos2.begin() ; it != fcos2.end() ; it++ )
06965 setResult.insert( (*it)->getTypeInhObject() );
06966 return setResult;
06967 }
06968
06969
06970
06971
06972
06973
06974
06975 FCORegistryNodeImpl::FCORegistryNodeImpl( FCOImpl* pObject )
06976 : RegistryNodeImpl( NULL, pObject )
06977 {
06978 }
06979
06980 COLORREF FCORegistryNodeImpl::getColor() const
06981 {
06982 COLORREF color;
06983 return ( Convert( getObject()->getRegistry()->getValueByPath( PREF_Color ), color ) ) ? color : RGB( 00, 00, 00 );
06984 }
06985
06986 void FCORegistryNodeImpl::setColor( COLORREF color )
06987 {
06988 getObject()->getRegistry()->setValueByPath( PREF_Color, Convert( color ) );
06989 }
06990
06991 COLORREF FCORegistryNodeImpl::getNameColor() const
06992 {
06993 COLORREF color;
06994 return ( Convert( getObject()->getRegistry()->getValueByPath( PREF_NameColor ), color ) ) ? color : RGB( 00, 00, 00 );
06995 }
06996
06997 void FCORegistryNodeImpl::setNameColor( COLORREF color )
06998 {
06999 getObject()->getRegistry()->setValueByPath( PREF_NameColor, Convert( color ) );
07000 }
07001
07002 bool FCORegistryNodeImpl::getNameEnabled() const
07003 {
07004 std::string strValue = getObject()->getRegistry()->getValueByPath( PREF_NameEnabled );
07005 return ( strValue.empty() ) ? true : (bool) Util::Variant( strValue );
07006 }
07007
07008 void FCORegistryNodeImpl::setNameEnabled( bool bEnabled )
07009 {
07010 getObject()->getRegistry()->setValueByPath( PREF_NameEnabled, (std::string) Util::Variant( bEnabled ) );
07011 }
07012
07013 std::string FCORegistryNodeImpl::getHelpURL() const
07014 {
07015 return getObject()->getRegistry()->getValueByPath( PREF_HelpURL );
07016 }
07017
07018 void FCORegistryNodeImpl::setHelpURL( const std::string& strURL )
07019 {
07020 getObject()->getRegistry()->setValueByPath( PREF_HelpURL, strURL );
07021 }
07022
07023 std::set<AutoRouterPref> FCORegistryNodeImpl::getInAutoRouterPref() const
07024 {
07025 return std::set<AutoRouterPref>();
07026 }
07027
07028 void FCORegistryNodeImpl::setInAutoRouterPref( const std::set<AutoRouterPref>& setPrefs )
07029 {
07030 }
07031
07032 std::set<AutoRouterPref> FCORegistryNodeImpl::getOutAutoRouterPref() const
07033 {
07034 return std::set<AutoRouterPref>();
07035 }
07036
07037 void FCORegistryNodeImpl::setOutAutoRouterPref( const std::set<AutoRouterPref>& setPrefs )
07038 {
07039 }
07040
07041
07042
07043
07044
07045
07046
07047 FCOExRegistryNodeImpl::FCOExRegistryNodeImpl( FCOImpl* pObject )
07048 : FCORegistryNodeImpl( pObject )
07049 {
07050 }
07051
07052 Point FCOExRegistryNodeImpl::getLocation( const MON::Aspect& aspect ) const
07053 {
07054 if ( aspect ) {
07055 if ( getObject()->getProject()->getProjectMeta() != aspect.project() )
07056 {
07057 MON::Exception exc( "? does not belong to ? of ?!");
07058 exc << aspect.infoString() << getObject()->getProject()->getProjectMeta().infoString() << getObject()->getProject()->getInfoString();
07059 ASSERTTHROW( exc);
07060 }
07061
07062 Point point;
07063 std::string strLocation = getObject()->getRegistry()->getValueByPath( PREF_Location1 + aspect.name() + PREF_Location2 );
07064 return ( sscanf( strLocation.c_str(), "%d,%d", &(point.first), &(point.second) ) == 2 ) ? point : Point( 0, 0 );
07065 }
07066
07067 if ( ! FCO( getObject() )->getRole() )
07068 return Point( 0, 0 );
07069 std::set<MON::ContainmentPart> parts = FCO( getObject() )->getRole().parts();
07070 if ( parts.empty() )
07071 return Point( 0, 0 );
07072
07073 std::set<MON::ContainmentPart>::iterator it;
07074 for ( it = parts.begin() ; it != parts.end() ; it++ )
07075 if ( it->isPrimary() ) {
07076 Point point;
07077 std::string strLocation = getObject()->getRegistry()->getValueByPath( PREF_Location1 + it->aspect().name() + PREF_Location2 );
07078 if ( sscanf( strLocation.c_str(), "%d,%d", &(point.first), &(point.second) ) == 2 )
07079 return point;
07080 else
07081 break;
07082 }
07083
07084 it = parts.begin();
07085 Point point;
07086 std::string strLocation = getObject()->getRegistry()->getValueByPath( PREF_Location1 + it->aspect().name() + PREF_Location2 );
07087 return ( sscanf( strLocation.c_str(), "%d,%d", &(point.first), &(point.second) ) == 2 ) ? point : Point( 0, 0 );
07088 }
07089
07090 void FCOExRegistryNodeImpl::setLocation( const Point& point, const MON::Aspect& aspect )
07091 {
07092 if ( aspect ) {
07093 if ( getObject()->getProject()->getProjectMeta() != aspect.project() )
07094 {
07095 MON::Exception exc( "? does not belong to ? of ?!");
07096 exc << aspect.infoString() << getObject()->getProject()->getProjectMeta().infoString() << getObject()->getProject()->getInfoString();
07097 ASSERTTHROW( exc);
07098 }
07099
07100 char chBuffer[ 100 ];
07101 sprintf( chBuffer, "%d,%d", point.first, point.second );
07102 getObject()->getRegistry()->setValueByPath( PREF_Location1 + aspect.name() + PREF_Location2, std::string( chBuffer ) );
07103 return;
07104 }
07105
07106 if ( FCO( getObject() )->getRole() ) {
07107
07108 char chBuffer[ 100 ];
07109 sprintf( chBuffer, "%d,%d", point.first, point.second );
07110
07111 std::set<MON::ContainmentPart> parts = FCO( getObject() )->getRole().parts();
07112 for ( std::set<MON::ContainmentPart>::iterator it = parts.begin() ; it != parts.end() ; it++ )
07113 getObject()->getRegistry()->setValueByPath( PREF_Location1 + it->aspect().name() + PREF_Location2, std::string( chBuffer ) );
07114 }
07115 }
07116
07117 Point FCOExRegistryNodeImpl::getLocation( const std::string& strAspect ) const
07118 {
07119 MON::Aspect meta;
07120 if ( ! strAspect.empty() ) {
07121 meta = getProject()->getProjectMeta().findByName( strAspect );
07122 THROW_METAPROJECT_DOES_NOT_HAVE( meta, Aspect, strAspect );
07123 }
07124 return getLocation( meta );
07125 }
07126
07127 void FCOExRegistryNodeImpl::setLocation( const Point& point, const std::string& strAspect )
07128 {
07129 MON::Aspect meta;
07130 if ( ! strAspect.empty() ) {
07131 meta = getProject()->getProjectMeta().findByName( strAspect );
07132 THROW_METAPROJECT_DOES_NOT_HAVE( meta, Aspect, strAspect );
07133 }
07134 setLocation( point, meta );
07135 }
07136
07137 NamePosition FCOExRegistryNodeImpl::getNamePosition() const
07138 {
07139 NamePosition ePos;
07140 return ( ! Convert( getObject()->getRegistry()->getValueByPath( PREF_NamePosition ), ePos ) ) ? ePos : NP_South;
07141 }
07142
07143 void FCOExRegistryNodeImpl::setNamePosition( NamePosition pos )
07144 {
07145 getObject()->getRegistry()->setValueByPath( PREF_NamePosition, Convert( pos ) );
07146 }
07147
07148 unsigned short FCOExRegistryNodeImpl::getNameWrap() const
07149 {
07150 long lWrap = (long) Util::Variant( getObject()->getRegistry()->getValueByPath( PREF_NameWrap ) );
07151 return ( lWrap < 0 ) ? 0 : (unsigned short) lWrap;
07152 }
07153
07154 void FCOExRegistryNodeImpl::setNameWrap( unsigned short usWrap )
07155 {
07156 getObject()->getRegistry()->setValueByPath( PREF_NameWrap, (std::string) Util::Variant( (long) usWrap ) );
07157 }
07158
07159 bool FCOExRegistryNodeImpl::getHotspotEnabled() const
07160 {
07161 std::string strHot = getObject()->getRegistry()->getValueByPath( PREF_HotSpotEnabled );
07162 return ( strHot.empty() ) ? true : (bool) Util::Variant( strHot );
07163 }
07164
07165 void FCOExRegistryNodeImpl::setHotspotEnabled( bool bEnabled )
07166 {
07167 getObject()->getRegistry()->setValueByPath( PREF_HotSpotEnabled, (std::string) Util::Variant( bEnabled ) );
07168 }
07169
07170 bool FCOExRegistryNodeImpl::getTypeNameEnabled() const
07171 {
07172 std::string strEnabled = getObject()->getRegistry()->getValueByPath( PREF_TypeNameEnabled );
07173 return ( strEnabled.empty() ) ? true : (bool) Util::Variant( strEnabled );
07174 }
07175
07176 void FCOExRegistryNodeImpl::setTypeNameEnabled( bool bEnabled )
07177 {
07178 getObject()->getRegistry()->setValueByPath( PREF_TypeNameEnabled, (std::string) Util::Variant( bEnabled ) );
07179 }
07180
07181 bool FCOExRegistryNodeImpl::getTypeInfoEnabled() const
07182 {
07183 std::string strEnabled = getObject()->getRegistry()->getValueByPath( PREF_TypeInfoEnabled );
07184 return ( strEnabled.empty() ) ? true : (bool) Util::Variant( strEnabled );
07185 }
07186
07187 void FCOExRegistryNodeImpl::setTypeInfoEnabled( bool bEnabled )
07188 {
07189 getObject()->getRegistry()->setValueByPath( PREF_TypeInfoEnabled, (std::string) Util::Variant( bEnabled ) );
07190 }
07191
07192 bool FCOExRegistryNodeImpl::getModelAutoRoutingEnabled() const
07193 {
07194 std::string strEnabled = getObject()->getRegistry()->getValueByPath( PREF_ModelAutoRoutingEnabled );
07195 return ( strEnabled.empty() ) ? true : (bool) Util::Variant( strEnabled );
07196 }
07197
07198 void FCOExRegistryNodeImpl::setModelAutoRoutingEnabled( bool bEnabled )
07199 {
07200 getObject()->getRegistry()->setValueByPath( PREF_ModelAutoRoutingEnabled, (std::string) Util::Variant( bEnabled ) );
07201 }
07202
07203 std::string FCOExRegistryNodeImpl::getDecorator() const
07204 {
07205 return getObject()->getRegistry()->getValueByPath( PREF_Decorator );
07206 }
07207
07208 void FCOExRegistryNodeImpl::setDecorator( const std::string& strName )
07209 {
07210 getObject()->getRegistry()->setValueByPath( PREF_Decorator, strName );
07211 }
07212
07213 std::string FCOExRegistryNodeImpl::getIcon() const
07214 {
07215 return getObject()->getRegistry()->getValueByPath( PREF_Icon );
07216 }
07217
07218 void FCOExRegistryNodeImpl::setIcon( const std::string& strName ) const
07219 {
07220 getObject()->getRegistry()->setValueByPath( PREF_Icon, strName );
07221 }
07222
07223 std::string FCOExRegistryNodeImpl::getPortIcon() const
07224 {
07225 return getObject()->getRegistry()->getValueByPath( PREF_PortIcon );
07226 }
07227
07228 void FCOExRegistryNodeImpl::setPortIcon( const std::string& strName ) const
07229 {
07230 getObject()->getRegistry()->setValueByPath( PREF_PortIcon, strName );
07231 }
07232
07233 std::string FCOExRegistryNodeImpl::getSubTypeIcon() const
07234 {
07235 return getObject()->getRegistry()->getValueByPath( PREF_SubTypeIcon );
07236 }
07237
07238 void FCOExRegistryNodeImpl::setSubTypeIcon( const std::string& strName ) const
07239 {
07240 getObject()->getRegistry()->setValueByPath( PREF_SubTypeIcon, strName );
07241 }
07242
07243 std::string FCOExRegistryNodeImpl::getInstanceIcon() const
07244 {
07245 return getObject()->getRegistry()->getValueByPath( PREF_InstanceIcon );
07246 }
07247
07248 void FCOExRegistryNodeImpl::setInstanceIcon( const std::string& strName ) const
07249 {
07250 getObject()->getRegistry()->setValueByPath( PREF_InstanceIcon, strName );
07251 }
07252
07253
07254
07255
07256
07257
07258
07259 ModelRegistryNodeImpl::ModelRegistryNodeImpl( ModelImpl* pModel )
07260 : FCOExRegistryNodeImpl( pModel )
07261 {
07262 }
07263
07264 COLORREF ModelRegistryNodeImpl::getBorderColor() const
07265 {
07266 COLORREF color;
07267 return ( Convert( getObject()->getRegistry()->getValueByPath( PREF_BorderColor ), color ) ) ? color : RGB( 0, 0, 0 );
07268 }
07269
07270 void ModelRegistryNodeImpl::setBorderColor( COLORREF color )
07271 {
07272 getObject()->getRegistry()->setValueByPath( PREF_BorderColor, Convert( color ) );
07273 }
07274
07275 COLORREF ModelRegistryNodeImpl::getBackgroundColor() const
07276 {
07277 COLORREF color;
07278 return ( Convert( getObject()->getRegistry()->getValueByPath( PREF_BackgroundColor ), color ) ) ? color : RGB( 0, 0, 0 );
07279 }
07280
07281 void ModelRegistryNodeImpl::setBackgroundColor( COLORREF color )
07282 {
07283 getObject()->getRegistry()->setValueByPath( PREF_BackgroundColor, Convert( color ) );
07284 }
07285
07286 COLORREF ModelRegistryNodeImpl::getPortNameColor() const
07287 {
07288 COLORREF color;
07289 return ( Convert( getObject()->getRegistry()->getValueByPath( PREF_PortNameColor ), color ) ) ? color : RGB( 0, 0, 0 );
07290 }
07291
07292 void ModelRegistryNodeImpl::setPortNameColor( COLORREF color )
07293 {
07294 getObject()->getRegistry()->setValueByPath( PREF_PortNameColor, Convert( color ) );
07295 }
07296
07297
07298
07299
07300
07301
07302
07303 ConnectionRegistryNodeImpl::ConnectionRegistryNodeImpl( ConnectionImpl* pConnection )
07304 : FCORegistryNodeImpl( pConnection )
07305 {
07306 }
07307
07308 LineType ConnectionRegistryNodeImpl::getLineType() const
07309 {
07310 LineType eType;
07311 return ( Convert( getObject()->getRegistry()->getValueByPath( PREF_LineType ), eType ) ) ? eType : LT_Solid;
07312 }
07313
07314 void ConnectionRegistryNodeImpl::setLineType( LineType eType )
07315 {
07316 getObject()->getRegistry()->setValueByPath( PREF_LineType, Convert( eType ) );
07317 }
07318
07319 LineEndType ConnectionRegistryNodeImpl::getSrcLineEndType() const
07320 {
07321 LineEndType eType;
07322 return ( Convert( getObject()->getRegistry()->getValueByPath( PREF_SrcLineEndType ), eType ) ) ? eType : LET_Butt;
07323 }
07324
07325 void ConnectionRegistryNodeImpl::setSrcLineEndType( LineEndType eType )
07326 {
07327 getObject()->getRegistry()->setValueByPath( PREF_SrcLineEndType, Convert( eType ) );
07328 }
07329
07330 LineEndType ConnectionRegistryNodeImpl::getDstLineEndType() const
07331 {
07332 LineEndType eType;
07333 return ( Convert( getObject()->getRegistry()->getValueByPath( PREF_DstLineEndType ), eType ) ) ? eType : LET_Butt;
07334 }
07335
07336 void ConnectionRegistryNodeImpl::setDstLineEndType( LineEndType eType )
07337 {
07338 getObject()->getRegistry()->setValueByPath( PREF_DstLineEndType, Convert( eType ) );
07339 }
07340
07341 std::string ConnectionRegistryNodeImpl::getLabel() const
07342 {
07343 return getObject()->getRegistry()->getValueByPath( PREF_LabelFormat );
07344 }
07345
07346 void ConnectionRegistryNodeImpl::setLabel( const std::string& strFormat )
07347 {
07348 getObject()->getRegistry()->setValueByPath( PREF_LabelFormat, strFormat );
07349 }
07350
07351 std::string ConnectionRegistryNodeImpl::getSrcLabel1() const
07352 {
07353 return getObject()->getRegistry()->getValueByPath( PREF_SrcLabel1 );
07354 }
07355
07356 void ConnectionRegistryNodeImpl::setSrcLabel1( const std::string& strFormat )
07357 {
07358 getObject()->getRegistry()->setValueByPath( PREF_SrcLabel1, strFormat );
07359 }
07360
07361 std::string ConnectionRegistryNodeImpl::getSrcLabel2() const
07362 {
07363 return getObject()->getRegistry()->getValueByPath( PREF_SrcLabel2 );
07364 }
07365
07366 void ConnectionRegistryNodeImpl::setSrcLabel2( const std::string& strFormat )
07367 {
07368 getObject()->getRegistry()->setValueByPath( PREF_SrcLabel2, strFormat );
07369 }
07370
07371 std::string ConnectionRegistryNodeImpl::getDstLabel1() const
07372 {
07373 return getObject()->getRegistry()->getValueByPath( PREF_DstLabel1 );
07374 }
07375
07376 void ConnectionRegistryNodeImpl::setDstLabel1( const std::string& strFormat )
07377 {
07378 getObject()->getRegistry()->setValueByPath( PREF_DstLabel1, strFormat );
07379 }
07380
07381 std::string ConnectionRegistryNodeImpl::getDstLabel2() const
07382 {
07383 return getObject()->getRegistry()->getValueByPath( PREF_DstLabel2 );
07384 }
07385
07386 void ConnectionRegistryNodeImpl::setDstLabel2( const std::string& strFormat )
07387 {
07388 getObject()->getRegistry()->setValueByPath( PREF_DstLabel2, strFormat );
07389 }
07390
07391 bool ConnectionRegistryNodeImpl::getConnectionAutoRoutingEnabled() const
07392 {
07393 std::string strEnabled = getObject()->getRegistry()->getValueByPath( PREF_ConnectionAutoRoutingEnabled );
07394 return ( strEnabled.empty() ) ? true : (bool) Util::Variant( strEnabled );
07395 }
07396
07397 void ConnectionRegistryNodeImpl::setConnectionAutoRoutingEnabled( bool bEnabled )
07398 {
07399 getObject()->getRegistry()->setValueByPath( PREF_ConnectionAutoRoutingEnabled, (std::string) Util::Variant( bEnabled ) );
07400 }
07401
07402 };