00001 #include "stdafx.h"
00002
00003 #include "BON.h"
00004 #include "BONImpl.h"
00005
00006 #include "ReferenceRep.h"
00007 #include "ModelRep.h"
00008 #include "Dumper.h"
00009 #include "Broker.h"
00010
00011 #include "logger.h"
00012 #include "algorithm"
00013
00014 #include "globals.h"
00015 extern Globals global_vars;
00016
00017 #include <iterator>
00018
00019 const std::string ModelRep::IsTypeInfoShown_str = "IsTypeInfoShown";
00020
00021 ModelRep::ModelRep( BON::FCO& ptr, BON::FCO& resp_ptr)
00022 : FCO( ptr, resp_ptr)
00023 , m_initialRoleMap()
00024 , m_finalRoleMap()
00025 , m_initialAspectList()
00026 , m_finalAspectList()
00027 , m_bAttrIsTypeInfoShown( true )
00028 {
00029 }
00030
00031
00032 ModelRep::~ModelRep()
00033 {
00034 m_initialRoleMap.clear();
00035 m_finalRoleMap.clear();
00036 m_initialAspectList.clear();
00037 m_finalAspectList.clear();
00038 }
00039
00040 void ModelRep::initAttributes()
00041 {
00042
00043 FCO::initAttributes();
00044
00045 bool istypeinfoshown_set = false;
00046 if( m_ptr->getAttribute( IsTypeInfoShown_str)->getStatus() >= BON::AS_Here)
00047 {
00048 m_bAttrIsTypeInfoShown = m_ptr->getAttribute( IsTypeInfoShown_str)->getBooleanValue();
00049 istypeinfoshown_set = true;
00050 }
00051
00052
00053 std::set< BON::FCO >::const_iterator it = m_equivs.begin();
00054 for ( ; it != m_equivs.end(); ++it)
00055 {
00056 if ( *it == m_ptr) continue;
00057 if ((*it)->getObjectMeta().name().find("Proxy") != std::string::npos) continue;
00058
00059 if( !istypeinfoshown_set && (*it)->getAttribute( IsTypeInfoShown_str)->getStatus() >= BON::AS_Here)
00060 {
00061 m_bAttrIsTypeInfoShown = m_bAttrIsTypeInfoShown || (*it)->getAttribute( IsTypeInfoShown_str)->getBooleanValue();
00062 istypeinfoshown_set = true;
00063 }
00064 }
00065 }
00066
00067 void ModelRep::addRole( FCO* whose, RoleSeriesValue& role)
00068 {
00069 RoleMapValue &series = m_initialRoleMap[ whose ];
00070
00071
00072
00073 RoleSeries_Iterator it = std::find( series.begin(), series.end(), role);
00074
00075 if ( it == series.end() )
00076 series.push_back( role);
00077 else
00078 global_vars.err << MSG_ERROR << "Error: Found duplicate role \"" << role.getSmartRoleName() << "\" in model \"" << m_ptr << "\"\n";
00079 }
00080
00081
00082 void ModelRep::initRoles()
00083 {
00084 RoleMap_Iterator it = m_initialRoleMap.begin();
00085 for( ; it != m_initialRoleMap.end(); ++it)
00086 {
00087 RoleMapKey fco = it->first;
00088 std::string nn = fco->getName();
00089
00090 std::vector<FCO*> children;
00091 fco->getIntDescendants( children);
00092
00093
00094
00095 int how_many_non_abstract = 0;
00096 if ( !fco->isAbstract()) ++how_many_non_abstract;
00097 for( unsigned int i = 0; i < children.size(); ++i)
00098 {
00099 std::string cn = children[i]->getName();
00100 if (! children[i]->isAbstract())
00101 ++how_many_non_abstract;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110 if ( how_many_non_abstract > 1 )
00111 {
00112 RoleMapValue &series = it->second;
00113 RoleSeries_Iterator role_it = series.begin();
00114 for(; role_it != series.end(); ++role_it)
00115 {
00116 role_it->setLongForm( true);
00117 }
00118 }
00119 }
00120 }
00121
00122
00123 bool ModelRep::getRoles( FCO * ptr, RoleMapValue& map_val) const
00124 {
00125 RoleMap_ConstIterator it = m_initialRoleMap.find( ptr);
00126 if ( it == m_initialRoleMap.end())
00127 return false;
00128
00129 map_val = it->second;
00130 return true;
00131 }
00132
00133
00134 std::vector< ModelRep* > ModelRep::getInnerModels() const
00135 {
00136 std::vector< ModelRep* > models;
00137
00138 RoleMap_ConstIterator it = m_initialRoleMap.begin();
00139 while ( it != m_initialRoleMap.end())
00140 {
00141 FCO * const ptr = it->first;
00142 if ( ptr->getMyKind() == Any::MODEL)
00143 {
00144 ModelRep * mod_ptr = dynamic_cast< ModelRep *> ( ptr);
00145 models.push_back( mod_ptr);
00146 }
00147 ++it;
00148 }
00149 return models;
00150 }
00151
00152
00153 void ModelRep::addAspect( AspectRep * asp_ptr)
00154 {
00155 std::vector<AspectRep*>::iterator ii =
00156 std::find( m_initialAspectList.begin(), m_initialAspectList.end(), asp_ptr);
00157
00158 if (ii == m_initialAspectList.end())
00159 m_initialAspectList.push_back(asp_ptr);
00160 else
00161 global_vars.err << MSG_ERROR << "CHECK: Model \"" << m_ptr << "\" has aspect \"" << asp_ptr->getPtr() << "\" associated twice\n";
00162 }
00163
00164
00165 const ModelRep::AspectRepPtrList& ModelRep::getAspectRepPtrList() const
00166 {
00167 return m_initialAspectList;
00168 }
00169
00170
00171
00172
00173
00174 void ModelRep::addFinalRole( FCO* whose, RoleSeriesValue& role)
00175 {
00176 RoleMapValue &series = m_finalRoleMap[ whose ];
00177
00178
00179
00180 RoleSeries_Iterator it = std::find( series.begin(), series.end(), role);
00181
00182 if ( it == series.end() )
00183 series.push_back( role);
00184 else
00185 global_vars.err << MSG_ERROR << "Error: Found duplicate final role \"" << role.getSmartRoleName() << "\" in model \"" << m_ptr << "\"\n";
00186 }
00187
00188 bool ModelRep::getFinalRoles( const FCO * ptr, RoleMapValue& map_val) const
00189 {
00190 RoleMap_ConstIterator it = m_finalRoleMap.find( const_cast<FCO *>( ptr));
00191 if ( it == m_finalRoleMap.end())
00192 return false;
00193
00194 map_val = it->second;
00195 return true;
00196 }
00197
00198
00199 std::vector< ModelRep* > ModelRep::getInnerModelsFinal() const
00200 {
00201 std::vector< ModelRep* > models;
00202
00203 RoleMap_ConstIterator it = m_finalRoleMap.begin();
00204 while ( it != m_finalRoleMap.end())
00205 {
00206 FCO * const ptr = it->first;
00207 if ( ptr->getMyKind() == Any::MODEL)
00208 {
00209 ModelRep * mod_ptr = dynamic_cast< ModelRep *> ( ptr);
00210 models.push_back( mod_ptr);
00211 }
00212 ++it;
00213 }
00214 return models;
00215 }
00216
00217
00218 std::vector< ReferenceRep *> ModelRep::getInnerModelReferencesFinal() const
00219 {
00220 std::vector< ReferenceRep *> refs;
00221 RoleMap_ConstIterator it = m_finalRoleMap.begin();
00222 while ( it != m_finalRoleMap.end())
00223 {
00224 FCO * const ptr = it->first;
00225 if ( ptr->getMyKind() == Any::REF)
00226 {
00227 ReferenceRep * ref_ptr = dynamic_cast< ReferenceRep *> ( ptr);
00228 if ( ref_ptr->pointsToModels())
00229 refs.push_back( ref_ptr);
00230 }
00231 ++it;
00232 }
00233 return refs;
00234 }
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 void ModelRep::inherit()
00253 {
00254 std::vector<FCO*> model_descendants;
00255 this->getImpDescendants( model_descendants);
00256 model_descendants.push_back( this);
00257
00258
00259 std::vector<FCO*>::reverse_iterator model_it = model_descendants.rbegin();
00260 for( ; model_it != model_descendants.rend(); ++model_it)
00261 {
00262 if ( (*model_it)->getMyKind() != Any::MODEL)
00263 throw std::string("Error: nonmodel kind ") + (*model_it)->getPtr()->getName() + " has model descendant " + this->getName();
00264 ModelRep * mod_desc_ptr = dynamic_cast<ModelRep*>(*model_it);
00265 if (!mod_desc_ptr) global_vars.err << MSG_ERROR << "Error: model descendant badly casted to model\n";
00266
00267 RoleMap_Iterator fco_it( m_initialRoleMap.begin());
00268
00269 for( ; fco_it != m_initialRoleMap.end(); ++fco_it)
00270 {
00271 RoleMapKey fco_ptr = fco_it->first;
00272 std::vector<FCO*> children;
00273
00274 fco_ptr->getIntDescendants( children);
00275 children.push_back( fco_ptr);
00276
00277
00278 RoleSeries &roles = fco_it->second;
00279
00280 RoleSeries_Iterator role_it = roles.begin();
00281
00282 for( ; role_it != roles.end(); ++role_it)
00283 {
00284 std::vector<FCO*>::iterator desc_it = children.begin();
00285
00286 for( ; desc_it != children.end(); ++desc_it)
00287 {
00288
00289
00290 RoleRep r(
00291 role_it->getOnlyRoleName(),
00292 *desc_it,
00293 mod_desc_ptr,
00294 role_it->isPort(),
00295 role_it->getCardinality(),
00296 mod_desc_ptr != this,
00297 role_it->isLongForm());
00298
00299 mod_desc_ptr->addFinalRole( *desc_it, r);
00300 (*desc_it)->iAmPartOfFinal( mod_desc_ptr);
00301 }
00302 }
00303 }
00304 }
00305 }
00306
00307
00308 void ModelRep::sortMyAspects()
00309 {
00310
00311 AspectCompare asp_less_than;
00312 std::sort( m_finalAspectList.begin(), m_finalAspectList.end(), asp_less_than);
00313 }
00314
00315
00316 void ModelRep::createPartsInModelAspects()
00317 {
00318 RoleMap_Iterator role_it = m_finalRoleMap.begin();
00319
00320 for( ; role_it != m_finalRoleMap.end(); ++role_it)
00321 {
00322 RoleStringLex lex;
00323 std::sort( role_it->second.begin(), role_it->second.end(), lex);
00324 std::vector<AspectRep*>::iterator asp_it = m_finalAspectList.begin();
00325
00326 for( ; asp_it != m_finalAspectList.end(); ++asp_it)
00327 {
00328
00329 RoleMapKey fco_ptr = role_it->first;
00330
00331 if ( !fco_ptr->isAbstract())
00332 {
00333 if ( (*asp_it)->findFinalFCO( fco_ptr) || (*asp_it)->isDummy())
00334 {
00335
00336 RoleSeries_Iterator jt = role_it->second.begin();
00337 for( ; jt != role_it->second.end(); ++jt)
00338 {
00339 PartRep pr( *jt, *asp_it);
00340 (*asp_it)->addPart2Map( this, pr);
00341 }
00342 }
00343 else
00344 {
00345
00346 RoleSeries_Iterator jt = role_it->second.begin();
00347 for( ; jt != role_it->second.end(); ++jt)
00348 {
00349 if ( (*asp_it)->findFinalRole( *jt))
00350 {
00351 PartRep pr( *jt, *asp_it);
00352 (*asp_it)->addPart2Map( this, pr);
00353 }
00354 }
00355 }
00356 }
00357 }
00358 }
00359 }
00360
00361
00362 const ModelRep::AspectRepPtrList& ModelRep::getFinalAspectRepPtrList() const
00363 {
00364 return m_finalAspectList;
00365 }
00366
00367
00368 void ModelRep::addFinalAspect( AspectRep * asp_ptr)
00369 {
00370 std::vector<AspectRep*>::iterator ii =
00371 std::find( m_finalAspectList.begin(), m_finalAspectList.end(), asp_ptr);
00372
00373 if (ii == m_finalAspectList.end())
00374 m_finalAspectList.push_back(asp_ptr);
00375
00376
00377 }
00378
00379
00380 void ModelRep::addFinalAspectList(const AspectRepPtrList& l)
00381 {
00382 std::vector<AspectRep*>::const_iterator ii = l.begin();
00383 for( ; ii != l.end(); ++ii)
00384 addFinalAspect(*ii);
00385 }
00386
00387
00388 int ModelRep::howManyAspects() const
00389 {
00390 return m_finalAspectList.size();
00391 }
00392
00393
00394 AspectRep * ModelRep::getFirstAspect() const
00395 {
00396
00397 unsigned int i;
00398 unsigned sel_i = -1;
00399 for( i = 0; i < m_finalAspectList.size(); ++i)
00400 {
00401 if (sel_i == -1)
00402 sel_i = 0;
00403 else
00404 {
00405 AspectRep * curr_best = m_finalAspectList[sel_i];
00406 if ( !curr_best->lessThan( *m_finalAspectList[i]))
00407 sel_i = i;
00408 }
00409 }
00410 if ( sel_i != -1) return m_finalAspectList[sel_i];
00411 else return 0;
00412 }
00413
00414
00415 bool ModelRep::findAspect( const AspectRep * one_asp) const
00416 {
00417 std::vector<AspectRep*>::const_iterator ii =
00418 std::find( m_finalAspectList.begin(), m_finalAspectList.end(), one_asp);
00419
00420 return ii != m_finalAspectList.end();
00421 }
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433 AspectRep* ModelRep::getMyFirstAspectFromSet( const std::vector<AspectRep *> & aspect_set) const
00434 {
00435 bool found = false;
00436
00437 std::vector<AspectRep *>::const_iterator aspects_it = aspect_set.begin();
00438 while( aspects_it != aspect_set.end() && !found)
00439 {
00440 std::vector<AspectRep*>::const_iterator ii =
00441 std::find( m_finalAspectList.begin(), m_finalAspectList.end(), *aspects_it);
00442
00443 found = ii != m_finalAspectList.end();
00444 if (!found) ++aspects_it;
00445 }
00446
00447 if (found)
00448 return *aspects_it;
00449 else
00450 return 0;
00451 }
00452
00453
00454
00455
00456
00457 int ModelRep::searchMyAspectsForPart( PartRep& part) const
00458 {
00459 const FCO * asp_element = part.getFCOPtr();
00460 unsigned int i = 0;
00461 int count = 0;
00462 while ( i < m_finalAspectList.size())
00463 {
00464 if ( m_finalAspectList[i]->findFinalFCO( asp_element) ||
00465 m_finalAspectList[i]->findFinalRole( *part.getRoleRepPtr()) )
00466 ++count;
00467 ++i;
00468 }
00469 return count;
00470 }
00471
00472
00473 void ModelRep::getAspectNames(CStringList &list) const
00474 {
00475 unsigned int i = 0;
00476 while ( i < m_finalAspectList.size())
00477 {
00478 list.AddTail(m_finalAspectList[i]->getName().c_str());
00479 ++i;
00480 }
00481 }
00482
00483
00484 std::string ModelRep::dumpTypeInfoShown()
00485 {
00486 std::string mmm;
00487 std::vector<FCO*> ancestors;
00488 bool typeInfoShown = m_bAttrIsTypeInfoShown;
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504 if( typeInfoShown) {
00505 mmm += indStr() + "<regnode name = \"isTypeInfoShown\" value =\"true\"></regnode>\n";
00506 }
00507 return mmm;
00508 }
00509
00510
00511 std::string ModelRep::doDump()
00512 {
00513 bool error = false;
00514 std::string m_ref = askMetaRef();
00515
00516 std::string model_name = getName();
00517 std::string mmm = indStr() + "<model name = \"" + model_name + "\" metaref = \"" + m_ref + "\"";
00518
00519 std::string dumped_attr_list = dumpAttributeList();
00520 mmm += dumped_attr_list;
00521 mmm +=" >\n";
00522 dumped_attr_list = dumpAttributeList( true);
00523 ++ind;
00524 mmm += dumpDispName();
00525 ++ind;
00526 mmm += dumpNamePosition();
00527 mmm += dumpGeneralPref();
00528
00529 mmm += dumpIcon();
00530 mmm += dumpPortIcon();
00531 mmm += dumpDecorator();
00532 mmm += dumpHotspotEnabled();
00533 mmm += dumpTypeShown();
00534 mmm += dumpTypeInfoShown();
00535 mmm += dumpSubTypeIcon();
00536 mmm += dumpInstanceIcon();
00537 mmm += dumpNameWrap();
00538 mmm += dumpNameEnabled();
00539 mmm += dumpResizable();
00540 mmm += dumpAutoRouterPref();
00541 mmm += dumpHelpURL();
00542
00543 mmm += dumpGradientFillEnabled();
00544 mmm += dumpGradientFillColor();
00545 mmm += dumpGradientFillDirection();
00546 mmm += dumpShadowCastEnabled();
00547 mmm += dumpShadowColor();
00548 mmm += dumpShadowThickness();
00549 mmm += dumpShadowDirection();
00550 mmm += dumpRoundRectangleEnabled();
00551 mmm += dumpRoundRectangleRadius();
00552 --ind;
00553 mmm += dumpConstraints();
00554 mmm += dumpAttributes();
00555
00556 std::vector<std::string> role_lines_to_dump;
00557 std::vector< RoleMapKey> key_list;
00558
00559 for( RoleMap_Iterator it = m_finalRoleMap.begin();
00560 it != m_finalRoleMap.end();
00561 ++it) {
00562 key_list.push_back( it->first);
00563 }
00564
00565 AnyLexicographicSort any_lex;
00566 std::sort( key_list.begin(), key_list.end(), any_lex);
00567
00568 for( std::vector< RoleMapKey>::iterator key_it = key_list.begin();
00569 key_it != key_list.end();
00570 ++key_it ) {
00571
00572
00573 RoleMapKey ptr = *key_it;
00574 RoleMapValue &roles = m_finalRoleMap[ ptr];
00575 RoleSeries_Iterator jt = roles.begin();
00576 for( ; jt != roles.end(); ++jt)
00577 if (!jt->getFCOPtr()->isAbstract())
00578 {
00579 const std::string &role_name = jt->getSmartRoleName();
00580 const std::string &kind_name = ptr->getName();
00581
00582 std::string m_ref = jt->getFCOPtr()->askMetaRef("/" + model_name + "/" + role_name);
00583
00584 std::string role_line = indStr() + "<role name = \"" + role_name + "\" metaref = \"" + m_ref +"\" kind = \"" + kind_name + "\"></role>\n";
00585
00586 if ( std::find(role_lines_to_dump.begin(),
00587 role_lines_to_dump.end(), role_line)
00588 != role_lines_to_dump.end())
00589 {
00590 RoleRep &r = *jt;
00591 global_vars.err << MSG_ERROR << "Duplicate role line found: " << role_line << "\n"
00592 << MSG_NORMAL
00593 << role_name << " of kind " << kind_name
00594 << " in model " << m_ptr << ". Details of the 2nd role following: "
00595 << (r.isInheritedRole()?"":"Not ") << "Inherited Role, "
00596 << (r.isLongForm()?"":"Not ") << "Long form, "
00597 << "Is " << (r.isPort()?"":"Not ") << "Port, "
00598 << "Cardinality: " << r.getCardinality() << " Not dumping twice.\n";
00599 if (!error)
00600 {
00601 TO("Please check the metamodel for duplicate roles.");
00602 error = true;
00603 }
00604 }
00605 else
00606 role_lines_to_dump.push_back( role_line);
00607 }
00608 }
00609 StringLex lex;
00610 std::sort( role_lines_to_dump.begin(), role_lines_to_dump.end(), lex);
00611
00612 std::vector<std::string>::iterator sorted_list_it = role_lines_to_dump.begin();
00613 for( ; sorted_list_it != role_lines_to_dump.end(); ++sorted_list_it)
00614 mmm += *sorted_list_it;
00615
00616 role_lines_to_dump.clear();
00617
00618
00619 {
00620 AspectCompare asp_less_than;
00621 std::sort( m_finalAspectList.begin(), m_finalAspectList.end(), asp_less_than);
00622 std::vector<AspectRep *>::iterator asp_it = m_finalAspectList.begin();
00623 for( ; asp_it != m_finalAspectList.end(); ++asp_it)
00624 {
00625 AspectRep * asp_ptr = *asp_it;
00626 std::string asp_name = asp_ptr->getName();
00627 std::string m_ref = asp_ptr->askMetaRef("/" + model_name);
00628
00629 mmm += indStr() + "<aspect name = \"" + asp_name + "\" metaref = \"" + m_ref + "\"";
00630 mmm += dumped_attr_list;
00631 mmm +=" >\n";
00632
00633 ++ind;
00634
00635 std::string asp_disp = asp_ptr->getDispName();
00636 if (!asp_disp.empty() && asp_disp != asp_name)
00637 mmm += asp_ptr->dumpDispName();
00638
00639 std::vector< std::string> part_lines_to_dump;
00640
00641 const AspectRep::PartRepSeries parts = (*asp_it)->getPartSeries( this);
00642 AspectRep::PartRepSeries_ConstIterator part_it = parts.begin();
00643 for( ; part_it != parts.end(); ++part_it)
00644 {
00645 std::string r_name = part_it->getRoleRepPtr()->getSmartRoleName();
00646
00647
00648 std::string regPath, regVal1, regVal2;
00649
00650
00651 regPath = "/PrimaryAspects/" + model_name + ":" + r_name + "/" + asp_name;
00652
00653
00654 regVal1 = part_it->getFCOPtr()->getMyRegistry()->getValueByPath(regPath);
00655
00656 std::string m_ref = part_it->getFCOPtr()->askMetaRef("/" + model_name + '/' + r_name + '/' + asp_name);
00657
00658
00659
00660 bool is_model = ( part_it->getFCOPtr()->getMyKind() == Any::MODEL);
00661
00662 bool is_ref_to_model = false;
00663 if ( part_it->getFCOPtr()->getMyKind() == Any::REF)
00664 {
00665 const ReferenceRep * ref_ptr = dynamic_cast<const ReferenceRep *>( part_it->getFCOPtr());
00666 is_ref_to_model = ref_ptr->pointsToModels();
00667 }
00668
00669 std::string is_port_str = part_it->getRoleRepPtr()->isPort()?"yes":"no";
00670 std::string primary_str = (!regVal1.empty() && regVal1=="no")?"no":"yes";
00671 std::string kind_aspect_name = "";
00672
00673 if ( is_model || is_ref_to_model)
00674 {
00675
00676 regPath = "/KindAspects/" + model_name + ":" + r_name + "/" + asp_name;
00677
00678 regVal2 = part_it->getFCOPtr()->getMyRegistry()->getValueByPath(regPath);
00679
00680 if ( regVal2 != "__GME_default_mechanism" && !regVal2.empty() && regVal2.find_first_not_of(' ') != std::string::npos)
00681 kind_aspect_name = std::string("\" kindaspect = \"") + regVal2;
00682 #if( _DEBUG)
00683 else
00684 global_vars.err << "Empty kindaspect value left out. Model: " << model_name << " Aspect: " << asp_name << " Role: " << r_name << "\n";
00685 #endif
00686 }
00687 std::string part_line = "<part metaref = \"" + m_ref + "\" role = \"" + r_name + "\" primary = \"" + primary_str + kind_aspect_name +"\" linked = \"" + is_port_str + "\"></part>";
00688
00689 if ( std::find( part_lines_to_dump.begin(), part_lines_to_dump.end(), part_line) !=
00690 part_lines_to_dump.end())
00691 {
00692 global_vars.err << MSG_ERROR << "Duplicate part found. Not dumping twice: " << part_line << "\n";
00693 if (!error)
00694 {
00695 TO("Please check the metamodel for duplicate parts.");
00696 error = true;
00697 }
00698 }
00699 else
00700 part_lines_to_dump.push_back( part_line);
00701 }
00702
00703 PartStringLex lex;
00704 std::sort( part_lines_to_dump.begin(), part_lines_to_dump.end(), lex);
00705 std::vector<std::string>::iterator part_lines_it = part_lines_to_dump.begin();
00706 for( ; part_lines_it != part_lines_to_dump.end(); ++part_lines_it)
00707 mmm += indStr() + *part_lines_it + "\n";
00708
00709 part_lines_to_dump.clear();
00710 --ind;
00711 mmm += indStr() + "</aspect>\n";
00712 }
00713 }
00714
00715 --ind;
00716 mmm += indStr() + "</model>\n";
00717 return mmm;
00718 }
00719
00720
00721 bool ModelRep::checkMyAspects( Sheet * s)
00722 {
00723 bool no = (howManyAspects() >= 1);
00724 if (!no)
00725 {
00726 if (m_finalRoleMap.size() > 0) {
00727 std::string name = m_ptr->getName();
00728 std::vector<std::string> rolenames;
00729 std::transform(m_finalRoleMap.begin(), m_finalRoleMap.end(), std::back_inserter(rolenames),
00730 [](const RoleMap::value_type& p){ return p.first->getNamespace() + "::" + p.first->getName(); });
00731 std::string children;
00732 std::for_each(m_finalRoleMap.begin(), m_finalRoleMap.end(),
00733 [&](const RoleMap::value_type& p) { children += p.first->getName() + ", "; });
00734 children = children.substr(0, children.size() - 2);
00735 global_vars.err << MSG_WARNING << "Warning: Model \"" << m_ptr << "\" has no aspect defined and may contain: " + children;
00736 }
00737 AspectRep * asp = s->createAspectRep( BON::FCO(), BON::FCO());
00738 this->addFinalAspect( asp);
00739 no = true;
00740 }
00741 return no;
00742 }
00743
00744
00745 void ModelRep::createConstraints( Sheet * s)
00746 {
00747 RoleMap_ConstIterator it = m_initialRoleMap.begin();
00748 for ( ; it != m_initialRoleMap.end(); ++it)
00749 {
00750 FCO * const ptr = it->first;
00751
00752 std::vector<FCO*> descendants;
00753 ptr->getIntDescendants( descendants);
00754
00755 RoleSeries_ConstIterator jt = it->second.begin();
00756 for( ; jt != it->second.end(); ++jt)
00757
00758 {
00759 const RoleRep & r = *jt;
00760 std::string card = jt->getCardinality();
00761 {
00762 std::string str_expr_end;
00763 std::string str_card_context;
00764 str_card_context = "[containment] In model: " + r.getModelRepPtr()->getName() + ", Role: " + r.getSmartRoleName();
00765 bool valid_constr = ! Dumper::doParseCardinality( card, "partCount", str_card_context, str_expr_end);
00766 if ( ! valid_constr )
00767 {
00768 global_vars.err << MSG_ERROR << "Ignoring invalid cardinality string in role: " << r.getSmartRoleName() << ". String: " << card << ".\n";
00769 }
00770
00771
00772
00773
00774
00775 std::string str_expr_begin =
00776 "let partCount = self.parts( \"" + r.getSmartRoleName() + "\" ) -> size ";
00777
00778 std::vector<FCO*>::iterator desc_it = descendants.begin();
00779 for( ; desc_it != descendants.end(); ++desc_it)
00780 if ( !(*desc_it)->isAbstract())
00781 str_expr_begin += "+ self.parts( \"" + (*desc_it)->getName() + r.getOnlyRoleName() + "\" ) -> size ";
00782
00783 str_expr_begin += "in\n ";
00784
00785
00786
00787 if ( valid_constr && ! str_expr_end.empty() ) {
00788
00789
00790
00791 int id = Broker::getNextConstraintId();
00792 char str_id[64];
00793 sprintf( str_id, "%d", id);
00794
00795 std::string str_cons_name;
00796 str_cons_name = "Valid" + getName() + "PartCardinality" + std::string(str_id);
00797 std::string::size_type pos = str_cons_name.find( "::");
00798 if( pos != std::string::npos)
00799 str_cons_name.replace( pos, 2, 2, '_');
00800
00801 int iEventMask = 0;
00802 char chMask[64];
00803 sprintf( chMask, "%x", iEventMask );
00804
00805 std::string str_desc;
00806 str_desc = "Multiplicity of parts, which are contained by "
00807 + getName() + ", has to match "+ card + ".";
00808
00809 ConstraintRep * cr = s->createConstraintRep( BON::FCO());
00810 std::string s_b = str_expr_begin + str_expr_end;
00811 cr->init( str_cons_name, global_vars.genConstr.reg_cont_mask, "1", global_vars.genConstr.priority, s_b, str_desc);
00812
00813 this->addInitialConstraintRep( cr);
00814 cr->attachedTo();
00815 }
00816 }
00817 }
00818 }
00819 }