00001 #include "stdafx.h"
00002 #include "BON2Component.h"
00003
00004 #include "logger.h"
00005
00006 #include "string"
00007
00008 #include "Dumper.h"
00009 #include "NameSpecDlg.h"
00010 #include "globals.h"
00011
00012 extern Globals global_vars;
00013 extern NameSpecDlg * dlg;
00014
00015 namespace BON
00016 {
00017
00018 void Component::entityBuilder( const Model& model, const Folder& parent)
00019 {
00020
00021 std::set<Set> aspects = model->getChildSets();
00022 std::set<Set>::iterator aspect = aspects.begin();
00023 for( ; aspect != aspects.end(); ++aspect)
00024 {
00025 Entity new_elem( parent, *aspect);
00026 m_entities.push_back( new_elem);
00027
00028 std::set<FCO> aspect_elements = (*aspect)->getMembers();
00029 std::set<FCO>::iterator asp_elem = aspect_elements.begin();
00030 for( ; asp_elem != aspect_elements.end(); ++asp_elem)
00031 {
00032
00033
00034
00035
00036 if ((*asp_elem)->getObjectMeta().type() == MON::OT_Atom ||
00037 (*asp_elem)->getObjectMeta().type() == MON::OT_Reference)
00038 {
00039
00040 Relation rela( Relation::ASPECT_MEMBER_OP, *aspect, *asp_elem);
00041
00042 if ( m_relations.end() == std::find( m_relations.begin(), m_relations.end(), rela))
00043 m_relations.push_back( rela);
00044 else
00045 global_vars.err << MSG_ERROR << "Internal warning: Relation ASPECT_MEMBER \"" << BON::FCO( *asp_elem) << "\" found already in relations.\n";
00046 }
00047 else if ((*asp_elem)->getObjectMeta().type() == MON::OT_Connection &&
00048 (*asp_elem)->getObjectMeta().name() == Relation::containment_str )
00049 {
00050 FCO src_fco, dst_model;
00051 Connection containment( *asp_elem);
00052 if (containment)
00053 {
00054 src_fco = FCO( containment->getSrc());
00055 dst_model = FCO( containment->getDst());
00056 }
00057
00058 Relation rela( Relation::ASPECT_MEMBER_OP, *aspect, src_fco, *asp_elem, dst_model);
00059
00060 if ( m_relations.end() == std::find( m_relations.begin(), m_relations.end(), rela))
00061 m_relations.push_back( rela);
00062 else
00063 global_vars.err << MSG_ERROR << "Internal warning: Relation ASPECT_MEMBER \"" << BON::FCO( *asp_elem) << "\" found already in relations\n";
00064 }
00065 else
00066 global_vars.err << MSG_ERROR << "Cannot handle AspectMember operation. Op1: " << BON::FCO( *aspect) << " Op2: " << BON::FCO( *asp_elem) << "\n";
00067 }
00068 }
00069
00070
00071 std::set<Connection> conns = model->getChildConnections();
00072 std::set<Connection>::iterator conn_it = conns.begin();
00073 for( ; conn_it != conns.end(); ++conn_it)
00074 {
00075 #if(0)
00076 **
00077 * in case of reference:
00078 * op1: FCO ( referred )
00079 * op2: Reference
00080 * op3: connection line
00081 *
00082 * in other cases:
00083 * op1: container
00084 * op2: element
00085 * op3: association class (in case of connector)
00086 * connection line class (in case of containment and foldercontainment)
00087 * op4: connection line class (in case of connector: source2connector)
00088 * op5: connection line class (in case of connector: connector2destination)
00089 *
00090 #endif
00091
00092 std::string conn_kind = (*conn_it)->getObjectMeta().name();
00093 if ( conn_kind == Relation::containment_str ||
00094 conn_kind == Relation::folder_containment_str ||
00095 conn_kind == Relation::set_membership_str ||
00096 conn_kind == Relation::refer_to_str ||
00097 conn_kind == Relation::has_aspect_str ||
00098 conn_kind == Relation::has_constraint_str ||
00099 conn_kind == Relation::has_attribute_str)
00100 {
00101 FCO src = FCO((*conn_it)->getSrc());
00102 FCO dst = FCO((*conn_it)->getDst());
00103
00104 Relation rela( Relation::CONTAINMENT_OP, dst, src);
00105
00106 if ( conn_kind == Relation::containment_str)
00107 {
00108 rela.setOperation( Relation::CONTAINMENT_OP);
00109 rela.setOp3( *conn_it);
00110 }
00111 else if ( conn_kind == Relation::folder_containment_str)
00112 {
00113 rela.setOperation( Relation::FOLDER_CONTAINMENT_OP);
00114 rela.setOp3( *conn_it);
00115 }
00116 else if ( conn_kind == Relation::set_membership_str)
00117 rela.setOperation( Relation::SET_MEMBER_OP);
00118 else if ( conn_kind == Relation::refer_to_str)
00119 {
00120 rela.setOperation( Relation::REFER_TO_OP);
00121 rela.setOp3( *conn_it);
00122 }
00123 else if ( conn_kind == Relation::has_aspect_str)
00124 rela.setOperation( Relation::HAS_ASPECT_OP);
00125 else if ( conn_kind == Relation::has_constraint_str)
00126 rela.setOperation( Relation::HAS_CONSTRAINT_OP);
00127 else if ( conn_kind == Relation::has_attribute_str)
00128 rela.setOperation( Relation::HAS_ATTRIBUTE_OP);
00129 else
00130 global_vars.err << MSG_ERROR << "Unknown connection kind.\n";
00131
00132 m_relations.push_back(rela);
00133 }
00134 }
00135
00136
00137 std::set<Reference> refs = model->getChildReferences();
00138 std::set<Reference>::iterator ref_it = refs.begin();
00139 for( ; ref_it != refs.end(); ++ref_it)
00140 {
00141 Entity new_elem( parent, *ref_it);
00142 m_entities.push_back( new_elem);
00143
00144 try
00145 {
00146 FCO referred = (*ref_it)->getReferred();
00147 this->m_realObj[ *ref_it] = referred;
00148 if ( referred)
00149 this->m_equivBag[ referred].insert( *ref_it);
00150 else
00151 global_vars.err << MSG_ERROR << "Null proxy object found: " << BON::FCO( *ref_it) << "\n";
00152 }
00153 catch( ... )
00154 {
00155 global_vars.err << MSG_ERROR << "Handling exeception thrown by Null proxy " << BON::FCO( *ref_it) << "\n";
00156 }
00157 }
00158
00159
00160 std::set<Atom> atoms = model->getChildAtoms();
00161 std::set<Atom>::iterator atom_it = atoms.begin();
00162 for( ; atom_it != atoms.end(); ++atom_it)
00163 {
00164 if ( (*atom_it)->getStereotype() != OT_Set)
00165 {
00166 Entity new_elem( parent, *atom_it);
00167
00168 std::string kind_name = (*atom_it)->getObjectMeta().name();
00169 if ( kind_name != Relation::connector_str.c_str() &&
00170 kind_name != Relation::inheritance_str.c_str() &&
00171 kind_name != Relation::int_inheritance_str.c_str() &&
00172 kind_name != Relation::imp_inheritance_str.c_str() &&
00173 kind_name != Relation::equivalence_str.c_str() &&
00174 kind_name != Relation::same_folder_str.c_str() &&
00175 kind_name != Relation::same_aspect_str.c_str())
00176 {
00177 m_entities.push_back( new_elem);
00178 }
00179 else if ( kind_name == Relation::connector_str)
00180 {
00181 Connection in_connection_line;
00182 Connection out_connection_line;
00183
00184 ConnectionEnd obj1, obj2, obja;
00185
00186 std::set<Connection> con_list_ptr_i = (*atom_it)->getInConnLinks( Relation::connector_src.c_str());
00187 std::set<Connection> con_list_ptr_o = (*atom_it)->getOutConnLinks( Relation::connector_dst.c_str());
00188
00189 if ( !con_list_ptr_i.empty())
00190 {
00191 in_connection_line = * con_list_ptr_i.begin();
00192 obj1 = in_connection_line->getSrc();
00193 }
00194 if ( !con_list_ptr_o.empty())
00195 {
00196 out_connection_line = * con_list_ptr_o.begin();
00197 obj2 = out_connection_line->getDst();
00198 }
00199 if ( !in_connection_line || !out_connection_line)
00200 global_vars.err << MSG_ERROR << "Connector \"" << BON::FCO( *atom_it) << "\" does not have both SourceToConnector and ConnectorToDestination connections attached.\n";
00201
00202
00203
00204
00205
00206 std::multiset<ConnectionEnd> a_out_list = (*atom_it)->getOutConnEnds( Relation::connector_descr);
00207 std::multiset<ConnectionEnd> a_in_list = (*atom_it)->getInConnEnds( Relation::connector_descr);
00208
00209 if ( !a_out_list.empty())
00210 {
00211 obja = * a_out_list.begin();
00212 }
00213 else if ( !a_in_list.empty())
00214 {
00215 obja = * a_in_list.begin();
00216 }
00217 else
00218 global_vars.err << MSG_ERROR << "Connector \"" << BON::FCO( *atom_it) << "\" has no Associated Class!\n";
00219
00220
00221
00222
00223 if ( !obj1 || !obj2 || !obja || !in_connection_line || !out_connection_line)
00224 {
00225 global_vars.err << MSG_ERROR << "Association \"" << BON::FCO( obja) << "\" disregarded.\n";
00226 }
00227 else
00228 {
00229 Relation rela(
00230 Relation::ASSOCIATION_OP,
00231 FCO( obj1),
00232 FCO( obj2),
00233 FCO( obja),
00234 in_connection_line,
00235 out_connection_line);
00236 m_relations.push_back(rela);
00237 }
00238 }
00239 else if ( kind_name == Relation::inheritance_str)
00240 {
00241 ConnectionEnd obj1, obj2;
00242 std::multiset<ConnectionEnd> in_list = (*atom_it)->getInConnEnds( Relation::inheritance_base);
00243 std::multiset<ConnectionEnd> out_list = (*atom_it)->getOutConnEnds( Relation::inheritance_derived);
00244 std::multiset<ConnectionEnd>::iterator in_it = in_list.begin();
00245 std::multiset<ConnectionEnd>::iterator out_it = out_list.begin();
00246
00247 int how_many_bases = 0;
00248 for( ; in_it != in_list.end(); ++in_it )
00249 {
00250 obj1 = * in_it;
00251 ++how_many_bases;
00252 if ( how_many_bases > 1) global_vars.err << MSG_WARNING << "Too many base classes at " << BON::FCO( *atom_it) << ". Multiple inheritance should be used with two different operators.\n";
00253 for( ; out_it != out_list.end(); ++out_it)
00254 {
00255 obj2 = * out_it;
00256
00257 Relation rela( Relation::INHERITANCE_OP, FCO( obj1), FCO( obj2));
00258 m_relations.push_back(rela);
00259 }
00260 }
00261 }
00262 else if ( kind_name == Relation::imp_inheritance_str)
00263 {
00264 ConnectionEnd obj1, obj2;
00265 std::multiset<ConnectionEnd> in_list = (*atom_it)->getInConnEnds( Relation::imp_inheritance_base);
00266 std::multiset<ConnectionEnd> out_list = (*atom_it)->getOutConnEnds( Relation::imp_inheritance_derived);
00267 std::multiset<ConnectionEnd>::iterator in_it = in_list.begin();
00268 std::multiset<ConnectionEnd>::iterator out_it = out_list.begin();
00269
00270 int how_many_bases = 0;
00271 for( ; in_it != in_list.end(); ++in_it )
00272 {
00273 obj1 = * in_it;
00274 ++how_many_bases;
00275 if ( how_many_bases > 1) global_vars.err << MSG_WARNING << "Too many base classes at " << BON::FCO( *atom_it) << ". Multiple inheritance should be used with two different operators.\n";
00276 for( ; out_it != out_list.end(); ++out_it)
00277 {
00278 obj2 = * out_it;
00279
00280 Relation rela( Relation::IMP_INHERITANCE_OP, FCO( obj1), FCO( obj2));
00281 m_relations.push_back(rela);
00282 }
00283 }
00284 }
00285 else if ( kind_name == Relation::int_inheritance_str)
00286 {
00287 ConnectionEnd obj1, obj2;
00288 std::multiset<ConnectionEnd> in_list = (*atom_it)->getInConnEnds( Relation::int_inheritance_base);
00289 std::multiset<ConnectionEnd> out_list = (*atom_it)->getOutConnEnds( Relation::int_inheritance_derived);
00290 std::multiset<ConnectionEnd>::iterator in_it = in_list.begin();
00291 std::multiset<ConnectionEnd>::iterator out_it = out_list.begin();
00292
00293 int how_many_bases = 0;
00294 for( ; in_it != in_list.end(); ++in_it )
00295 {
00296 obj1 = * in_it;
00297 ++how_many_bases;
00298 if ( how_many_bases > 1) global_vars.err << MSG_WARNING << "Too many base classes at " << BON::FCO( *atom_it) << ". Multiple inheritance should be used with two different operators.\n";
00299 for( ; out_it != out_list.end(); ++out_it)
00300 {
00301 obj2 = * out_it;
00302
00303 Relation rela( Relation::INT_INHERITANCE_OP, FCO( obj1), FCO( obj2));
00304 m_relations.push_back(rela);
00305 }
00306 }
00307 }
00308 else if ( kind_name == Relation::equivalence_str)
00309 {
00310 ConnectionEnd obj1, obj2;
00311 std::multiset<ConnectionEnd> in_list = (*atom_it)->getInConnEnds( Relation::equivalence_right);
00312 std::multiset<ConnectionEnd> out_list = (*atom_it)->getOutConnEnds( Relation::equivalence_left);
00313 std::multiset<ConnectionEnd>::iterator in_it = in_list.begin();
00314 std::multiset<ConnectionEnd>::iterator out_it = out_list.begin();
00315
00316 for( ; in_it != in_list.end(); ++in_it )
00317 {
00318 obj1 = * in_it;
00319 for( ; out_it != out_list.end(); ++out_it)
00320 {
00321 obj2 = * out_it;
00322
00323 Relation rela( Relation::EQUIVALENCE_OP, FCO( obj1), FCO( obj2), *atom_it);
00324 m_equivRelations.push_back(rela);
00325 }
00326 }
00327 }
00328 else if ( kind_name == Relation::same_aspect_str)
00329 {
00330 ConnectionEnd obj1, obj2;
00331 std::multiset<ConnectionEnd> in_list = (*atom_it)->getInConnEnds( Relation::same_aspect_right);
00332 std::multiset<ConnectionEnd> out_list = (*atom_it)->getOutConnEnds( Relation::same_aspect_left);
00333 std::multiset<ConnectionEnd>::iterator in_it = in_list.begin();
00334 std::multiset<ConnectionEnd>::iterator out_it = out_list.begin();
00335
00336 for( ; in_it != in_list.end(); ++in_it )
00337 {
00338 obj1 = * in_it;
00339 for( ; out_it != out_list.end(); ++out_it)
00340 {
00341 obj2 = * out_it;
00342
00343 Relation rela( Relation::SAME_ASPECT_OP, FCO( obj1), FCO( obj2), *atom_it);
00344 m_equivRelations.push_back(rela);
00345 }
00346 }
00347 }
00348 else if ( kind_name == Relation::same_folder_str)
00349 {
00350 ConnectionEnd obj1, obj2;
00351 std::multiset<ConnectionEnd> in_list = (*atom_it)->getInConnEnds( Relation::same_folder_right);
00352 std::multiset<ConnectionEnd> out_list = (*atom_it)->getOutConnEnds( Relation::same_folder_left);
00353 std::multiset<ConnectionEnd>::iterator in_it = in_list.begin();
00354 std::multiset<ConnectionEnd>::iterator out_it = out_list.begin();
00355
00356 for( ; in_it != in_list.end(); ++in_it )
00357 {
00358 obj1 = * in_it;
00359 for( ; out_it != out_list.end(); ++out_it)
00360 {
00361 obj2 = * out_it;
00362
00363 Relation rela( Relation::SAME_FOLDER_OP, FCO( obj1), FCO( obj2), *atom_it);
00364 m_equivRelations.push_back(rela);
00365 }
00366 }
00367 }
00368 }
00369 }
00370 }
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 void Component::selectFromSameAspectsFolders()
00381 {
00382 Relation_Iterator rel_it = m_equivRelations.begin();
00383 for( ; rel_it != m_equivRelations.end(); ++rel_it)
00384 {
00385 if ( rel_it->getOperation() == Relation::SAME_ASPECT_OP ||
00386 rel_it->getOperation() == Relation::SAME_FOLDER_OP ||
00387 rel_it->getOperation() == Relation::EQUIVALENCE_OP)
00388 {
00389 {
00390 int p1 = isProxy( rel_it->getOp1());
00391 int p2 = isProxy( rel_it->getOp2());
00392 if( p1 == 2 || p2 == 2)
00393 {
00394 global_vars.err << MSG_ERROR << rel_it->getOperationStr() << " relation disregarded between " << rel_it->getOp1() << " and " << rel_it->getOp2() << ".\n";
00395 continue;
00396 }
00397
00398 bool is_proxy_first = p1 == 1;
00399 bool is_proxy_second = p2 == 1;
00400
00401 ObjPointer selected_ptr = 0;
00402 if (is_proxy_first == is_proxy_second)
00403 selected_ptr = rel_it->getOp3();
00404 else if (is_proxy_first)
00405 selected_ptr = rel_it->getOp2();
00406 else
00407 selected_ptr = rel_it->getOp1();
00408
00409
00410
00411
00412
00413 ObjPointer to_find = is_proxy_first?m_realObj[rel_it->getOp1()]:rel_it->getOp1();
00414
00415 Entity_Iterator it( m_entities.begin());
00416 while( it != m_entities.end())
00417 {
00418 if ( to_find == it->getPointer())
00419 {
00420 it->setRespPointer( selected_ptr);
00421 }
00422 ++it;
00423 }
00424
00425 to_find = is_proxy_second?m_realObj[rel_it->getOp2()]:rel_it->getOp2();
00426 it = m_entities.begin();
00427 while( it != m_entities.end())
00428 {
00429 if ( to_find == it->getPointer())
00430 {
00431 it->setRespPointer( selected_ptr);
00432 }
00433 ++it;
00434 }
00435 }
00436 }
00437 }
00438 }
00439
00440
00441 Entity Component::entitySearch( const ObjPointer& p_ptr)
00442 {
00443 Entity_Iterator it( m_entities.begin());
00444 while ( it != m_entities.end() && p_ptr != it->getPointer())
00445 ++it;
00446
00447 if ( it == m_entities.end())
00448 return Entity( BON::Folder(), BON::FCO());
00449 else
00450 return *it;
00451 }
00452
00453
00454
00455
00456
00457
00458
00459
00460 void Component::proxyFinder()
00461 {
00462 RealMap_Iterator real_map_it = this->m_realObj.begin();
00463 for( ; real_map_it != m_realObj.end(); ++real_map_it)
00464 {
00465 ObjPointer proxy_for_sure = real_map_it->first;
00466 ObjPointer real_for_sure = real_map_it->second;
00467
00468 #ifdef _DEBUG
00469 std::string n1, n2;
00470 if ( proxy_for_sure != BON::FCO())
00471 n1 = proxy_for_sure->getName();
00472 if ( real_for_sure != BON::FCO())
00473 n2= real_for_sure->getName();
00474 #endif
00475 if ( proxy_for_sure != BON::FCO() && real_for_sure != BON::FCO())
00476 {
00477 Entity_Iterator it( m_entities.begin());
00478 while ( it != m_entities.end() && proxy_for_sure != it->getPointer())
00479 ++it;
00480
00481 if ( it == m_entities.end())
00482 {
00483 global_vars.err << MSG_ERROR << "Entity not found during proxyFinder: " << proxy_for_sure << "\n";
00484 }
00485 else
00486 {
00487 operandSearchAndReplace( proxy_for_sure, real_for_sure);
00488
00489 }
00490 }
00491 }
00492 }
00493
00494
00495 void Component::equivalenceFinder()
00496 {
00497 Relation_Iterator rel_it = m_equivRelations.begin();
00498 while ( rel_it != m_equivRelations.end())
00499 {
00500 if( rel_it->getOperation() == Relation::EQUIVALENCE_OP ||
00501 rel_it->getOperation() == Relation::SAME_FOLDER_OP ||
00502 rel_it->getOperation() == Relation::SAME_ASPECT_OP )
00503 {
00504 ObjPointer obj1 = rel_it->getOp1(), obj2 = rel_it->getOp2();
00505
00506
00507 if( obj1 != obj2)
00508 {
00509
00510 insertIntoEquivBag( obj2, obj1);
00511 operandSearchAndReplace( obj2, obj1);
00512 }
00513
00514 rel_it = m_equivRelations.erase( rel_it);
00515
00516 }
00517 else
00518 {
00519 ASSERT(0);
00520 ++rel_it;
00521 }
00522 }
00523 ASSERT( m_equivRelations.empty());
00524 }
00525
00526
00527
00528
00529
00530 void Component::insertIntoEquivBag( const ObjPointer& obj2, const ObjPointer& obj1)
00531 {
00532 if ( obj1 == obj2) return;
00533
00534 std::set< FCO > bag2;
00535
00536
00537 EquivBag_Iterator it = m_equivBag.find( obj2);
00538 if ( it != m_equivBag.end())
00539 {
00540 bag2 = m_equivBag[ obj2];
00541 m_equivBag.erase( it);
00542 }
00543
00544 m_equivBag[obj1].insert( bag2.begin(), bag2.end());
00545 m_equivBag[obj1].insert( obj1);
00546 m_equivBag[obj1].insert( obj2);
00547
00548 #ifdef _DEBUG
00549 std::string n1 = obj1->getName();
00550 std::string n2 = obj2->getName();
00551
00552 std::set< FCO > :: const_iterator ii = m_equivBag[obj1].begin();
00553 for( ; ii != m_equivBag[obj1].end(); ++ii)
00554 {
00555 n2 = (*ii)->getName();
00556 }
00557 #endif
00558
00559 }
00560
00561
00562 void Component::markEquivEntities()
00563 {
00564 EquivBag_Iterator it = m_equivBag.begin();
00565 for( ; it != m_equivBag.end(); ++it)
00566 {
00567 ASSERT( !it->first->isDeleted());
00568 std::set< ObjPointer > & clique = it->second;
00569 std::set< ObjPointer > :: const_iterator jt = clique.begin();
00570
00571
00572 for( ; jt != clique.end(); ++jt)
00573 {
00574
00575 if ( *jt != it->first)
00576 {
00577 Entity_Iterator kt( m_entities.begin());
00578 while ( kt != m_entities.end() && *jt != kt->getPointer())
00579 ++kt;
00580
00581 if ( kt != m_entities.end())
00582 {
00583 kt->deleted( true);
00584 }
00585 else
00586 {
00587 global_vars.err << MSG_ERROR << "Entity not found during markEquivEntities: " << BON::FCO( *jt) << "\n";
00588 }
00589 }
00590 }
00591 }
00592 }
00593
00594
00595
00596
00597
00598
00599
00600
00601 void Component::operandSearchAndReplace( const std::vector<ObjPointer>& find_obj_vec, const ObjPointer& real_obj)
00602 {
00603 const static int len = 2;
00604 Relations* reldb[ len] = { &m_relations, &m_equivRelations};
00605 for ( int k = 0; k < len; ++k)
00606 {
00607 Relation_Iterator rel_it = reldb[k]->begin();
00608 for( ; rel_it != reldb[k]->end(); ++rel_it)
00609 {
00610 if (!rel_it->getOp1()) global_vars.err << MSG_ERROR << "First operand is Null Pointer\n";
00611 if (!rel_it->getOp2()) global_vars.err << MSG_ERROR << "Second operand is Null Pointer\n";
00612
00613 ObjPointer obj = BON::FCO(); obj = rel_it->getOp1();
00614
00615 if ( std::find( find_obj_vec.begin(), find_obj_vec.end(), obj) != find_obj_vec.end())
00616 rel_it->setOp1( real_obj);
00617
00618 obj = BON::FCO(); obj = rel_it->getOp2();
00619
00620 if ( std::find( find_obj_vec.begin(), find_obj_vec.end(), obj) != find_obj_vec.end())
00621 rel_it->setOp2( real_obj);
00622
00623
00624 obj = BON::FCO(); obj = rel_it->getOp3();
00625
00626 if ( obj != BON::FCO() && std::find( find_obj_vec.begin(), find_obj_vec.end(), obj) != find_obj_vec.end())
00627 rel_it->setOp3( real_obj);
00628
00629
00630 obj = BON::FCO(); obj = rel_it->getOp4();
00631
00632 if ( obj != BON::FCO() && std::find( find_obj_vec.begin(), find_obj_vec.end(), obj) != find_obj_vec.end())
00633 rel_it->setOp4(real_obj);
00634
00635 obj = BON::FCO(); obj = rel_it->getOp5();
00636
00637 if ( obj != BON::FCO() && std::find( find_obj_vec.begin(), find_obj_vec.end(), obj) != find_obj_vec.end())
00638 rel_it->setOp5(real_obj);
00639 }
00640 }
00641 }
00642
00643
00644 void Component::operandSearchAndReplace( const ObjPointer& find_obj, const ObjPointer& real_obj)
00645 {
00646 operandSearchAndReplace( std::vector< ObjPointer>( 1, find_obj), real_obj);
00647 }
00648
00649
00650 void Component::removeProxiesAndEquiv()
00651 {
00652 markEquivEntities();
00653 }
00654
00655
00656 bool Component::nameSelector()
00657 {
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673 bool res = true;
00674
00675 dlg = new NameSpecDlg();
00676
00677 Entity_Iterator it_1( m_entities.begin());
00678 for( ; it_1 != m_entities.end(); ++it_1 )
00679 {
00680 if( it_1->isDeleted()) continue;
00681
00682 FCO fco( it_1->getPointer());
00683 FCO resp( it_1->getRespPointer());
00684
00685 EquivBag_Iterator it_2 = m_equivBag.find( fco);
00686 if( it_2 == m_equivBag.end())
00687 continue;
00688
00689 if( !resp)
00690 resp = fco;
00691
00692
00693
00694
00695 std::string defname = resp->getName();
00696 std::string defdispname = "";
00697 std::string regname, regdispname;
00698
00699
00700 if( fco->getObjectMeta().name() == "Aspect")
00701 {
00702 regname = AspectRep::getMyRegistry( fco, it_1->getParentFolder())->getValueByPath( "/" + Any::NameSelectorNode_str);
00703 regdispname = AspectRep::getMyRegistry( fco, it_1->getParentFolder())->getValueByPath( "/" + Any::DisplayedNameSelectorNode_str);
00704 }
00705 else
00706 {
00707 regname = Any::getMyRegistry( fco, it_1->getParentFolder())->getValueByPath( "/" + Any::NameSelectorNode_str);
00708 regdispname = Any::getMyRegistry( fco, it_1->getParentFolder())->getValueByPath( "/" + Any::DisplayedNameSelectorNode_str);
00709 }
00710
00711
00712 bool is_any_alternative = false;
00713 bool is_def_among_names = false;
00714 bool is_reg_among_names = false;
00715 std::string anyDispName;
00716 std::set < ObjPointer >::iterator jt = it_2->second.begin();
00717 for( ; jt != it_2->second.end(); ++jt)
00718 {
00719 if( !isProxy( *jt))
00720 {
00721 std::string eqname = (*jt)->getName();
00722
00723 if( eqname == defname)
00724 is_def_among_names = true;
00725 else
00726 is_any_alternative = true;
00727
00728 if( eqname == regname)
00729 is_reg_among_names = true;
00730
00731 std::string tmpDispName = (*jt)->getAttribute( Any::DisplayedName_str)->getStringValue();
00732 if (tmpDispName != "")
00733 {
00734 if (anyDispName != "" && anyDispName != tmpDispName)
00735 {
00736 is_any_alternative = true;
00737 }
00738 anyDispName = tmpDispName;
00739 }
00740 }
00741 }
00742
00743 if( is_any_alternative)
00744 {
00745 CString dd = defname.c_str();
00746 CString kind = fco->getObjectMeta().name().c_str();
00747
00748 if( is_reg_among_names)
00749 dlg->m_dn[ fco] = make_pair( regname, regdispname);
00750 else
00751 dlg->m_dn[ fco] = make_pair( defname, defdispname);
00752
00753 if( !is_def_among_names)
00754 {
00755 dlg->m_map[ fco].insert( resp);
00756 }
00757
00758
00759 jt = it_2->second.begin();
00760 for( ; jt != it_2->second.end(); ++jt)
00761 {
00762 if( !isProxy( *jt))
00763 {
00764 dlg->m_map[ fco].insert( *jt);
00765 }
00766 }
00767 }
00768 else if (is_def_among_names)
00769 {
00770 it_1->setDispName(anyDispName);
00771 }
00772 }
00773
00774 if( global_vars.silent_mode)
00775 {
00776 res = true;
00777 dlg->m_result = dlg->m_dn;
00778 }
00779 else
00780 {
00781 res = false;
00782 if( !dlg->m_dn.empty()) res = dlg->DoModal() == IDOK;
00783 }
00784
00785 if( res)
00786 {
00787 NameSpecDlg::DEFNAMES_MAP::iterator it_0 = dlg->m_result.begin();
00788 for( ; it_0 != dlg->m_result.end(); ++it_0)
00789 {
00790 BON::FCO key_fco = it_0->first;
00791 std::string newsel_name = it_0->second.first;
00792 std::string newsel_dispname = it_0->second.second;
00793
00794 bool found = false;
00795 Entity_Iterator it_1( m_entities.begin());
00796 for( ; !found && it_1 != m_entities.end(); ++it_1 )
00797 {
00798 if( it_1->isDeleted()) continue;
00799
00800 if( it_1->getPointer() == key_fco)
00801 {
00802 found = true;
00803
00804
00805 BON::FCO newsel_resp;
00806
00807
00808 EquivBag_Iterator it_2 = m_equivBag.find( key_fco);
00809 if( it_2 != m_equivBag.end())
00810 {
00811
00812 std::set < ObjPointer >::iterator it_3 = it_2->second.begin();
00813 for( ; !newsel_resp && it_3 != it_2->second.end(); ++it_3)
00814 {
00815 if( !isProxy( *it_3))
00816 {
00817 std::string eqname = (*it_3)->getName();
00818
00819 if( eqname == newsel_name)
00820 newsel_resp = *it_3;
00821 }
00822 }
00823 }
00824 else
00825 {
00826 ASSERT( 0 );
00827 continue;
00828 }
00829
00830
00831
00832
00833
00834
00835
00836 if( newsel_resp)
00837 {
00838 it_1->setRespPointer( newsel_resp);
00839 }
00840
00841
00842 it_1->setDispName( newsel_dispname);
00843
00844
00845 if( key_fco->getObjectMeta().name() == "Aspect")
00846 {
00847 AspectRep::getMyRegistry( key_fco, it_1->getParentFolder())->setValueByPath( "/" + Any::NameSelectorNode_str, newsel_name);
00848 AspectRep::getMyRegistry( key_fco, it_1->getParentFolder())->setValueByPath( "/" + Any::DisplayedNameSelectorNode_str, newsel_dispname);
00849 }
00850 else
00851 {
00852 Any::getMyRegistry( key_fco, it_1->getParentFolder())->setValueByPath( "/" + Any::NameSelectorNode_str, newsel_name);
00853 Any::getMyRegistry( key_fco, it_1->getParentFolder())->setValueByPath( "/" + Any::DisplayedNameSelectorNode_str, newsel_dispname);
00854 }
00855 }
00856 }
00857 if( !found)
00858 {
00859 ASSERT( 0 );
00860 }
00861 }
00862 }
00863
00864 delete dlg;
00865 return res;
00866 }
00867
00868
00869 int Component::isProxy( const ObjPointer& ptr)
00870 {
00871 if( ptr == BON::FCO()) return 0;
00872 RealMap_Iterator it = m_realObj.find( ptr);
00873 if( it != m_realObj.end() && it->second != BON::FCO()) return 1;
00874 if( ptr->getObjectMeta().name().find("Proxy") != std::string::npos) return 2;
00875
00876 return 0;
00877 }
00878
00879
00880 bool Component::checkForProxies()
00881 {
00882 std::vector< ObjPointer> to_delete;
00883 bool correct = true;
00884 Entity_Iterator it(m_entities.begin());
00885 for( ; it != m_entities.end(); ++it)
00886 {
00887 if ( it->isDeleted()) continue;
00888
00889 int res;
00890 if ( res = isProxy( it->getPointer()))
00891 {
00892 if ( res == 1)
00893 global_vars.err << MSG_ERROR << "Internal error: entity " << it->getPointer() << " is a proxy.";
00894 else if ( res == 2)
00895 global_vars.err << MSG_ERROR << "Entity " << it->getPointer() << " is a NULL proxy.";
00896
00897
00898 global_vars.err << " Disregarding it from the Paradigm sheet.\n";
00899 correct = false;
00900 to_delete.push_back( it->getPointer());
00901 }
00902 }
00903
00904 unsigned int c = to_delete.size();
00905 Relation_Iterator rel_it = m_relations.begin();
00906 for( ; rel_it != m_relations.end(); ++rel_it)
00907 {
00908 if ( isProxy( rel_it->getOp1()))
00909 to_delete.push_back( rel_it->getOp1());
00910
00911 if ( isProxy( rel_it->getOp2()))
00912 to_delete.push_back( rel_it->getOp2());
00913
00914 if ( isProxy( rel_it->getOp3()))
00915 to_delete.push_back( rel_it->getOp3());
00916
00917 if ( isProxy( rel_it->getOp4()))
00918 to_delete.push_back( rel_it->getOp4());
00919
00920 if ( isProxy( rel_it->getOp5()))
00921 to_delete.push_back( rel_it->getOp5());
00922 }
00923
00924 rel_it = m_equivRelations.begin();
00925 for( ; rel_it != m_equivRelations.end(); ++rel_it)
00926 {
00927 if ( isProxy( rel_it->getOp1()))
00928 to_delete.push_back( rel_it->getOp1());
00929
00930 if ( isProxy( rel_it->getOp2()))
00931 to_delete.push_back( rel_it->getOp2());
00932
00933 if ( isProxy( rel_it->getOp3()))
00934 to_delete.push_back( rel_it->getOp3());
00935
00936 if ( isProxy( rel_it->getOp4()))
00937 to_delete.push_back( rel_it->getOp4());
00938
00939 if ( isProxy( rel_it->getOp5()))
00940 to_delete.push_back( rel_it->getOp5());
00941 }
00942
00943 if ( c != to_delete.size()) correct = false;
00944
00945 std::vector< ObjPointer>::iterator ee = to_delete.begin();
00946 for( ; ee != to_delete.end(); ++ee)
00947 {
00948 Entity_Iterator ent_it = m_entities.begin();
00949 while( ent_it != m_entities.end())
00950 {
00951 if (*ee != ent_it->getPointer())
00952 ++ent_it;
00953 else
00954 ent_it = m_entities.erase( ent_it);
00955 }
00956
00957 Relation_Iterator rel_it = m_relations.begin();
00958 while( rel_it != m_relations.end())
00959 {
00960 if ( rel_it->getOp1() != *ee &&
00961 rel_it->getOp2() != *ee &&
00962 rel_it->getOp3() != *ee &&
00963 rel_it->getOp4() != *ee &&
00964 rel_it->getOp5() != *ee )
00965 ++rel_it;
00966 else
00967 rel_it = m_relations.erase( rel_it);
00968 }
00969 rel_it = m_equivRelations.begin();
00970 while( rel_it != m_equivRelations.end())
00971 {
00972 if ( rel_it->getOp1() != *ee &&
00973 rel_it->getOp2() != *ee &&
00974 rel_it->getOp3() != *ee &&
00975 rel_it->getOp4() != *ee &&
00976 rel_it->getOp5() != *ee )
00977 ++rel_it;
00978 else
00979 rel_it = m_equivRelations.erase( rel_it);
00980 }
00981 }
00982 if( !correct)
00983 global_vars.err << MSG_ERROR << "Some objects/relations disregarded by the Proxy Checker.\n";
00984
00985 return correct;
00986 }
00987
00988
00989 void Component::inheritancesManager( Relation & rel_it)
00990 {
00991 Relation::OPER_TYPE relation[ ::FCO::NUMBER_OF_INHERITANCES ] = {
00992 Relation::INHERITANCE_OP,
00993 Relation::INT_INHERITANCE_OP,
00994 Relation::IMP_INHERITANCE_OP
00995 };
00996
00997 ::FCO::INHERITANCE_TYPE new_relation[ ::FCO::NUMBER_OF_INHERITANCES ] = {
00998 ::FCO::REGULAR,
00999 ::FCO::INTERFACE,
01000 ::FCO::IMPLEMENTATION
01001 };
01002
01003 int inh_type;
01004 for( inh_type = 0; inh_type != ::FCO::NUMBER_OF_INHERITANCES; ++inh_type )
01005 {
01006 if ( rel_it.getOperation() == relation[inh_type] )
01007 {
01008 ObjPointer obj1 = rel_it.getOp1();
01009 ObjPointer obj2 = rel_it.getOp2();
01010
01011 ::FCO* base = m_sheet->findFCO( rel_it.getOp1());
01012 ::FCO* derived = m_sheet->findFCO( rel_it.getOp2());
01013 if ( base != 0 && derived != 0)
01014 {
01015 base->addChild( new_relation[inh_type], derived);
01016 derived->addParent( new_relation[inh_type], base);
01017 }
01018 else
01019 {
01020 if ( base == 0 )
01021 global_vars.err << MSG_ERROR << "No base peer present in inheritance relation: " << obj1 << " <|---- " << obj2 << "\n";
01022 if ( derived == 0 )
01023 global_vars.err << MSG_ERROR << "No derived peer present in inheritance relation: " << obj1 << " <|---- " << obj2 << "\n";
01024 }
01025 }
01026 }
01027 }
01028
01029
01030 void Component::associationClassManager( Relation & rel_it)
01031 {
01032 if ( rel_it.getOperation() == Relation::ASSOCIATION_OP )
01033 {
01034 ObjPointer obj1 = rel_it.getOp1();
01035 ObjPointer obj2 = rel_it.getOp2();
01036 ObjPointer obj3 = rel_it.getOp3();
01037
01038
01039 BON::Connection obj4( rel_it.getOp4());
01040 BON::Connection obj5( rel_it.getOp5());
01041
01042 ::FCO* op1 = m_sheet->findFCO( rel_it.getOp1());
01043 ::FCO* op2 = m_sheet->findFCO( rel_it.getOp2());
01044 ::FCO* op3 = m_sheet->findFCO( rel_it.getOp3());
01045
01046 if ( op1 != 0 && op2 != 0 && op3 != 0)
01047 {
01048
01049 std::string src_role = "src", dst_role = "dst";
01050 std::string src_card = "0..*", dst_card = "0..*";
01051
01052 src_card = obj4->getAttribute( "Cardinality")->getStringValue();
01053 dst_card = obj5->getAttribute( "Cardinality")->getStringValue();
01054
01055 src_role = obj4->getAttribute( "srcRolename")->getStringValue();
01056 if ( src_role != "" && src_role != "src")
01057 global_vars.err << MSG_ERROR << "Incorrect Rolename attribute: <" << src_role << "> of " << obj4 << "\n";
01058
01059 dst_role = obj5->getAttribute( "dstRolename")->getStringValue();
01060 if ( dst_role != "" && dst_role != "dst")
01061 global_vars.err << MSG_ERROR << "Incorrect Rolename attribute: <" << dst_role << "> of " << obj5 << "\n";
01062
01063
01064 ConnJoint::SDList list_op1, list_op2;
01065 list_op1.push_back( op1);
01066 list_op2.push_back( op2);
01067
01068 if ( op3->getMyKind() != Any::CONN ) global_vars.err << MSG_ERROR << "How can happen that the association class is Not a Connection.\n";
01069 ConnectionRep * conn_obj = dynamic_cast< ConnectionRep * > ( op3 );
01070
01071 ConnJoint assoc( conn_obj,
01072 list_op1, list_op2, src_role == dst_role,
01073 src_card, dst_card);
01074
01075 if (conn_obj) conn_obj->addJoint( assoc );
01076 else global_vars.err << MSG_ERROR << "After dynamic_cast - conn" << obj3 << "\n";
01077 }
01078 else if ( obj3 == BON::FCO() )
01079 global_vars.err << MSG_ERROR << "Association relation is not complete. Association class missing. Op1: " << obj1 << " Op2: " << obj2 << "\n";
01080 else
01081 global_vars.err << MSG_ERROR << "Association relation is not complete. Some part missing. Op1: " << obj1 << " Op2: " << obj2 << " Association class: " << obj3 << "\n";
01082 }
01083 }
01084
01085
01086 void Component::setMemberManager( Relation & rel_it)
01087 {
01088 if ( rel_it.getOperation() == Relation::SET_MEMBER_OP )
01089 {
01090 ObjPointer obj1 = rel_it.getOp1();
01091 ObjPointer obj2 = rel_it.getOp2();
01092
01093 ::FCO* set = m_sheet->findFCO( rel_it.getOp1());
01094 ::FCO* member = m_sheet->findFCO( rel_it.getOp2());
01095 if ( set != 0 && member != 0)
01096 {
01097 if ( set->getMyKind() != Any::SET ) global_vars.err << MSG_ERROR << "Internal error: Not a set on left hand side of set_member relation\n";
01098 SetRep * set_obj = dynamic_cast< SetRep * > ( set );
01099 if (set_obj) set_obj->addMember( member);
01100 else global_vars.err << MSG_ERROR << "Internal error: After dynamic_cast - set" << obj1 << "\n";
01101
01102 }
01103 else
01104 {
01105 if ( set == 0 )
01106 global_vars.err << MSG_ERROR << "No set peer present in set_member relation. " << obj1 << " missing.\n";
01107 if ( member == 0 )
01108 global_vars.err << MSG_ERROR << "No member peer present in set_member relation. " << obj2 << " missing.\n";
01109 }
01110 }
01111 }
01112
01113
01114 void Component::refersToManager( Relation & rel_it)
01115 {
01116 if ( rel_it.getOperation() == Relation::REFER_TO_OP )
01117 {
01118 ObjPointer obj1 = rel_it.getOp1();
01119 ObjPointer obj2 = rel_it.getOp2();
01120 BON::Connection obj3( rel_it.getOp3());
01121
01122 ::FCO* elem = m_sheet->findFCO( rel_it.getOp1());
01123 ::FCO* ref = m_sheet->findFCO( rel_it.getOp2());
01124 if ( elem != 0 && ref != 0)
01125 {
01126 ReferenceRep * ref_obj = dynamic_cast<ReferenceRep *>( ref);
01127 if ( !ref_obj || ref->getMyKind() != Any::REF)
01128 global_vars.err << MSG_ERROR << "Not reference " << obj1 << " referring\n";
01129 else
01130 ref_obj->addInitialReferee( elem);
01131 bool show_ports = obj3->getAttribute("ShowPorts")->getBooleanValue();
01132 ref_obj->setShowPorts(show_ports);
01133 elem->addRefersToMe( ref_obj);
01134 }
01135 else
01136 {
01137 if ( elem == 0 )
01138 global_vars.err << MSG_ERROR << "No referee peer present in RefersTo relation. " << obj1 << " missing.\n";
01139 if ( ref == 0 )
01140 global_vars.err << MSG_ERROR << "No reference peer present in RefersTo relation. " << obj2 << " missing.\n";
01141 }
01142 }
01143 }
01144
01145
01146 void Component::containmentManager( Relation & rel_it)
01147 {
01148 if ( rel_it.getOperation() == Relation::CONTAINMENT_OP )
01149 {
01150 ObjPointer obj1 = rel_it.getOp1();
01151 ObjPointer obj2 = rel_it.getOp2();
01152 BON::Connection obj3( rel_it.getOp3());
01153
01154 ::FCO* model = m_sheet->findFCO( rel_it.getOp1());
01155 ::FCO* fco = m_sheet->findFCO( rel_it.getOp2());
01156
01157 if ( model != 0 && fco != 0)
01158 {
01159 ModelRep * model_obj = dynamic_cast< ModelRep * > ( model);
01160 if (!model_obj || model->getMyKind() != Any::MODEL)
01161 global_vars.err << MSG_ERROR << "ERROR: after dynamic_cast - containment - model is 0 / Not model " << obj1 << " contains an FCO\n";
01162
01163 if ( !obj3)
01164 global_vars.err << MSG_ERROR << "ERROR: Null containment line class - containmentManager\n";
01165
01166 bool is_a_port = obj3->getAttribute("IsPort")->getBooleanValue();
01167 std::string comp_role = obj3->getAttribute("Rolename")->getStringValue();
01168 std::string card = obj3->getAttribute("Cardinality")->getStringValue();
01169
01170 RoleRep role(
01171 comp_role,
01172 fco,
01173 model_obj,
01174 is_a_port,
01175 card,
01176 false,
01177 false);
01178
01179
01180
01181 model_obj->addRole( fco, role);
01182
01183 }
01184 else
01185 {
01186 if ( model == 0 )
01187 global_vars.err << MSG_ERROR << "No model peer present in containment relation. " << obj1 << " missing.\n";
01188 if ( fco == 0 )
01189 global_vars.err << MSG_ERROR << "No fco peer present in containment relation. " << obj2 << " missing.\n";
01190 }
01191 }
01192 }
01193
01194
01195 void Component::folderContainmentManager( Relation & rel_it)
01196 {
01197 if ( rel_it.getOperation() == Relation::FOLDER_CONTAINMENT_OP )
01198 {
01199 ObjPointer obj1 = rel_it.getOp1();
01200 ObjPointer obj2 = rel_it.getOp2();
01201 BON::Connection obj3( rel_it.getOp3());
01202
01203 Any* folder = m_sheet->findAny( rel_it.getOp1());
01204 Any* any = m_sheet->findAny( rel_it.getOp2());
01205 if ( folder != 0 && any != 0)
01206 {
01207 if ( folder->getMyKind() != Any::FOLDER ) global_vars.err << MSG_ERROR << "Not a folder " << obj1 << " contains an FCO\n";
01208
01209 FolderRep * folder_obj = dynamic_cast< FolderRep * > ( folder );
01210 if (!folder_obj) global_vars.err << MSG_ERROR << "ERROR after dynamic_cast - folder_containment - folder " << obj1 << " is 0\n";
01211
01212 std::string card = "0..*";
01213
01214 if ( any->getMyKind() != Any::FOLDER)
01215 {
01216 ::FCO * fco = dynamic_cast< ::FCO *>( any);
01217 if ( !fco) global_vars.err << MSG_ERROR << "ERROR after dynamic cast - folder containment - fco " << obj2 << " is 0\n";
01218 else folder_obj->addFCO( fco, card);
01219 }
01220 else
01221 {
01222 FolderRep * sub_f = dynamic_cast< FolderRep *>( any);
01223 if ( !sub_f) global_vars.err << MSG_ERROR << "ERROR after dynamic cast - folder containment - subfolder " << obj2 << " is 0\n";
01224 else folder_obj->addSubFolderRep( sub_f, card);
01225 }
01226 }
01227 else
01228 {
01229 if ( folder == 0 )
01230 global_vars.err << MSG_ERROR << "No folder peer present in folder_containment relation. " << obj1 << " missing.\n";
01231 if ( any == 0 )
01232 global_vars.err << MSG_ERROR << "No element peer present in folder_containment relation. " << obj2 << " missing.\n";
01233 }
01234 }
01235 }
01236
01237
01238 void Component::hasAspectManager( Relation & rel_it)
01239 {
01240 if ( rel_it.getOperation() == Relation::HAS_ASPECT_OP )
01241 {
01242 ObjPointer obj1 = rel_it.getOp1();
01243 ObjPointer obj2 = rel_it.getOp2();
01244
01245 ::FCO* model = m_sheet->findFCO( rel_it.getOp1());
01246 Any* aspect = m_sheet->findAny( rel_it.getOp2());
01247 if ( model != 0 && aspect != 0)
01248 {
01249 ModelRep * model_obj = dynamic_cast< ModelRep * > ( model );
01250 AspectRep * aspect_obj = dynamic_cast< AspectRep * > ( aspect );
01251 if (!aspect_obj)
01252 global_vars.err << MSG_ERROR << "ERROR after dynamic_cast - has aspect - aspect " << obj2 << " is 0\n";
01253 if (!model_obj || !aspect_obj || model->getMyKind() != Any::MODEL )
01254 global_vars.err << MSG_ERROR << "ERROR after dynamic_cast " << (aspect_obj?"aspect is 0":(model_obj?"model is 0":"wrong kind")) << "\n";
01255 else
01256 model_obj->addAspect( aspect_obj);
01257 }
01258 else
01259 {
01260 if ( model == 0 )
01261 global_vars.err << MSG_ERROR << "No model peer present in has_aspect relation. " << obj1 << " missing.\n";
01262 if ( aspect == 0 )
01263 global_vars.err << MSG_ERROR << "No aspect peer present in has_aspect relation. " << obj2 << " missing.\n";
01264 }
01265 }
01266 }
01267
01268
01269 void Component::aspectMemberManager( Relation & rel_it)
01270 {
01271 if ( rel_it.getOperation() == Relation::ASPECT_MEMBER_OP )
01272 {
01273 ObjPointer obj1 = rel_it.getOp1();
01274 ObjPointer obj2 = rel_it.getOp2();
01275
01276 Any* aspect = m_sheet->findAny( rel_it.getOp1());
01277 ::FCO* member = m_sheet->findFCO( rel_it.getOp2());
01278 if ( aspect != 0 && member != 0)
01279 {
01280 if ( aspect->getMyKind() != Any::ASPECT ) global_vars.err << MSG_ERROR << "Not an aspect " << obj1 << "\n";
01281
01282 AspectRep * aspect_obj = dynamic_cast< AspectRep * > ( aspect );
01283 if ( !aspect_obj) global_vars.err << MSG_ERROR << "ERROR after dynamic_cast - aspect member - aspect " << obj1 << " is 0\n";
01284
01285 if ( rel_it.getOp3() != BON::FCO() &&
01286 rel_it.getOp4() != BON::FCO())
01287 {
01288 std::string rolename = Connection( rel_it.getOp3())->getAttribute("Rolename")->getStringValue();
01289 bool is_a_port = Connection( rel_it.getOp3())->getAttribute("IsPort")->getBooleanValue();
01290 std::string card = Connection( rel_it.getOp3())->getAttribute("Cardinality")->getStringValue();
01291
01292 ModelRep * model = dynamic_cast<ModelRep*>( m_sheet->findFCO( rel_it.getOp4()));
01293 if ( model != 0)
01294 {
01295 RoleRep role(
01296 rolename,
01297 member,
01298 model,
01299 is_a_port,
01300 card,
01301 false,
01302 false);
01303
01304 aspect_obj->addRRole( role);
01305 }
01306 else
01307 global_vars.err << MSG_ERROR << "Interal error: No model present in aspect_member relation. " << rel_it.getOp4() << " missing.\n";
01308 }
01309 else
01310 aspect_obj->addFCO( member);
01311 }
01312 else
01313 {
01314 if ( aspect == 0 )
01315 global_vars.err << MSG_ERROR << "No aspect peer present in aspect_member relation. " << obj1 << " missing.\n";
01316 if ( member == 0 )
01317 global_vars.err << MSG_ERROR << "No member peer present in aspect_member relation. " << obj2 << " missing.\n";
01318 }
01319 }
01320 }
01321
01322
01323 void Component::hasConstraintManager( Relation & rel_it)
01324 {
01325 if ( rel_it.getOperation() == Relation::HAS_CONSTRAINT_OP )
01326 {
01327 ObjPointer obj1 = rel_it.getOp1();
01328 ObjPointer obj2 = rel_it.getOp2();
01329
01330 Any* any = m_sheet->findAny( rel_it.getOp1());
01331 Any* constraint = m_sheet->findAny( rel_it.getOp2());
01332 if ( any != 0 && constraint != 0)
01333 {
01334 ConstraintRep *constraint_obj = dynamic_cast< ConstraintRep * >(constraint);
01335 if (any && (any->isFCO() || any->getMyKind() == Any::FOLDER))
01336 {
01337 any->addInitialConstraintRep( constraint_obj);
01338 constraint_obj->attachedTo();
01339 }
01340 else
01341 global_vars.err << MSG_ERROR << obj2 << " constraint is owned by " << obj1 << " which is neither FCO nor Folder\n";
01342 }
01343 else
01344 {
01345 if ( any == 0 )
01346 global_vars.err << MSG_ERROR << "No owner (FCO or Folder) peer present in has_constraint relation. " << obj1 << " missing.\n";
01347 if ( constraint == 0 )
01348 global_vars.err << MSG_ERROR << "No Constraint peer present in has_constraint relation. " << obj2 << " missing.\n";
01349 }
01350 }
01351 }
01352
01353
01354 void Component::hasAttributeManager( Relation & rel_it)
01355 {
01356 if ( rel_it.getOperation() == Relation::HAS_ATTRIBUTE_OP )
01357 {
01358 ObjPointer obj1 = rel_it.getOp1();
01359 ObjPointer obj2 = rel_it.getOp2();
01360
01361 ::FCO* fco = m_sheet->findFCO( rel_it.getOp1());
01362 Any* attr = m_sheet->findAny( rel_it.getOp2());
01363 if ( fco != 0 && attr != 0)
01364 {
01365 AttributeRep * attr_obj = dynamic_cast< AttributeRep *>( attr);
01366 fco->addInitialAttribute( attr_obj);
01367 if ( !attr_obj->isGlobal())
01368 attr_obj->addOwner( fco);
01369 }
01370 else
01371 {
01372 if ( fco == 0 )
01373 global_vars.err << MSG_ERROR << "No fco peer present in has_attribute relation. " << obj1 << " missing.\n";
01374 if ( attr == 0 )
01375 global_vars.err << MSG_ERROR << "No attribute peer present in has_attribute relation. " << obj2 << " missing.\n";
01376 }
01377 }
01378 }
01379
01380
01385 void Component::CHECK()
01386 {
01387 #ifdef _DEBUG
01388 Relation_Iterator rel_it = m_relations.begin();
01389
01390 for( ; rel_it != m_relations.end(); ++rel_it)
01391 {
01392 if (rel_it->getOperation() == Relation::ASSOCIATION_OP)
01393 {
01394 bool three_op = rel_it->getOp3() != BON::FCO();
01395 if( rel_it->getOp1() == BON::FCO() ||
01396 rel_it->getOp2() == BON::FCO() ||
01397 rel_it->getOp3() == BON::FCO() ||
01398 rel_it->getOp4() == BON::FCO() ||
01399 rel_it->getOp5() == BON::FCO() )
01400 global_vars.err << MSG_ERROR << "Internal error: Assocation has one operand 0\n";
01401 Entity ent1 = entitySearch( rel_it->getOp1());
01402 Entity ent2 = entitySearch( rel_it->getOp2());
01403 Entity ent3 = entitySearch( rel_it->getOp3());
01404
01405 ObjPointer o1 = rel_it->getOp1();
01406
01407 ObjPointer ptr, o2 = rel_it->getOp2();
01408
01409 if ( ent1 == Entity( BON::Folder(), BON::FCO()) )
01410 {
01411 ptr = rel_it->getOp1();
01412 m_entities.push_back( Entity( BON::Folder(), rel_it->getOp1()));
01413 if ( ptr != BON::FCO())
01414 global_vars.err << "Internal error: Operand 1 of " << rel_it->getOperationStr() << " is not present in Entities\n" <<
01415 ptr->getName() << " : " << ptr->getObjectMeta().name() << " has been inserted";
01416 else
01417 global_vars.err << "Internal error: Operand 1 of " << rel_it->getOperationStr() << " is null\n";
01418 }
01419 if ( ent2 == Entity( BON::Folder(), BON::FCO()))
01420 {
01421 ptr = rel_it->getOp2();
01422 m_entities.push_back( Entity( BON::Folder(), rel_it->getOp2()));
01423 if ( ptr != BON::FCO())
01424 global_vars.err << "Internal error: Operand 2 of " << rel_it->getOperationStr() << " is not present in Entities\n" <<
01425 ptr->getName() << " : " << ptr->getObjectMeta().name() << " has been inserted";
01426 else
01427 global_vars.err << "Internal error: Operand 2 of " << rel_it->getOperationStr() << " is null\n";
01428 }
01429 if ( ent3 == Entity( BON::Folder(), BON::FCO()))
01430 {
01431 if ( three_op )
01432 {
01433 ptr = rel_it->getOp3();
01434 m_entities.push_back( Entity( BON::Folder(), rel_it->getOp3()));
01435 global_vars.err << "Internal error: Operand 3 of " << rel_it->getOperationStr() << " is not present in Entities\n" <<
01436 ptr->getName() << " : " << ptr->getObjectMeta().name() << " has been inserted";
01437 }
01438 else
01439 {
01440 global_vars.err << "Internal error: Association without Connection class: " << o1->getName() << " o " << o2->getName() << "\n";
01441 }
01442 }
01443 }
01444 else
01445 {
01446 if( rel_it->getOp1() == BON::FCO() ||
01447 rel_it->getOp2() == BON::FCO() )
01448 global_vars.err << "Internal error: " << rel_it->getOperationStr() << " has one operand 0\n";
01449
01450 Entity ent1 = entitySearch( rel_it->getOp1());
01451 Entity ent2 = entitySearch( rel_it->getOp2());
01452 ObjPointer ptr = BON::FCO();
01453 if ( ent1 == Entity( BON::Folder(), BON::FCO()))
01454 {
01455 ptr = rel_it->getOp1();
01456 m_entities.push_back( Entity( BON::Folder(), rel_it->getOp1()));
01457 if ( ptr != BON::FCO())
01458 global_vars.err << "Internal error: Operand 1 of " << rel_it->getOperationStr() << " is not present in Entities\n" <<
01459 ptr->getName() << " : " << ptr->getObjectMeta().name() << " has been inserted";
01460 else
01461 global_vars.err << "Internal error: Operand 1 of " << rel_it->getOperationStr() + " is null\n";
01462 }
01463 if ( ent2 == Entity( BON::Folder(), BON::FCO()))
01464 {
01465 ptr = rel_it->getOp2();
01466 m_entities.push_back( Entity( BON::Folder(), rel_it->getOp2()));
01467 ObjPointer ptr2 = rel_it->getOp1();
01468 std::string peer1, peer2;
01469 if ( ptr2 != BON::FCO())
01470 peer1 = ptr2->getName() + " " + ptr2->getObjectMeta().name();
01471 if ( rel_it->getOp2())
01472 peer2 = rel_it->getOp2()->getName() + " " + rel_it->getOp2()->getObjectMeta().name();
01473 global_vars.err << "Internal error: Operand 2 of " << rel_it->getOperationStr() << " is not present in Entities\n" <<
01474 ptr->getName() << " : " << ptr->getObjectMeta().name() << " has been inserted\n" <<
01475 "Operand1: " << peer1 << "\n" <<
01476 "Operand2: " << peer2 << "\n";
01477
01478
01479 if (rel_it->getOperation() == Relation::HAS_ASPECT_OP )
01480 {
01481
01482 ObjPointer t_ptr = rel_it->getOp2();
01483 ObjPointer obj = t_ptr;
01484
01485 BON::Set set = BON::Set( obj);
01486 if (!set) global_vars.err << "Internal error: during set manipulation\n";
01487
01488 std::set<FCO> list = set->getMembers();
01489 std::set<FCO>::iterator list_it = list.begin();
01490 std::string mmm;
01491 while ( list_it != list.end())
01492 {
01493 FCO actual = *list_it;
01494 Relation rela( Relation::ASPECT_MEMBER_OP, t_ptr, actual);
01495 m_relations.push_back(rela);
01496 mmm += actual->getName() + "/" + actual->getObjectMeta().name() + "\n";
01497 ++list_it;
01498 }
01499 global_vars.err << "Internal error: Aspect members are:\n" << mmm << "\n";
01500 }
01501 }
01502 if ( rel_it->getOperation() == Relation::CONTAINMENT_OP ||
01503 rel_it->getOperation() == Relation::FOLDER_CONTAINMENT_OP )
01504 {
01505 if (rel_it->getOp3() == BON::FCO())
01506 global_vars.err << "Internal error: (Folder)Containment line object not present in m_relations list\n";
01507 }
01508 }
01509 }
01510
01511 Relation_Iterator rel_it1 = m_relations.begin();
01512
01513 for( ; rel_it1 != m_relations.end(); ++rel_it1)
01514 {
01515 Relation_Iterator rel_it2 = m_relations.begin();
01516
01517 for( ; rel_it2 != m_relations.end(); ++rel_it2)
01518 {
01519 if (rel_it1->getOperation() == Relation::HAS_ATTRIBUTE_OP &&
01520 rel_it2->getOperation() == Relation::HAS_ATTRIBUTE_OP )
01521 {
01522
01523 if ( rel_it1->getOp1() == rel_it2->getOp1()
01524 && rel_it1->getOp2() == rel_it2->getOp2()
01525 && rel_it1 != rel_it2)
01526 {
01527 ObjPointer o1 = rel_it1->getOp1();
01528
01529 ObjPointer o2 = rel_it1->getOp2();
01530 global_vars.err << "Internal error: Same attribute " << o2->getName() <<
01531 " contained twice by " << o1->getName() << "\n";
01532 }
01533 }
01534 }
01535 }
01536 #endif
01537 }
01538
01539 };