导航

LcmAdvancerMessage input Object

Posted on 2006-06-10 15:29  hcfalan  阅读(398)  评论(0编辑  收藏  举报
LcmAdvancerMessage input object is Business item object, such as Document or Part. for example, 如果你想在一个业务对象的LicfCycleState发生改变的同时,更新其关联对象的LicfCycleState的属性值,那么就需要LcmAdvancerMessage.
1. define message
   define object message StateChange like LcmAdvancerMessage;
2. attach message
   attach object message StateChange to PdmItem in server bbksvr;
3. write method code
message PdmItem:StateChange
  (
     update:      ObjectPtr       obj::
     update:      ObjectPtr       procHist::
     input :      ObjectPtr       msgProc::
     output:      string*         exitState ::
     output:      string*         advComments ::
     output:      integer*        mfail 
  ) code
{
   char *mod_name = "PdmItem:StateChange";
   string classN = NULL;                /* class name for BeginDbFrame */
   string a_framename = NULL;           /* database frame name */
   string LCAttr = NULL;                /* pointer to LC state attr */
   integer dstat = OKAY;
   integer indx0 = 0, icnt = 0;
 
   ObjectPtr item = NULL;               /* related object being updated */
   SetOfObjects itemObjs = NULL;        /* related item objects */
   SetOfObjects relObjs = NULL;         /* relation objects */
  
   ObjectPtr genContext = NULL;
 
   *mfail = USC_OKAY;
   *exitState = "PASS";
   *advComments = "States Automatically Updated";
  
 
// get Life Cycle State from input object(such as Document, Part, etc)
   if (dstat = objGetAttribute(obj, LifeCycleStateAttr, &LCAttr))
   {
       goto EXIT;
   }
 
// expand AdHocDep relation to get dependent on items
 
   if (dstat = SetUpContext(objClass(obj), obj, &genContext, mfail))
   {
       goto EXIT;
   }
   if (*mfail) goto CLEANUP;
 
   if (dstat = ExpandRelationWithCtxt(AdHocDepClass, obj,
                                      "AdHocDependentOnItems",
                                      genContext,
                                      SC_SCOPE_OF_SESSION,
                                      NULL,
                                      &itemObjs,
                                      &relObjs,
                                      mfail))
   {
       goto EXIT;
   }
 
   if (*mfail) goto CLEANUP;
 
// update each dependent item
   icnt = low_set_size (itemObjs);
   for ( indx0 = 0; indx0 < icnt; indx0 ++ )
   {
       item = (ObjectPtr) low_set_get (itemObjs, indx0);
 
// Set Life Cycle State to the same as original object
       if ( dstat = objSetAttribute (item, LifeCycleStateAttr, LCAttr))
       {
           goto EXIT;
       }
 
// get class name
       if ( dstat = objGetClass (item, &classN))
       {
           goto EXIT;
       }
 
// begin DB frame
       if ( dstat = BeginDbFrame (classN, &a_framename, mfail))
       {
           goto EXIT;
       }
 
       if ( *mfail ) goto CLEANUP;
 
// lock and write object to database
       if ( dstat = LockDbObject (item, mfail))
       {
           goto EXIT;
       }
      
       if ( *mfail ) goto CLEANUP;
      
       if ( dstat = UpdateDbObject (item, mfail))
       {
           goto EXIT;
       }
 
       if ( *mfail ) goto CLEANUP;
 
// end DB frame
       if ( dstat = EndDbFrame (classN, a_framename, mfail))
       {
           goto EXIT;
       }
 
       if ( *mfail ) goto CLEANUP;
   }
 
CLEANUP:
 
   if ( a_framename )
      freespace ( a_framename );
 
   if ( itemObjs )
      objDisposeAll ( itemObjs );
 
   if ( relObjs )
      objDisposeAll ( relObjs );
 
EXIT:
 
   if ( dstat != OKAY )
      uiShowFatalError(dstat, WHERE);
   return ( dstat );
}
;
4. 在流程中使用Message Process, message name is StateChange.