GME  13
MgaMetaModel.cpp
Go to the documentation of this file.
00001 
00002 #include "stdafx.h"
00003 #include "MgaMetaModel.h"
00004 #include "MgaMetaConnection.h"
00005 #include "MgaMetaPointerSpec.h"
00006 
00007 // --------------------------- CMgaMetaModel
00008 
00009 STDMETHODIMP CMgaMetaModel::get_DefinedFCOByName(BSTR name, VARIANT_BOOL inscope, IMgaMetaFCO **p)
00010 {
00011         CHECK_OUT(p);
00012 
00013         COMTRY
00014         {
00015                 CCoreObjectPtr self(GetUnknown());
00016 
00017                 CComBstrObj_lightequal equal( GetUnknown());
00018                 coreobjects_type coreobjects;
00019                 self.GetCollectionValue(ATTRID_DEFFCO_PTR, coreobjects);
00020 
00021                 coreobjects_iterator i = coreobjects.begin();
00022                 coreobjects_iterator e = coreobjects.end();
00023                 while( i != e )
00024                 {
00025                         CComBstrObj n;
00026                         (*i).GetStringValue(ATTRID_NAME, PutOut(n));
00027                         
00028                         if (equal(n, name)) {
00029                                 HRESULT hr = ::QueryInterface(*i, p);
00030                                 if (FAILED(hr))
00031                                         COMTHROW(hr);
00032                                 return hr;
00033                         }
00034 
00035                         ++i;
00036                 }
00037 
00038                 if( inscope == VARIANT_FALSE )
00039                         COMRETURN(E_NOTFOUND);
00040 
00041                 CComObjPtr<IMgaMetaBase> parent;
00042                 COMTHROW( get_DefinedIn(PutOut(parent)) );
00043                 ASSERT( parent != NULL );
00044 
00045                 CComObjPtr<IMgaMetaFolder> folder;
00046                 if( SUCCEEDED(parent.QueryInterface(folder)) ) {
00047                         *p = folder->DefinedFCOByName[name, inscope].Detach();
00048                         return S_OK;
00049                 }
00050 
00051                 CComObjPtr<IMgaMetaModel> model;
00052                 COMTHROW( parent.QueryInterface(model) );
00053                 *p = model->DefinedFCOByName[name, inscope].Detach();
00054         }
00055         COMCATCH(;)
00056 }
00057 
00058 STDMETHODIMP CMgaMetaModel::get_RoleByName(BSTR name, IMgaMetaRole **p)
00059 {
00060         CHECK_OUT(p);
00061 
00062         COMTRY
00063         {
00064                 CCoreObjectPtr self(GetUnknown());
00065 
00066                 CComBstrObj_lightequal equal( GetUnknown());
00067                 coreobjects_type coreobjects;
00068                 self.GetCollectionValue(ATTRID_ROLES_COLL, coreobjects);
00069 
00070                 coreobjects_iterator i = coreobjects.begin();
00071                 coreobjects_iterator e = coreobjects.end();
00072                 while( i != e )
00073                 {
00074                         CComBstrObj n;
00075                         (*i).GetStringValue(ATTRID_NAME, PutOut(n));
00076                         
00077                         if (equal(n, name)) {
00078                                 HRESULT hr = ::QueryInterface(*i, p);
00079                                 if (FAILED(hr))
00080                                         COMTHROW(hr);
00081                                 return hr;
00082                         }
00083 
00084                         ++i;
00085                 }
00086 
00087                 throw_com_error(E_NOTFOUND, _bstr_t(L"Role name '") + name + L"' not found in model " + static_cast<CMgaMetaFCO *const>(this)->GetName());
00088         }
00089         COMCATCH(;)
00090 }
00091 
00092 STDMETHODIMP CMgaMetaModel::get_AspectByName(BSTR name, IMgaMetaAspect **p)
00093 {
00094         CHECK_OUT(p);
00095 
00096         COMTRY
00097         {
00098                 CCoreObjectPtr self(GetUnknown());
00099 
00100                 coreobjects_type coreobjects;
00101                 self.GetCollectionValue(ATTRID_ASPECTS_COLL, coreobjects);
00102 
00103                 coreobjects_iterator i = coreobjects.begin();
00104                 coreobjects_iterator e = coreobjects.end();
00105                 while( i != e )
00106                 {
00107                         CComBstrObj n;
00108                         (*i).GetStringValue(ATTRID_NAME, PutOut(n));
00109                         
00110                         if( n == name ) {
00111                                 HRESULT hr =::QueryInterface(*i, p);
00112                                 if (FAILED(hr))
00113                                         COMTHROW(hr);
00114                                 return hr;
00115                         }
00116                         ++i;
00117                 }
00118 
00119                 COMTHROW(E_NOTFOUND);
00120         }
00121         COMCATCH(;)
00122 }
00123 
00124 STDMETHODIMP CMgaMetaModel::LegalConnectionRoles(BSTR paths, IMgaMetaRoles **p)
00125 {
00126         CHECK_OUT(p);
00127 
00128         COMTRY
00129         {
00130                 // create the collection
00131                 CComObjPtr<RolesExCOMType> coll;
00132                 CreateComObject(coll);
00133 
00134                 // prepare the jointpaths
00135                 jointpaths_type jointpaths;
00136 
00137                 ASSERT( metaprojectref != NULL );
00138                 metaproject->CreateJointPaths(paths, jointpaths);
00139 
00140                 // traverse the roles
00141                 CCoreObjectPtr self(GetUnknown());
00142 
00143                 coreobjects_type roles;
00144                 self.GetCollectionValue(ATTRID_ROLES_COLL, roles);
00145 
00146                 coreobjects_iterator i = roles.begin();
00147                 coreobjects_iterator e = roles.end();
00148                 while( i != e )
00149                 {
00150                         CCoreObjectPtr kind;
00151                         i->GetPointerValue(ATTRID_KIND_PTR, kind);
00152 
00153                         if( kind.GetMetaID() == METAID_METACONNECTION &&
00154                                 CMgaMetaConnection::CheckPaths(kind, jointpaths) )
00155                         {
00156                                 CComObjPtr<IMgaMetaRole> role;
00157                                 COMTHROW( ::QueryInterface(*i, role) );
00158 
00159                                 coll->Add(role);
00160                         }
00161 
00162                         ++i;
00163                 }
00164 
00165                 // return
00166                 MoveTo(coll, p);
00167         }
00168         COMCATCH(;)
00169 }
00170 
00171 STDMETHODIMP CMgaMetaModel::LegalReferenceRoles(BSTR path, IMgaMetaRoles **p)
00172 {
00173         CHECK_OUT(p);
00174 
00175         COMTRY
00176         {
00177                 // create the collection
00178                 CComObjPtr<RolesExCOMType> coll;
00179                 CreateComObject(coll);
00180 
00181                 // prepare the pathitems
00182                 pathitems_type pathitems;
00183 
00184                 ASSERT( metaprojectref != NULL );
00185                 metaproject->CreatePathItems(begin(path), end(path), pathitems);
00186 
00187                 // traverse the roles
00188                 CCoreObjectPtr self(GetUnknown());
00189 
00190                 coreobjects_type roles;
00191                 self.GetCollectionValue(ATTRID_ROLES_COLL, roles);
00192 
00193                 coreobjects_iterator i = roles.begin();
00194                 coreobjects_iterator e = roles.end();
00195                 while( i != e )
00196                 {
00197                         CCoreObjectPtr kind;
00198                         i->GetPointerValue(ATTRID_KIND_PTR, kind);
00199 
00200                         if( kind.GetMetaID() == METAID_METAREFERENCE &&
00201                                 CMgaMetaPointerSpec::CheckPath(kind, pathitems, true) )
00202                         {
00203                                 CComObjPtr<IMgaMetaRole> role;
00204                                 COMTHROW( ::QueryInterface(*i, role) );
00205 
00206                                 coll->Add(role);
00207                         }
00208 
00209                         ++i;
00210                 }
00211 
00212                 // return
00213                 MoveTo(coll, p);
00214         }
00215         COMCATCH(;)
00216 }
00217 
00218 STDMETHODIMP CMgaMetaModel::LegalSetRoles(BSTR path, IMgaMetaRoles **p)
00219 {
00220         CHECK_OUT(p);
00221 
00222         COMTRY
00223         {
00224                 // create the collection
00225                 CComObjPtr<RolesExCOMType> coll;
00226                 CreateComObject(coll);
00227 
00228                 // prepare the pathitems
00229                 pathitems_type pathitems;
00230 
00231                 ASSERT( metaprojectref != NULL );
00232                 metaproject->CreatePathItems(begin(path), end(path), pathitems);
00233 
00234                 // traverse the roles
00235                 CCoreObjectPtr self(GetUnknown());
00236 
00237                 coreobjects_type roles;
00238                 self.GetCollectionValue(ATTRID_ROLES_COLL, roles);
00239 
00240                 coreobjects_iterator i = roles.begin();
00241                 coreobjects_iterator e = roles.end();
00242                 while( i != e )
00243                 {
00244                         CCoreObjectPtr kind;
00245                         i->GetPointerValue(ATTRID_KIND_PTR, kind);
00246 
00247                         if( kind.GetMetaID() == METAID_METASET &&
00248                                 CMgaMetaPointerSpec::CheckPath(kind, pathitems, false) )
00249                         {
00250                                 CComObjPtr<IMgaMetaRole> role;
00251                                 COMTHROW( ::QueryInterface(*i, role) );
00252 
00253                                 coll->Add(role);
00254                         }
00255 
00256                         ++i;
00257                 }
00258 
00259                 // return
00260                 MoveTo(coll, p);
00261         }
00262         COMCATCH(;)
00263 }
00264 
00265 STDMETHODIMP CMgaMetaModel::LegalRoles(IMgaMetaFCO *kind, IMgaMetaRoles **p)
00266 {
00267         CHECK_OUT(p);
00268 
00269         if( kind == NULL )
00270                 return E_INVALIDARG;
00271 
00272         COMTRY
00273         {
00274                 // create the collection
00275 
00276                 CComObjPtr<RolesExCOMType> coll;
00277                 CreateComObject(coll);
00278 
00279                 // traverse the roles
00280                 CCoreObjectPtr self(GetUnknown());
00281 
00282                 coreobjects_type roles;
00283                 self.GetCollectionValue(ATTRID_ROLES_COLL, roles);
00284 
00285                 coreobjects_iterator i = roles.begin();
00286                 coreobjects_iterator e = roles.end();
00287                 while( i != e )
00288                 {
00289                         CCoreObjectPtr rolekind;
00290                         i->GetPointerValue(ATTRID_KIND_PTR, rolekind);
00291 
00292                         if( IsEqualObject(rolekind,kind) )
00293                         {
00294                                 CComObjPtr<IMgaMetaRole> role;
00295                                 COMTHROW( ::QueryInterface(*i, role) );
00296 
00297                                 coll->Add(role);
00298                         }
00299 
00300                         ++i;
00301                 }
00302 
00303                 // return
00304                 MoveTo(coll, p);
00305         }
00306         COMCATCH(;)
00307 }
00308 
00309 // ------- Edit
00310 
00311 STDMETHODIMP CMgaMetaModel::CreateRole(IMgaMetaFCO *kind, IMgaMetaRole **p)
00312 {
00313         CHECK_OUT(p);
00314 
00315         ASSERT( metaprojectref != NULL );
00316 
00317         COMTRY
00318         {
00319                 if( kind == NULL )
00320                         COMTHROW(E_POINTER);
00321 
00322                 CCoreObjectPtr self(GetUnknown());
00323                 ASSERT( self != NULL );
00324 
00325                 CCoreObjectPtr other(kind);
00326                 ASSERT( other != NULL );
00327 
00328                 CCoreObjectPtr role;
00329                 metaproject->CreateMetaBase(METAID_METAROLE, role);
00330 
00331                 role.PutPointerValue(ATTRID_ROLES_COLL, self);
00332                 role.PutPointerValue(ATTRID_KIND_PTR, other);
00333 
00334                 COMTHROW( ::QueryInterface(role, p) );
00335         }
00336         COMCATCH(;)
00337 }
00338 
00339 // ------- Traverse
00340 
00341 void CMgaMetaModel::Traverse(CMgaMetaProject *metaproject, CCoreObjectPtr &me)
00342 {
00343         ASSERT( metaproject != NULL );
00344         ASSERT( me != NULL );
00345 
00346         CMgaMetaFCO::Traverse(metaproject, me);
00347 
00348         TraverseCollection(metaproject, me, ATTRID_DEFFCO_PTR);
00349         TraverseCollection(metaproject, me, ATTRID_ROLES_COLL);
00350         TraverseCollection(metaproject, me, ATTRID_ASPECTS_COLL);
00351 }