GME  13
GMEConstraintEx.cpp
Go to the documentation of this file.
00001 //###############################################################################################################################################
00002 //
00003 //      Object Constraint Language Generic Manager
00004 //      GMEConstraintEx.cpp
00005 //
00006 //###############################################################################################################################################
00007 #include "stdafx.h"
00008 #include "GMEConstraintEx.h"
00009 #include "OCLCommonEx.h"
00010 
00011 namespace OclGme
00012 {
00013         typedef Ocl::Constraint OclConstraint;
00014 
00015 //##############################################################################################################################################
00016 //
00017 //      C L A S S : OclGme::ConstraintBase <<< + Ocl::Constraint
00018 //
00019 //##############################################################################################################################################
00020 
00021         ConstraintBase::ConstraintBase()
00022                 : OclConstraint()
00023         {
00024         }
00025 
00026         ConstraintBase::~ConstraintBase()
00027         {
00028         }
00029 
00030         ConstraintBase::Type ConstraintBase::GetType() const
00031         {
00032                 return m_eType;
00033         }
00034 
00035         ConstraintBase::Location ConstraintBase::GetLocation() const
00036         {
00037                 return m_eLocation;
00038         }
00039 
00040         void ConstraintBase::SetType( ConstraintBase::Type eType, const StringVector& vecLibraryPath )
00041         {
00042                 m_eType = eType;
00043                 switch( eType ) {
00044                         case ConstraintBase::CT_CRITICAL_USER :
00045                         case ConstraintBase::CT_NON_CRITICAL_USER :
00046                                 m_eLocation = ConstraintBase::CL_PROJECT; break;
00047                         case ConstraintBase::CT_CRITICAL_LIBRARY :
00048                         case ConstraintBase::CT_NON_CRITICAL_LIBRARY :
00049                                 m_eLocation = ConstraintBase::CL_LIBRARY; m_vecLibraryPath = vecLibraryPath; break;
00050                         default :
00051                                 m_eLocation = ConstraintBase::CL_META; break;
00052                 }
00053         }
00054 
00055         StringVector ConstraintBase::GetLibraryPath() const
00056         {
00057                 return m_vecLibraryPath;
00058         }
00059 
00060         std::string ConstraintBase::GetFullName() const
00061         {
00062                 return ( IsValid() ) ? OclConstraint::GetFullName() : GetDefinedName();
00063         }
00064 
00065         bool ConstraintBase::GetContextAndName( std::string& strContext, std::string& strName ) const
00066         {
00067                 if ( IsValid() ) {
00068                         strContext = GetContextType();
00069                         strName = GetName();
00070                         return true;
00071                 }
00072 
00073                 std::string strDName = GetDefinedName();
00074                 size_t iPos = strDName.rfind( "::" );
00075 
00076                 if ( iPos == std::string::npos ) {
00077                         strContext = "?";
00078                         strName = strDName;
00079                         return false;
00080                 }
00081 
00082                 strContext = strDName.substr( 0, iPos );
00083                 strName = strDName.substr( iPos + 2 );
00084                 return false;
00085         }
00086 
00087 //##############################################################################################################################################
00088 //
00089 //      C L A S S : OclGme::Constraint <<< + OclGme::ConstraintBase
00090 //
00091 //##############################################################################################################################################
00092 
00093         Constraint::Constraint( const std::string& strName, const std::string& strContextType, const std::string& strExpression, const std::string& strMessage, unsigned long ulEventMask, long lPriority, constraint_depth_enum eDepth, bool bFieldsMandatory )
00094                 : ConstraintBase(), m_strMessage( strMessage ), m_ulEventMask( ulEventMask ), m_lPriority( lPriority ), m_eDepth( eDepth )
00095         {
00096                 SetType( ( lPriority == 1 ) ? CT_CRITICAL_USER : CT_NON_CRITICAL_USER );
00097 
00098                 m_strExpression = strExpression;
00099                 Trim( m_strExpression );
00100 
00101                 if ( m_strExpression.empty() && ! bFieldsMandatory )
00102                         Define( strContextType + "::" + strName, "", true );
00103                 else
00104                         Define( strContextType + "::" + strName, "context " + strContextType + " inv " + strName + " :\r\n\r\n" + m_strExpression, true );
00105         }
00106 
00107         Constraint::Constraint( const std::string& strContextType, CComPtr<IMgaFCO> spFCO, bool bFieldsMandatory )
00108                 : ConstraintBase()
00109         {
00110                 m_spFCO = spFCO;
00111 
00112                 COMTHROW( spFCO->get_IntAttrByName( CComBSTR( "ConstraintPriority" ), &m_lPriority ) );
00113                 SetType( ( m_lPriority == 0 ) ? CT_CRITICAL_META : CT_NON_CRITICAL_META );
00114 
00115                 // TODO : Obtain strMessage, ulEventMask, eDepth
00116 
00117                 std::string strName = OclCommonEx::GetObjectName( spFCO.p );
00118                 Trim( strName );
00119 
00120                 CString strExpression;
00121                 COMTHROW( spFCO->get_StrAttrByName( CComBSTR( "ConstraintEqn" ), PutOut( strExpression ) ) );
00122                 m_strExpression = OclCommonEx::Convert( strExpression );
00123                 Trim( m_strExpression );
00124 
00125                 if ( m_strExpression.empty() && ! bFieldsMandatory )
00126                         Define( strContextType + "::" + strName, "", true );
00127                 else
00128                         Define( strContextType + "::" + strName, "context " + strContextType + " inv " + strName + " :\r\n\r\n" + m_strExpression, true );
00129         }
00130 
00131         Constraint::Constraint( const std::string& strContextType, CComPtr<IMgaConstraint> spConstraint )
00132                 : ConstraintBase()
00133         {
00134                 m_spConstraint = spConstraint;
00135 
00136                 COMTHROW( spConstraint->get_Priority( &m_lPriority ) );
00137                 SetType( ( m_lPriority == 1 ) ? CT_CRITICAL_META : CT_NON_CRITICAL_META );
00138 
00139                 CString strMessage;
00140                 COMTHROW( spConstraint->get_DisplayedName( PutOut( strMessage ) ) );
00141                 m_strMessage = OclCommonEx::Convert( strMessage );
00142 
00143                 COMTHROW( spConstraint->get_Depth( &m_eDepth ) );
00144                 COMTHROW( spConstraint->get_EventMask( &m_ulEventMask ) );
00145 
00146                 CString strTemp;
00147                 COMTHROW( spConstraint->get_Name( PutOut( strTemp ) ) );
00148                 std::string strName = OclCommonEx::Convert( strTemp );
00149                 Trim( strName );
00150 
00151                 CString strExpression;
00152                 COMTHROW( spConstraint->get_Expression( PutOut( strExpression ) ) );
00153                 m_strExpression = OclCommonEx::Convert( strExpression );
00154                 Trim( m_strExpression );
00155 
00156                 Define( strContextType + "::" + strName, "context " + strContextType + " inv " + strName + " :\r\n\r\n" + m_strExpression, false );
00157         }
00158 
00159         Constraint::Constraint( CComPtr<IMgaRegNode> spRegNode, const StringVector& vecLibPath )
00160                 : ConstraintBase()
00161         {
00162                 m_spRegNode = spRegNode;
00163 
00164                 CComPtr<IMgaRegNode> spNode;
00165                 CString strTemp;
00166 
00167                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "Priority" ), &spNode ) );
00168                 COMTHROW( spNode->get_Value( PutOut( strTemp ) ) );
00169                 m_lPriority = _ttol( strTemp );
00170                 if ( ! vecLibPath.empty() )
00171                         SetType( ( m_lPriority == 1 ) ? CT_CRITICAL_LIBRARY : CT_NON_CRITICAL_LIBRARY, vecLibPath );
00172                 else
00173                         SetType( ( m_lPriority == 1 ) ? CT_CRITICAL_USER : CT_NON_CRITICAL_USER );
00174 
00175                 strTemp.Empty();
00176                 spNode = NULL;
00177 
00178                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "Description" ), &spNode ) );
00179                 COMTHROW( spNode->get_Value( PutOut( strTemp ) ) );
00180                 m_strMessage = OclCommonEx::Convert( strTemp );
00181 
00182                 strTemp.Empty();
00183                 spNode = NULL;
00184 
00185                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "Depth" ), &spNode ) );
00186                 COMTHROW( spNode->get_Value( PutOut( strTemp ) ) );
00187                 strTemp.TrimLeft(); strTemp.TrimRight();
00188                 if ( strTemp == "0" )
00189                         m_eDepth = CONSTRAINT_DEPTH_ZERO;
00190                 else
00191                         if ( strTemp == "1" )
00192                                 m_eDepth = CONSTRAINT_DEPTH_ONE;
00193                         else
00194                                 m_eDepth = CONSTRAINT_DEPTH_ANY;
00195 
00196                 strTemp.Empty();
00197                 spNode = NULL;
00198 
00199 
00200                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "EventMask" ), &spNode ) );
00201                 COMTHROW( spNode->get_Value( PutOut( strTemp ) ) );
00202                 TCHAR* pchStop;
00203                 m_ulEventMask = _tcstoul( strTemp, &pchStop, 10 );
00204 
00205                 strTemp.Empty();
00206                 spNode = NULL;
00207 
00208                 COMTHROW( spRegNode->get_Name( PutOut( strTemp ) ) );
00209                 int iPos = strTemp.ReverseFind( ':' );
00210                 std::string strName = OclCommonEx::Convert( strTemp.Right( strTemp.GetLength() - iPos - 1 ) );
00211                 std::string strContextType = OclCommonEx::Convert( strTemp.Left( iPos - 1 ) );
00212                 Trim( strName );
00213                 Trim( strContextType );
00214 
00215                 strTemp.Empty();
00216 
00217                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "Expression" ), &spNode ) );
00218                 COMTHROW( spNode->get_Value( PutOut( strTemp ) ) );
00219                 m_strExpression = OclCommonEx::Convert( strTemp );
00220                 Trim( m_strExpression );
00221 
00222                 Define( strContextType + "::" + strName, "context " + strContextType + " inv " + strName + " :\r\n\r\n" + m_strExpression, true );
00223         }
00224 
00225         Constraint::~Constraint()
00226         {
00227         }
00228 
00229         unsigned long Constraint::GetEventMask() const
00230         {
00231                 return m_ulEventMask;
00232         }
00233 
00234         long Constraint::GetPriority() const
00235         {
00236                 return m_lPriority;
00237         }
00238 
00239         constraint_depth_enum Constraint::GetDepth() const
00240         {
00241                 return m_eDepth;
00242         }
00243 
00244         std::string Constraint::GetMessage() const
00245         {
00246                 return m_strMessage;
00247         }
00248 
00249         std::string Constraint::GetExpression() const
00250         {
00251                 return m_strExpression;
00252         }
00253 
00254         OclConstraint::State Constraint::Write( CComPtr<IMgaRegNode> spRegNode )
00255         {
00256                 if ( GetState() < OclConstraint::CS_CHECK_SUCCEEDED )
00257                         return GetState();
00258 
00259                 // COMTHROW( spRegNode->put_Name( CComBSTR( OclCommonEx::Convert( GetFullName() ) ) ) );
00260 
00261                 CComPtr<IMgaRegNode> spNode;
00262                 CString strTemp;
00263 
00264                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( L"EventMask" ), &spNode ) );
00265                 strTemp.Format( _T("%d"), m_ulEventMask );
00266                 COMTHROW( spNode->put_Value( CComBSTR( strTemp ) ) );
00267                 strTemp.Empty();
00268                 spNode = NULL;
00269 
00270                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( L"Description" ), &spNode ) );
00271                 COMTHROW( spNode->put_Value( CComBSTR( OclCommonEx::Convert( m_strMessage ) ) ) );
00272                 spNode = NULL;
00273 
00274                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( L"Priority" ), &spNode ) );
00275                 strTemp.Format( _T("%d"), m_lPriority );
00276                 COMTHROW( spNode->put_Value( CComBSTR( strTemp ) ) );
00277                 strTemp.Empty();
00278                 spNode = NULL;
00279 
00280                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "Depth" ), &spNode ) );
00281                 if ( m_eDepth == CONSTRAINT_DEPTH_ZERO )
00282                         strTemp = "0";
00283                 else
00284                         if ( m_eDepth == CONSTRAINT_DEPTH_ONE )
00285                                 strTemp = "1";
00286                         else
00287                                 strTemp = "any";
00288                 COMTHROW( spNode->put_Value( CComBSTR( strTemp ) ) );
00289                 spNode = NULL;
00290 
00291                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "Expression" ), &spNode ) );
00292                 COMTHROW( spNode->put_Value( CComBSTR( OclCommonEx::Convert( m_strExpression ) ) ) );
00293 
00294                 return GetState();
00295         }
00296 
00297         Constraint::EnableInfo Constraint::GetEnableInfo( CComPtr<IMgaObject> spObject ) const
00298         {
00299                 // Check if constraint is valid.
00300 
00301                 if ( GetState() < OclConstraint::CS_CHECK_SUCCEEDED )
00302                         return Constraint::CE_NONE;
00303 
00304                 // Check if context kind is the appropriate.
00305 
00306                 if ( ! ( "meta::" + OclCommonEx::GetObjectKind( spObject ) == GetContextType() ) )
00307                         return Constraint::CE_NONE;
00308 
00309                 // Check if object is to be deleted.
00310 
00311                 long lStatus;
00312                 COMTHROW( spObject->get_Status( &lStatus ) );
00313                 if ( lStatus != OBJECT_EXISTS )
00314                         return Constraint::CE_ENABLED;
00315 
00316                 // Obtain library path of the object
00317 
00318                 StringVector vecObjectPath = OclCommonEx::GetLibraryPath( spObject );
00319 
00320                 // In case of Library constraint check if object is in the effect range of library (in the library itself or in the project)
00321 
00322                 if ( GetLocation() == ConstraintBase::CL_LIBRARY ) {
00323                         StringVector vecConstraintPath = GetLibraryPath();
00324                         for ( unsigned int i = 0 ; i < min( vecConstraintPath.size(), vecObjectPath.size() ) ; i++ )
00325                                 if ( vecObjectPath[ i ] != vecConstraintPath[ i ] )
00326                                         return Constraint::CE_NONE;
00327                         if ( ! vecObjectPath.empty() && vecObjectPath.size() < vecConstraintPath.size() )
00328                                 return Constraint::CE_NONE;
00329                 }
00330                 if ( GetLocation() == ConstraintBase::CL_PROJECT && ! vecObjectPath.empty() )
00331                         return Constraint::CE_NONE;
00332 
00333                 // Check if constraint defined in the paradigm and has high priority
00334 
00335                 if ( GetLocation() == ConstraintBase::CL_META && GetPriority() == 1 )
00336                         return Constraint::CE_ENABLED_READONLY;
00337 
00338                 // Obtain the flag of the object.
00339 
00340                 CComQIPtr<IMgaFCO> spFCO = spObject;
00341                 CComQIPtr<IMgaFolder> spFolder = spObject;
00342                 CComPtr<IMgaRegNode> spRegNode;
00343                 if ( spFCO.p )
00344                         COMTHROW( spFCO->get_RegistryNode( CComBSTR( OclCommonEx::Convert( "ConstraintEnabling/" + GetFullName() ) ), &spRegNode ) );
00345                 else
00346                         COMTHROW( spFolder->get_RegistryNode( CComBSTR( OclCommonEx::Convert( "ConstraintEnabling/" + GetFullName() ) ), &spRegNode ) );
00347 
00348                 CString strEnable;
00349                 COMTHROW( spRegNode->get_Value( PutOut( strEnable ) ) );
00350                 strEnable.MakeLower();
00351 
00352                 // If the object is in a library
00353 
00354                 if ( ! vecObjectPath.empty() )
00355                         return ( strEnable == "yes" || strEnable.IsEmpty() && GetLocation() == ConstraintBase::CL_META ) ? Constraint::CE_ENABLED_READONLY : Constraint::CE_DISABLED_READONLY;
00356 
00357                 // If the constraint is defined in a library and it has high priority
00358 
00359                 if ( strEnable == "yes" && GetLocation() == ConstraintBase::CL_LIBRARY && GetPriority() == 1 )
00360                         return Constraint::CE_ENABLED_READONLY;
00361 
00362                 // Obtain the inheritance flag
00363 
00364                 long lFlagStatus;
00365                 COMTHROW( spRegNode->get_Status( &lFlagStatus ) );
00366 
00367                 if ( lFlagStatus == 0 )
00368                         return ( strEnable == "yes" || strEnable.IsEmpty() && GetLocation() == ConstraintBase::CL_META ) ? Constraint::CE_ENABLED : Constraint::CE_DISABLED;
00369                 else
00370                         return ( strEnable == "yes" || strEnable.IsEmpty() && GetLocation() == ConstraintBase::CL_META ) ? Constraint::CE_ENABLED_INHERITED : Constraint::CE_DISABLED_INHERITED;
00371         }
00372 
00373 //##############################################################################################################################################
00374 //
00375 //      C L A S S : OclGme::ConstraintFunction <<< + OclGme::ConstraintBase
00376 //
00377 //##############################################################################################################################################
00378 
00379         ConstraintFunction::ConstraintFunction( const std::string& strName, const std::string& strContextType, const std::string& strParameterList, const std::string& strReturnType, bool bIsAttribute, const std::string& strExpression, bool bFieldsMandatory )
00380                 : ConstraintBase()
00381         {
00382                 CString strTemp = OclCommonEx::Convert( strParameterList );
00383                 strTemp.Replace( _T(","), _T(";") );
00384                 m_strParameterList = OclCommonEx::Convert( strTemp );
00385                 Trim( m_strParameterList );
00386 
00387                 m_strExpression = strExpression;
00388                 Trim( m_strExpression );
00389 
00390                 SetType( ( bIsAttribute ) ? ConstraintBase::CT_ATTRIBUTE_USER : ConstraintBase::CT_METHOD_USER );
00391                 std::string strStereotype = ( bIsAttribute ) ? " defattribute " : " defmethod ";
00392 
00393                 Define( strContextType + "::" + strName, "context " + strContextType + "::" + strName + "( " + m_strParameterList + " ) : " + strReturnType + strStereotype + strName + " :\r\n\r\n" + m_strExpression );
00394         }
00395 
00396         ConstraintFunction::ConstraintFunction( CComPtr<IMgaFCO> spFCO, bool bFieldsMandatory )
00397                 : ConstraintBase()
00398         {
00399                 m_spFCO = spFCO;
00400 
00401                 CString strParameterList;
00402                 COMTHROW( spFCO->get_StrAttrByName( CComBSTR( L"CFuncParamList" ), PutOut( strParameterList ) ) );
00403                 strParameterList.Replace( _T(","), _T(";") );
00404                 m_strParameterList = OclCommonEx::Convert( strParameterList );
00405                 Trim( m_strParameterList );
00406 
00407                 CString strExpression;
00408                 COMTHROW( spFCO->get_StrAttrByName( CComBSTR( L"CFuncDefinition" ), PutOut( strExpression ) ) );
00409                 m_strExpression = OclCommonEx::Convert( strExpression );
00410                 Trim( m_strExpression );
00411 
00412                 CString strAttrStereotype;
00413                 COMTHROW( spFCO->get_StrAttrByName( CComBSTR( L"CFuncStereotype" ), PutOut( strAttrStereotype ) ) );
00414                 SetType( ( strAttrStereotype == _T("attribute") ) ? ConstraintBase::CT_ATTRIBUTE_META : ConstraintBase::CT_METHOD_META );
00415                 std::string strStereotype = " def" + OclCommonEx::Convert( strAttrStereotype ) + " ";
00416 
00417                 std::string strName = OclCommonEx::GetObjectName( spFCO.p );
00418 
00419                 CString strAttrContextType;
00420                 COMTHROW( spFCO->get_StrAttrByName( CComBSTR( "CFuncContext" ), PutOut( strAttrContextType ) ) );
00421                 std::string strContextType = OclCommonEx::Convert( strAttrContextType );
00422                 Trim( strContextType );
00423 
00424                 CString strAttrReturnType;
00425                 COMTHROW( spFCO->get_StrAttrByName( CComBSTR( "CFuncReturnType" ), PutOut( strAttrReturnType ) ) );
00426                 std::string strReturnType = OclCommonEx::Convert( strAttrReturnType );
00427 
00428                 Define( strContextType + "::" + strName, "context " + strContextType + "::" + strName + "( " + m_strParameterList + " ) : " + strReturnType + strStereotype + strName + " :\r\n\r\n" + m_strExpression );
00429         }
00430 
00431         ConstraintFunction::ConstraintFunction( CComPtr<IMgaConstraint> spConstraint )
00432                 : ConstraintBase()
00433         {
00434                 m_spConstraint = spConstraint;
00435 
00436                 CString strCFName;
00437                 COMTHROW( spConstraint->get_Name( PutOut( strCFName ) ) );
00438                 if ( strCFName.IsEmpty() )
00439                         ReadFromOldFormat();
00440                 else
00441                         ReadFromNewFormat();
00442         }
00443 
00444         void ConstraintFunction::ReadFromOldFormat()
00445         {
00446                 SetType( ConstraintBase::CT_METHOD_META );
00447                 std::string strStereotype = " defmethod ";
00448                 std::string strContextType = "gme::Project";
00449                 std::string strReturnType = "ocl::Boolean";
00450                 std::string strName;
00451 
00452                 CString strFunctionData;
00453                 CString strTemp;
00454                 COMTHROW( m_spConstraint->get_Expression( PutOut( strFunctionData ) ) );
00455                 strFunctionData.TrimLeft();
00456                 if ( strFunctionData.GetLength() > 8 ) {
00457                         strFunctionData = strFunctionData.Right( strFunctionData.GetLength() - 8 );
00458                         strFunctionData.TrimLeft();
00459 
00460                         int iPos = strFunctionData.Find( _T("(") );
00461                         if ( iPos != -1 ) {
00462                                 strTemp = strFunctionData.Left( iPos );
00463                                 strTemp.TrimLeft(); strTemp.TrimRight();
00464                                 strName = OclCommonEx::Convert( strTemp );
00465 
00466                                 strFunctionData = strFunctionData.Right( strFunctionData.GetLength() - iPos - 1 );
00467                                 iPos = strFunctionData.Find( _T(")") );
00468                                 if ( iPos != -1 ) {
00469                                         strTemp = strFunctionData.Left( iPos );
00470                                         strTemp.TrimLeft(); strTemp.TrimRight();
00471                                         strTemp.Replace( _T(","), _T(";") );
00472                                         m_strParameterList = OclCommonEx::Convert( strTemp );
00473 
00474                                         strFunctionData = strFunctionData.Right( strFunctionData.GetLength() - iPos - 1 );
00475                                         m_strExpression = OclCommonEx::Convert( strFunctionData );
00476                                         Trim( m_strExpression );
00477                                 }
00478                         }
00479                 }
00480                 Define( strContextType + "::" + strName, "context " + strContextType + "::" + strName + "( " + m_strParameterList + " ) : " + strReturnType + strStereotype + strName + " :\r\n\r\n" + m_strExpression );
00481         }
00482 
00483         void ConstraintFunction::ReadFromNewFormat()
00484         {
00485                 CString strCFName;
00486                 COMTHROW( m_spConstraint->get_Name( PutOut( strCFName ) ) );
00487                 std::string strName = OclCommonEx::Convert( strCFName );
00488                 Trim( strName );
00489 
00490                 CString strFunctionData;
00491                 CString strTemp;
00492                 COMTHROW( m_spConstraint->get_Expression( PutOut( strFunctionData ) ) );
00493 
00494                 std::string strStereotype = " defmethod ";
00495                 int iPos = strFunctionData.Find( ';' );
00496                 if ( iPos != -1 ) {
00497                         strTemp = strFunctionData.Left( iPos );
00498                         strTemp.TrimLeft(); strTemp.TrimRight();
00499                         strStereotype = OclCommonEx::Convert( strTemp );
00500                         if ( strStereotype == "attribute" )
00501                                 strStereotype = " defattribute ";
00502                         else
00503                                 strStereotype = " defmethod ";
00504                         strFunctionData = strFunctionData.Right( strFunctionData.GetLength() - iPos - 1 );
00505                 }
00506                 SetType( ( strStereotype == " defattribute " ) ? ConstraintBase::CT_ATTRIBUTE_META : ConstraintBase::CT_METHOD_META );
00507 
00508                 std::string strContextType = "gme::Project";
00509                 iPos = strFunctionData.Find( ';' );
00510                 if ( iPos != -1 ) {
00511                         strTemp = strFunctionData.Left( iPos );
00512                         strTemp.TrimLeft(); strTemp.TrimRight();
00513                         strContextType = OclCommonEx::Convert( strTemp );
00514                         Trim( strContextType );
00515                         strFunctionData = strFunctionData.Right( strFunctionData.GetLength() - iPos - 1 );
00516                 }
00517 
00518                 iPos = strFunctionData.Find( _T(';') );
00519                 if ( iPos != -1 ) {
00520                         strTemp = strFunctionData.Left( iPos );
00521                         strTemp.TrimLeft(); strTemp.TrimRight();
00522                         strTemp.Replace( _T(","), _T(";") );
00523                         m_strParameterList = OclCommonEx::Convert( strTemp );
00524                         strFunctionData = strFunctionData.Right( strFunctionData.GetLength() - iPos - 1 );
00525                 }
00526 
00527                 std::string strReturnType = "ocl::Boolean";
00528                 iPos = strFunctionData.Find( ';' );
00529                 if ( iPos != -1 ) {
00530                         strTemp = strFunctionData.Left( iPos );
00531                         strTemp.TrimLeft(); strTemp.TrimRight();
00532                         strReturnType = OclCommonEx::Convert( strTemp );
00533                         strFunctionData = strFunctionData.Right( strFunctionData.GetLength() - iPos - 1 );
00534                 }
00535 
00536                 strFunctionData.TrimLeft(); strFunctionData.TrimRight();
00537                 m_strExpression = OclCommonEx::Convert( strFunctionData );
00538 
00539                 Define( strContextType + "::" + strName, "context " + strContextType + "::" + strName + "( " + m_strParameterList + " ) : " + strReturnType + strStereotype + strName + " :\r\n\r\n" + m_strExpression );
00540         }
00541 
00542         ConstraintFunction::ConstraintFunction( CComPtr<IMgaRegNode> spRegNode )
00543                 : ConstraintBase()
00544         {
00545                 m_spRegNode = spRegNode;
00546 
00547                 CComPtr<IMgaRegNode> spNode;
00548                 CString strTemp;
00549 
00550                 COMTHROW( spRegNode->get_Name( PutOut( strTemp ) ) );
00551                 std::string strName = OclCommonEx::Convert( strTemp );
00552                 Trim( strName );
00553 
00554                 strTemp.Empty();
00555 
00556                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "Context" ), &spNode ) );
00557                 COMTHROW( spNode->get_Value( PutOut( strTemp ) ) );
00558                 std::string strContextType = OclCommonEx::Convert( strTemp );
00559                 Trim( strContextType );
00560 
00561                 strTemp.Empty();
00562                 spNode = NULL;
00563 
00564                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "Stereotype" ), &spNode ) );
00565                 COMTHROW( spNode->get_Value( PutOut( strTemp ) ) );
00566                 std::string strStereotype = OclCommonEx::Convert( strTemp );
00567                 Trim( strStereotype );
00568                 if ( strStereotype == "attribute" )
00569                         strStereotype = " defattribute ";
00570                 else
00571                         strStereotype = " defmethod ";
00572                 SetType( ( strStereotype == " defattribute " ) ? ConstraintBase::CT_ATTRIBUTE_USER : ConstraintBase::CT_METHOD_USER );
00573 
00574                 strTemp.Empty();
00575                 spNode = NULL;
00576 
00577                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "ParameterList" ), &spNode ) );
00578                 COMTHROW( spNode->get_Value( PutOut( strTemp ) ) );
00579                 m_strParameterList = OclCommonEx::Convert( strTemp );
00580                 Trim( m_strParameterList );
00581 
00582                 strTemp.Empty();
00583                 spNode = NULL;
00584 
00585                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "ReturnType" ), &spNode ) );
00586                 COMTHROW( spNode->get_Value( PutOut( strTemp ) ) );
00587                 std::string strReturnType = OclCommonEx::Convert( strTemp );
00588                 Trim( strReturnType );
00589 
00590                 strTemp.Empty();
00591                 spNode = NULL;
00592 
00593                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "Expression" ), &spNode ) );
00594                 COMTHROW( spNode->get_Value( PutOut( strTemp ) ) );
00595                 m_strExpression = OclCommonEx::Convert( strTemp );
00596                 Trim( m_strExpression );
00597 
00598                 Define( strContextType + "::" + strName, "context " + strContextType + "::" + strName + "( " + m_strParameterList + " ) : " + strReturnType + strStereotype + strName + " :\r\n\r\n" + m_strExpression, true );
00599         }
00600 
00601         std::string ConstraintFunction::GetParameterList() const
00602         {
00603                 return m_strParameterList;
00604         }
00605 
00606         std::string ConstraintFunction::GetExpression() const
00607         {
00608                 return m_strExpression;
00609         }
00610 
00611         OclConstraint::State ConstraintFunction::Write( CComPtr<IMgaRegNode> spRegNode )
00612         {
00613                 if ( GetState() < OclConstraint::CS_CHECK_SUCCEEDED )
00614                         return GetState();
00615 
00616                 // COMTHROW( spRegNode->put_Name( CComBSTR( OclCommonEx::Convert( GetName() ) ) ) );
00617 
00618                 CComPtr<IMgaRegNode> spNode;
00619 
00620                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "Context" ), &spNode ) );
00621                 COMTHROW( spNode->put_Value( CComBSTR( OclCommonEx::Convert( GetContextType() ) ) ) );
00622                 spNode = NULL;
00623 
00624                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "Stereotype" ), &spNode ) );
00625                 COMTHROW( spNode->put_Value( CComBSTR( ( GetType() == ConstraintBase::CT_ATTRIBUTE_USER ) ? "attribute" : "method" ) ) );
00626                 spNode = NULL;
00627 
00628                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "ParameterList" ), &spNode ) );
00629                 COMTHROW( spNode->put_Value( CComBSTR( OclCommonEx::Convert( m_strParameterList ) ) ) );
00630                 spNode = NULL;
00631 
00632                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "ReturnType" ), &spNode ) );
00633                 COMTHROW( spNode->put_Value( CComBSTR( OclCommonEx::Convert( GetReturnType() ) ) ) );
00634                 spNode = NULL;
00635 
00636                 COMTHROW( spRegNode->get_SubNodeByName( CComBSTR( "Expression" ), &spNode ) );
00637                 COMTHROW( spNode->put_Value( CComBSTR( OclCommonEx::Convert( m_strExpression ) ) ) );
00638 
00639                 return GetState();
00640         }
00641 
00642 }; // namespace OclGme