home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Core / ODSessn.cpp < prev    next >
Encoding:
Text File  |  1996-08-28  |  19.5 KB  |  605 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ODSessn.cpp
  3.  
  4.     Contains:    ODSession class implementation
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>    19.07.1996    NP        1370120: don't purge objects that don't
  13.                                     exist!
  14.          <3>     6/21/96    RA        T10025: Set Binding before InitBinding
  15.                                     because Binding needs to call session for
  16.                                     ref to itself
  17.         <50>     10/8/95    TJ        Fixes Recomended by Refball
  18.         <49>     4/10/95    NP        1287722: Change signature of
  19.                                     ODSession::GetUserName.
  20.         <48>    25/09/95    NP        1280561: Check results of operator new.
  21.         <47>     8/29/95    DM        1276569: FB3:ODSession::GetUserName can
  22.                                     return bogus string
  23.         <46>     8/29/95    RR        # 1276401 Register Mouse Focus
  24.         <45>     8/16/95    NP        1242634: Remove #define PLATFORMFILEVIRTUAL
  25.                                     when PlatformFile has no virt. methods.
  26.         <44>      8/3/95    RR        #1257260: Collapse B classes. Remove
  27.                                     somInit methods. Don't call IsInitialized
  28.                                     or SubclassResponsibility
  29.         <43>     7/27/95    CC        1153788: Use std C library routines rand
  30.                                     and srand for generating unique update ids.
  31.         <42>     5/30/95    CG        #1252280 BB: PStrToIntl should not  be used
  32.                                     by OpenDoc.
  33.         <41>     5/26/95    DM        1251403: Multithreading naming support.
  34.         <40>     5/24/95    CG        #1239535 BB: Added temporary work around.
  35.         <39>     5/11/95    NP        1242421: Fix exception handling
  36.         <38>     5/11/95    VL        1238421: Implemented Purge.
  37.         <37>     4/26/95    CG        1211082 BB: 5$ Bugs need to be evaluated
  38.                                     and removed from Core
  39.         <36>      4/5/95    CG        #1216169 BB, #1221135: When Editors folder
  40.                                     or OpenDoc Libraries folder is missing,
  41.                                     OpenDoc quits and displays error.
  42.         <35>     3/27/95    CC        1231902: Pass ODSession to
  43.                                     InitTranslation().
  44.         <34>      3/7/95    RR        #1220929 Caching of foci in ODWindowState
  45.                                     necessitated reordering of Inits
  46.         <33>     2/16/95    CG        #1207793: defined resource id constant.
  47.         <32>     2/10/95    CG        #1177475: Need to initialize translation
  48.                                     object before nameSpaceManager.
  49.         <31>    12/13/94    SS        1205663 - changed ODQD to gODQD
  50.         <30>     12/5/94    jpa        Added global ODQD & initialization code
  51.                                     [1203926]
  52.         <29>    11/30/94    RR        Include time.h
  53.         <28>    11/15/94    NP        1200193-The Shell should instantiate its
  54.                                     Semantic Interface.
  55.         <27>    11/15/94    NP        1200132-Removed instantiation of Shell
  56.                                     Semantic Interface from here.
  57.         <26>     10/7/94    CC        1191489 - Moved UniqueUpdateID() in from
  58.                                     base class.
  59.         <25>      9/9/94    NP        1184043: Change to InitSemanticInterface.
  60.         <24>     8/22/94    TÇ        #1182448 System Process quits when no
  61.                                     OpenDoc documents are running
  62.         <23>     8/19/94    NP        1181622: Ownership fix.
  63.         <22>     8/13/94    TÇ        #1180814 Added support for ODPartWrapper
  64.                                     API and removed a chr(16) on line #288
  65.                                     which was randomly introduced by projector?
  66.         <21>     8/12/94    NP        1180762-added setters for getters. moved
  67.                                     stuff to B file. Removed GetSemtInterface.
  68.         <20>      8/3/94    CC        Register the clipboard focus.
  69.         <19>      8/3/94    VL        1153123: Storage to ODStor.
  70.         <18>      8/2/94    TÇ        bug# for #17 right below was #1178167
  71.         <17>      8/2/94    TÇ        added TOKENTABLECORRUPTED to work around
  72.                                     heap corruption occuring when fTokenTable
  73.                                     was deleted.  Changed deletes to
  74.                                     ODDeleteObject.
  75.         <16>     7/29/94    CG        Removed Object registration APIs from
  76.                                     session.
  77.         <15>     7/21/94    TÇ        explicitly create & delete a PlatformFile
  78.                                     to make sure it is not deadstripped, added
  79.                                     #define PLATFORMFILEVIRTUAL
  80.         <14>     7/11/94    TÇ        added GetInfo, SetInfo, set _fInfo in
  81.                                     InitSession
  82.         <13>     7/11/94    NP        Fixed compile problem in GetUserName.
  83.         <12>      7/8/94    NP        Fix GetUserName.
  84.         <11>      7/7/94    RR        Initialize dispatcher AFTER token table
  85.         <10>      7/1/94    NP        Change to InitSIHelper.
  86.          <9>      7/1/94    CG        Uncommented code in GetUserName.
  87.          <8>     6/30/94    CG        Uncommented messaging-related fields and
  88.                                     methods, moved StdDisp initialization to
  89.                                     Dispatch.cpp.
  90.          <7>     6/28/94    VL        Use DragDrp.
  91.          <6>     6/28/94    VL        Fixed parameters to InitStorageSystem.
  92.          <5>     6/24/94    CG        Initialization clean up.
  93.          <4>     6/23/94    CG        Somverted original implementation.
  94.          <3>     6/19/94    MB        Implement GetDefaultHeap
  95.          <2>     6/18/94    MB        Add memory component
  96.          <1>     6/14/94    CG        first checked in
  97.         ------------------------------------------------------------
  98.          <7>      6/6/94    jpa        Eliminate spurious ASLM header include.
  99.                                     [1153437]
  100.          <6>      6/1/94    CG        Moved fPreferences to nameSpaceManager and
  101.                                     changed session to use public binding
  102.                                     object.
  103.          <5>     5/27/94    CG        #1165186: Abstracted prefs out of binding.
  104.          <4>      5/9/94    MB        #1162181: Changes necessary to install MMM.
  105.          <3>      4/1/94    TÇ        #1154941: Get OpenDoc source to actually
  106.                                     compile for PowerPC
  107.          <2>     3/31/94    eeh        bug #1153999: PStrToIntl interface changed.
  108.          <1>     3/28/94    CG        first checked in
  109.          <6>     3/26/94    NP        1153512. Object Registration API needed.
  110.          <5>     3/26/94    NP        1153504. InitSemanticInterface.
  111.          <4>     3/25/94    CC        Change name of included file to
  112.                                     <LinkMgr.xh>. (1153348)
  113.          <3>     3/15/94    MB        Changes to support SCpp/ASLM builds,
  114.                                     #1150864.
  115.          <2>     2/28/94    CG        (no bug #) Changed call to GetSystemPool()
  116.                                     to XMPGetSystemHeap().
  117.         <39>      2/9/94    TÇ        Throw to THROW
  118.         <38>      2/7/94    TÇ        more PPC header fixes
  119.         <37>      2/4/94    TÇ        fixes to compile with PPC Universal headers
  120.         <36>      2/3/94    CG        System Session gets created in InitSession.
  121.         <35>      2/1/94    RR        Call InitSessionForPlatform in InitSession
  122.         <34>     1/28/94    CC        Added UniqueUpdateID().
  123.         <33>     1/15/94    RR        WinState.h->WinStat.h,
  124.                                     Dispatch.h->Disptch.h
  125.         <32>     1/14/94    NP        Init changes.
  126.         <31>     1/14/94    CG        Added include for new NmSpcMgr.h.
  127.         <30>     1/12/94    CG        Added fBinding field and calls to new
  128.                                     ODBinding and InitBinding.
  129.         <29>     1/12/94    VL        Init changes.
  130.         <28>    12/20/93    RR        New constructor/init interface
  131.         <27>    12/15/93    TÇ        more InitObject changes, rename
  132.                                     Initialize() method call for ClipBoard and
  133.                                     NameSpaceManager
  134.         <26>     12/8/93    CC        Create and Initialize Link Manager object
  135.         <25>     12/3/93    TÇ        Stop including ODError.h, it is included
  136.                                     as ErrorDef.h inside Except.h
  137.         <24>     12/2/93    CC        Call InitClipboard().
  138.         <23>    11/16/93    RR        Register stddispatchmodule for
  139.                                     kHighLevelEvent
  140.         <22>    11/15/93    NP        Changed XMPSymbols to ODNameSpaceManager.
  141.         <21>    10/28/93    NP        GetType returns a boolean instead of
  142.                                     throwing an exception.
  143.         <20>    10/22/93    NP        Added session parameter to ODNameResolver
  144.                                     constructor.
  145.         <19>    10/20/93    CC        Added session parameter to ODClipboard
  146.                                     constructor
  147.         <18>     9/20/93    NP        Changed order of ODMessageInterface and
  148.                                     ODNameResolver initialization.
  149.         <17>     8/11/93    RR        Added code to install standard dispatch
  150.                                     module (moved from dispatcher)
  151.         <16>     7/28/93    NP        Added GetSession function.
  152.         <15>     7/21/93    TÇ        change destructor to delete fTokenTable
  153.                                     before deleting fNameSpaceManager (~TokenTable
  154.                                     seemed to need fNameSpaceManager)
  155.         <14>     7/12/93    CG        Added fShellSemtInterface and
  156.                                     AcquireShellSemtInterface() to Session class.
  157.         <13>     6/23/93    RCR        Initialize TokenTable before arbitrator.
  158.         <12>     6/22/93    NP        Added Tokenize methods.
  159.         <11>     5/18/93    NP        Changed call to ODMessageInterface
  160.                                     constructor.
  161.         <10>     4/28/93    NP        File name changes.
  162.          <9>     4/27/93    NP        Uncommented last comments.
  163.          <8>     4/27/93    NP        Commented out the construction of some
  164.                                     objects. Fixed OpenODSession.
  165.          <7>     4/23/93    NP        Removed warning from Purge.
  166.          <6>     4/23/93    NP        Fixed GetStorageSystem.
  167.          <5>     4/23/93    NP        Fixed Purge.
  168.          <4>     4/23/93    NP        Fixed call to ODSemanticInterface
  169.                                     constructor.
  170.          <3>     4/23/93    NP        Fixed Initialize to call Initialize members
  171.                                     for objects it creates. Uncommented
  172.                                     constructor and zeroed out fields in it.
  173.          <2>     4/22/93    RCR        Add Session:: to Initialize. Remove ODMethod
  174.          <1>     4/21/93    NP        first checked in
  175.  
  176.     To Do: 1276569: when name is not found return empty string from GetUserName()
  177. */
  178.  
  179. #ifndef _PLFMDEF_
  180. #include "PlfmDef.h"
  181. #endif
  182.  
  183. #ifndef SOM_ODStorageSystem_xh
  184. #include <ODStor.xh>
  185. #endif
  186.  
  187. #ifndef SOM_ODWindowState_xh
  188. #include <WinStat.xh>
  189. #endif
  190.  
  191. #ifndef SOM_ODDispatcher_xh
  192. #include <Disptch.xh>
  193. #endif
  194.  
  195. #ifndef SOM_ODArbitrator_xh
  196. #include <Arbitrat.xh>
  197. #endif
  198.  
  199. #ifndef SOM_ODInfo_xh
  200. #include <info.xh>
  201. #endif
  202.  
  203. #ifndef SOM_ODTranslation_xh
  204. #include <Translt.xh>
  205. #endif
  206.  
  207. #ifndef SOM_ODClipboard_xh
  208. #include <Clipbd.xh>
  209. #endif
  210.  
  211. #ifndef SOM_ODDragAndDrop_xh
  212. #include <DragDrp.xh>
  213. #endif
  214.  
  215. #ifndef SOM_ODLinkManager_xh
  216. #include <LinkMgr.xh>
  217. #endif
  218.  
  219. #ifndef SOM_ODNameSpaceManager_xh
  220. #include <NmSpcMg.xh>
  221. #endif
  222.  
  223. #ifndef SOM_ODMessageInterface_xh
  224. #include <MssgIntf.xh>
  225. #endif
  226.  
  227. #ifndef SOM_ODNameResolver_xh
  228. #include <NamRslvr.xh>
  229. #endif
  230.  
  231. #ifndef _SIHELPER_
  232. #include "SIHelper.h"
  233. #endif
  234.  
  235. #ifndef SOM_ODUndo_xh
  236. #include <undo.xh>
  237. #endif
  238.  
  239. #ifndef SOM_ODBinding_xh
  240. #include <ODBindng.xh>
  241. #endif
  242.  
  243. #ifndef SOM_Module_OpenDoc_Foci_defined
  244. #include <Foci.xh>
  245. #endif
  246.  
  247. #ifndef _PLFMFILE_
  248. #include <PlfmFile.h>
  249. #endif
  250.  
  251. #ifndef _ODUTILS_
  252. #include <ODUtils.h>
  253. #endif
  254.  
  255. #ifndef _PASCLSTR_
  256. #include "PasclStr.h"
  257. #endif
  258.  
  259. #ifndef _TOKNTABL_
  260. #include "ToknTabl.h"
  261. #endif
  262.  
  263. #ifndef __RESOURCES__
  264. #include <Resources.h>
  265. #endif
  266.  
  267. #ifndef __TEXTUTILS__
  268. #include <TextUtils.h>
  269. #endif
  270.  
  271. #ifndef __TIME_H__
  272. #include <time.h>
  273. #endif
  274.  
  275. #ifndef __SCRIPT__
  276. #include <script.h>
  277. #endif
  278.  
  279. #ifndef __STDLIB__
  280. #include <StdLib.h>
  281. #endif
  282.  
  283. #define ODSession_Class_Source
  284. #define VARIABLE_MACROS
  285. #include <ODSessn.xih>
  286.  
  287. #pragma segment ODSession
  288.  
  289.  
  290. //------------------------------------------------------------------------------
  291. // Globals
  292. //------------------------------------------------------------------------------
  293.  
  294. QDGlobals * const gODQD = kODNULL;        // Declared in PlfmDef.h
  295.  
  296. //------------------------------------------------------------------------------
  297. // Constants
  298. //------------------------------------------------------------------------------
  299.  
  300. #define kMacUserNameResID -16096    // this Macintosh system resource id is not 
  301.                                     // defined in universal headers as of 2/13/95
  302.  
  303. //==============================================================================
  304. // ODSession
  305. //==============================================================================
  306.  
  307. //------------------------------------------------------------------------------
  308. // ODSession: InitSession
  309. //------------------------------------------------------------------------------
  310.  
  311. SOM_Scope void     SOMLINK ODSessionInitSession(ODSession *somSelf, Environment *ev)
  312. {
  313.     ODSessionMethodDebug("ODSession","InitSession");
  314.  
  315.     SOM_TRY
  316.  
  317.     somSelf->InitBaseSession(ev);
  318.     
  319.     // Initialize ODQDGlobals, a pointer to the QuickDraw globals. The variable
  320.     // is declared as const so nobody else can modify it, so to initialize it
  321.     // we have to do some fancy casting. (We can't initialize it statically since
  322.     // the QD globals aren't set up at that point.)
  323.     *(QDGlobals**)&gODQD
  324.         = (QDGlobals*)( *(char**)LMGetCurrentA5()
  325.                                             - sizeof(QDGlobals) + sizeof(GrafPtr));
  326.  
  327.     // Initialize the random number seed for UniqueUpdateID
  328.     srand(time((time_t *) kODNULL));
  329.  
  330.     ODStorageSystem* storageSystem = new ODStorageSystem;
  331.     THROW_IF_NULL(storageSystem);
  332.     storageSystem->InitStorageSystem(ev, somSelf);
  333.     somSelf->SetStorageSystem(ev, storageSystem);
  334.     ODClipboard* clipboard = new ODClipboard;
  335.     THROW_IF_NULL(clipboard);
  336.     clipboard->InitClipboard(ev, somSelf);
  337.     somSelf->SetClipboard(ev, clipboard);
  338.     ODInfo* info = new ODInfo;
  339.     THROW_IF_NULL(info);
  340.     info->InitInfo(ev, somSelf);
  341.     somSelf->SetInfo(ev, info);
  342.     ODLinkManager* linkManager = new ODLinkManager;
  343.     THROW_IF_NULL(linkManager);
  344.     linkManager->InitLinkManager(ev, somSelf);
  345.     somSelf->SetLinkManager(ev, linkManager);
  346.  
  347.     ODTranslation* translation = new ODTranslation;
  348.     THROW_IF_NULL(translation);
  349.     translation->InitTranslation(ev, somSelf);
  350.     somSelf->SetTranslation(ev, translation);
  351.  
  352.     ODNameResolver* nameResolver = new ODNameResolver;
  353.     THROW_IF_NULL(nameResolver);
  354.     nameResolver->InitNameResolver(ev, somSelf);
  355.     somSelf->SetNameResolver(ev, nameResolver);
  356.     ODMessageInterface* messageInterface = new ODMessageInterface;
  357.     THROW_IF_NULL(messageInterface);
  358.     messageInterface->InitMessageInterface(ev, somSelf);
  359.     somSelf->SetMessageInterface(ev, messageInterface);
  360.     
  361.     ODUndo* undo = new ODUndo;
  362.     THROW_IF_NULL(undo);
  363.     undo->InitUndo(ev);
  364.     somSelf->SetUndo(ev, undo);
  365.  
  366.     ODNameSpaceManager* nameSpaceManager = new ODNameSpaceManager;
  367.     THROW_IF_NULL(nameSpaceManager);
  368.     // Note that InitNameSpaceManager needs to ask the session for itself
  369.     //    during init time!
  370.     somSelf->SetNameSpaceManager(ev, nameSpaceManager);
  371.     nameSpaceManager->InitNameSpaceManager(ev, somSelf);
  372.     ODBinding* binding = new ODBinding;
  373.     THROW_IF_NULL(binding);
  374.     somSelf->SetBinding(ev, binding);
  375.     binding->InitBinding(ev, somSelf);
  376.     // Note that InitBinding needs to ask the session for itself
  377.     //    during init time to support the BndNSUtils.
  378.  
  379.     TokenTable* tt = new TokenTable(somSelf->GetNameSpaceManager(ev));
  380.     THROW_IF_NULL(tt);
  381.     tt->Initialize();
  382.     somSelf->SetTokenTable(ev, tt);
  383.  
  384.     ODWindowState* windowState = new ODWindowState; // Must be after token table
  385.     THROW_IF_NULL(windowState);
  386.     windowState->InitWindowState(ev, somSelf); 
  387.     somSelf->SetWindowState(ev, windowState);
  388.     ODDragAndDrop* dragAndDrop = new ODDragAndDrop;
  389.     THROW_IF_NULL(dragAndDrop);
  390.     dragAndDrop->InitDragAndDrop(ev, somSelf); // Must be after Window State
  391.     somSelf->SetDragAndDrop(ev, dragAndDrop);
  392.     ODArbitrator* arbitrator = new ODArbitrator; // Must be after token table
  393.     THROW_IF_NULL(arbitrator);
  394.     arbitrator->InitArbitrator(ev, somSelf);
  395.     somSelf->SetArbitrator(ev, arbitrator);
  396.     ODDispatcher* dispatcher = new ODDispatcher; // Must be after token table
  397.     THROW_IF_NULL(dispatcher);
  398.     // Note that InitDispatcher needs to ask the session for itself
  399.     //    during init time!
  400.     somSelf->SetDispatcher(ev, dispatcher);
  401.     dispatcher->InitDispatcher(ev, somSelf);
  402.  
  403.         // temporary work around for #1239535
  404.     somSelf->GetNameSpaceManager(ev)->SynchNSTable(ev);  // Must be after dispatcher
  405.  
  406.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODKeyFocus),kODNULL);    
  407.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODMenuFocus),kODNULL);    
  408.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODSelectionFocus),kODNULL);    
  409.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODModalFocus),kODNULL);
  410.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODMouseFocus),kODNULL);
  411.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODScrollingFocus),kODNULL);
  412.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODClipboardFocus),kODNULL);
  413.  
  414.     SOM_CATCH_ALL
  415.     SOM_ENDTRY
  416. }
  417. #if 0
  418. //------------------------------------------------------------------------------
  419. // ODSession: ~ODSession
  420. //------------------------------------------------------------------------------
  421.  
  422. SOM_Scope void  SOMLINK ODSessionsomUninit(ODSession *somSelf)
  423. {
  424.     ODSessionMethodDebug("ODSession","somUninit");
  425.  
  426.     ODSession_parents_somUninit(somSelf);
  427. }
  428. #endif /* 0 */
  429. //------------------------------------------------------------------------------
  430. // ODSession: Purge
  431. //------------------------------------------------------------------------------
  432.  
  433. SOM_Scope ODSize  SOMLINK ODSessionPurge(ODSession *somSelf, Environment *ev,
  434.         ODSize size)
  435. {
  436.     ODSessionMethodDebug("ODSession","Purge");
  437.  
  438.     // dh - Wrap all purge calls in a SOM_TRY block. Also aggregate the total of the
  439.     // amount purged in each call and return that value.
  440.     // You might wonder why I wraped each individual call to the session object's Purge
  441.     // method in another nested TRY block. This is necessary because I cannot 
  442.     // guarantee that each session object, which can be replaced or patched, will not
  443.     // throw, thus stopping purging for the other objects. This also makes the code
  444.     // harder to read.
  445.     ODSize purged = 0; ODVolatile( purged );
  446.     
  447.     SOM_TRY
  448.         TRY
  449.             ODArbitrator*    Arbitrator = somSelf->GetArbitrator(ev);
  450.             if (Arbitrator)
  451.                 purged += somSelf->GetArbitrator(ev)->Purge(ev, size);
  452.         CATCH_ALL
  453.         ENDTRY
  454.  
  455.         TRY
  456.             ODBinding*    Binding = somSelf->GetBinding(ev);
  457.             if (Binding)
  458.                 purged += somSelf->GetBinding(ev)->Purge(ev, size);
  459.         CATCH_ALL
  460.         ENDTRY
  461.  
  462.         TRY
  463.             ODClipboard*    Clipboard = somSelf->GetClipboard(ev);
  464.             if (Clipboard)
  465.                 purged += somSelf->GetClipboard(ev)->Purge(ev, size);
  466.         CATCH_ALL
  467.         ENDTRY
  468.  
  469.         TRY
  470.             ODDispatcher*    Dispatcher = somSelf->GetDispatcher(ev);
  471.             if (Dispatcher)
  472.                 purged += somSelf->GetDispatcher(ev)->Purge(ev, size);
  473.         CATCH_ALL
  474.         ENDTRY
  475.  
  476.         TRY
  477.             ODDragAndDrop*    DragAndDrop = somSelf->GetDragAndDrop(ev);
  478.             if (DragAndDrop)
  479.                 purged += somSelf->GetDragAndDrop(ev)->Purge(ev, size);
  480.         CATCH_ALL
  481.         ENDTRY
  482.  
  483.         TRY
  484.             ODLinkManager*    LinkManager = somSelf->GetLinkManager(ev);
  485.             if (LinkManager)
  486.                 purged += somSelf->GetLinkManager(ev)->Purge(ev, size);
  487.         CATCH_ALL
  488.         ENDTRY
  489.  
  490.         TRY
  491.             ODMessageInterface*    MessageInterface = somSelf->GetMessageInterface(ev);
  492.             if (MessageInterface)
  493.                 purged += somSelf->GetMessageInterface(ev)->Purge(ev, size);
  494.         CATCH_ALL
  495.         ENDTRY
  496.  
  497.         TRY
  498.             ODNameResolver*    NameResolver = somSelf->GetNameResolver(ev);
  499.             if (NameResolver)
  500.                 purged += somSelf->GetNameResolver(ev)->Purge(ev, size);
  501.         CATCH_ALL
  502.         ENDTRY
  503.  
  504.         TRY
  505.             ODNameSpaceManager*    NameSpaceManager = somSelf->GetNameSpaceManager(ev);
  506.             if (NameSpaceManager)
  507.                 purged += somSelf->GetNameSpaceManager(ev)->Purge(ev, size);
  508.         CATCH_ALL
  509.         ENDTRY
  510.  
  511.         TRY
  512.             ODStorageSystem*    StorageSystem = somSelf->GetStorageSystem(ev);
  513.             if (StorageSystem)
  514.                 purged += somSelf->GetStorageSystem(ev)->Purge(ev, size);
  515.         CATCH_ALL
  516.         ENDTRY
  517.  
  518.         TRY
  519.             ODTranslation*    Translation = somSelf->GetTranslation(ev);
  520.             if (Translation)
  521.                 purged += somSelf->GetTranslation(ev)->Purge(ev, size);
  522.         CATCH_ALL
  523.         ENDTRY
  524.  
  525.         TRY
  526.             ODUndo*    Undo = somSelf->GetUndo(ev);
  527.             if (Undo)
  528.                 purged += somSelf->GetUndo(ev)->Purge(ev, size);
  529.         CATCH_ALL
  530.         ENDTRY
  531.  
  532.         TRY
  533.             ODWindowState*    WindowState = somSelf->GetWindowState(ev);
  534.             if (WindowState)
  535.                 purged += somSelf->GetWindowState(ev)->Purge(ev, size);
  536.         CATCH_ALL
  537.         ENDTRY
  538.  
  539.  
  540.         purged += parent_Purge(somSelf, ev, size);
  541.     
  542.     SOM_CATCH_ALL
  543.         WARN("Error %ld trying to purge in ODSessionPurge",ErrorCode());
  544.         SetErrorCode(kODNoError);        // Eat the exception; Purge should not 
  545.                                         // propagate it because clients function
  546.                                         // fine whether memory was purged or not.
  547.     SOM_ENDTRY
  548.  
  549.     return purged;
  550. }
  551.  
  552. //------------------------------------------------------------------------------
  553. // ODSession: GetUserName
  554. //------------------------------------------------------------------------------
  555.  
  556. SOM_Scope void  SOMLINK ODSessionGetUserName(ODSession *somSelf, Environment *ev,
  557.         ODIText* name)
  558. {
  559.     ODSessionMethodDebug("ODSession","GetUserName");
  560.  
  561.     StringHandle    userName;
  562.  
  563.     SOM_TRY
  564.         ASSERT(name, kODErrIllegalNullInput);
  565.  
  566.         //ODScriptCode script = GetScriptManagerVariable(smSysScript);
  567.         ODScriptCode script = FontToScript(GetAppFont());
  568.         ODLangCode lang = GetScriptVariable(script, smScriptLang);
  569.  
  570.         name->format = kODTraditionalMacText;
  571.         name->text._buffer = kODNULL;
  572.         SetITextBufferSize(name, sizeof(ODTradITextDataHeader), kODFalse);
  573.         SetITextScriptCode(name, script);
  574.         SetITextLangCode(name, lang);
  575.  
  576.         userName = GetString(kMacUserNameResID);
  577.         if (userName)
  578.         {
  579.             ODLockHandle((ODHandle)userName);
  580.             SetITextString(name, (StringPtr)*userName);
  581. //            name = CreateITextPString(script, lang, (StringPtr)(*userName));    
  582.         
  583.             ODUnlockHandle((ODHandle)userName);
  584.             ReleaseResource((Handle)userName);
  585.         }
  586.         else
  587.             SetITextString(name, "");
  588. //            name = CreateITextPString(script, lang, (StringPtr) "");
  589.         
  590.         *name = *name;
  591.     SOM_CATCH_ALL
  592.     SOM_ENDTRY
  593. }
  594.  
  595. //------------------------------------------------------------------------------
  596. // ODSession: UniqueUpdateID
  597. //------------------------------------------------------------------------------
  598.  
  599. SOM_Scope ODUpdateID  SOMLINK ODSessionUniqueUpdateID(ODSession *somSelf, Environment *ev)
  600. {
  601.     ODSessionMethodDebug("ODSession","UniqueUpdateID");
  602.  
  603.     return (ODUpdateID) rand();
  604. }
  605.