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 / NmSpcMg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  14.3 KB  |  486 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        NmSpcMg.cpp
  3.  
  4.     Contains:    Implementation of ODNameSpaceManager class
  5.  
  6.     Owned by:    David McCusker
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>     6/22/96    EL        1355350: DeleteNameSpace does not remove
  13.                                     namespace as parent
  14.         <21>     8/29/95    DM        1279569: check nil for new SOM instances
  15.         <20>     8/26/95    TÇ        1274606 FB2: Patching Remarks
  16.         <19>     8/25/95    JP        1272288: Added GetAETEs
  17.         <18>      8/3/95    RR        #1257260: Collapse B classes. Remove
  18.                                     somInit methods. Don't call IsInitialized
  19.                                     or SubclassResponsibility
  20.         <17>     7/27/95    DM        #1270320: Mem leaks: temp name in
  21.                                     DeleteNameSpace
  22.         <16>     7/24/95    CG        #1270320: Memory leak fixes.
  23.         <15>     5/25/95    jpa        Return of <12>: HasNameSpace will call
  24.                                     SynchNSTable if the namespace is synched to
  25.                                     the Editors folders. SynchNSTable now
  26.                                     returns a Boolean.  [1240150]
  27.         <14>     5/18/95    CG        #1241621    BB: Need to implement Purge for
  28.                                     Binding subsystem objects.
  29.         <13>     5/17/95    TJ        Backed out changes from previous checkin.
  30.         <11>     5/11/95    DM        #1181622: Updated file ownership.
  31.         <10>     4/26/95    CG        1211082 BB: 5$ Bugs need to be evaluated
  32.                                     and removed from Core
  33.          <9>     4/25/95    DM        1172791: Replace AEHashTable with
  34.                                     OpenHashTable
  35.          <8>      4/6/95    TJ        Fixed Compile Errors.
  36.          <7>      4/5/95    CG        #1216169 BB, #1221135: When Editors folder
  37.                                     or OpenDoc Libraries folder is missing,
  38.                                     OpenDoc quits and displays error.
  39.          <6>     2/14/95    TJ        Fixed copyright date.
  40.          <5>     2/14/95    jpa        Preferences::LoadAnyNewEditors -->
  41.                                     ScanLibsAndEditors [1205141]
  42.          <4>     1/23/95    CG        #1195019: Added field for tracking maximum
  43.                                     length of strings in value name spaces.
  44.          <3>     8/24/94    CG        #1181622: Updated file ownership.
  45.          <2>     8/17/94    CG        #1178378: Destructor now deletes all name
  46.                                     spaces.
  47.          <1>     7/29/94    CG        first checked in
  48.          <3>     6/28/94    VL        Used Translt.xh.
  49.          <2>     6/24/94    CG        SOMized.
  50.          <1>     6/14/94    CG        first checked in
  51.         --------------------------------------------------------------
  52.          <8>      6/1/94    CG        Added fPreferences and associated getters.
  53.          <7>     5/27/94    jpa        New exception support [1165267]
  54.          <6>     5/27/94    CG        #1165186: Abstracted prefs out of binding.
  55.          <5>      5/9/94    MB        #1162181: Changes necessary to install MMM.
  56.          <4>     3/26/94    NP        1152831. Add private stuff.
  57.          <3>     3/15/94    MB        Changes to support SCpp/ASLM builds,
  58.                                     #1150864.
  59.          <2>     2/15/94    CG        #1143680 - NameSpaceManager now being
  60.                                     allocated on specified heap.
  61.          <7>      2/8/94    TÇ        Throw -> THROW & some code clean up
  62.          <6>      2/3/94    CG        System Session break out.
  63.          <5>     1/29/94    NP        Init changes and changed parameters of
  64.                                     CreateNameSpace.
  65.          <4>     1/21/94    CG        More NMAP changes.
  66.          <3>     1/18/94    CG        Changes for new NMAP and for new
  67.                                     XMPNameSpace::GetValue().
  68.          <2>     1/18/94    TÇ        use kOpenDocShellSignature
  69.          <1>     1/14/94    CG        first checked in
  70.     To Do:
  71.     In Progress:
  72. */
  73.  
  74.  
  75. #ifndef _PLFMDEF_
  76. #include "PlfmDef.h"
  77. #endif
  78.  
  79. #define ODNameSpaceManager_Class_Source
  80. #define VARIABLE_MACROS
  81. #include <NmSpcMg.xih>
  82.  
  83. #ifndef SOM_ODNameSpace_xh
  84. #include <NamSpac.xh>
  85. #endif
  86.  
  87. #ifndef SOM_ODObjectNameSpace_xh
  88. #include <ObjectNS.xh>
  89. #endif
  90.  
  91. #ifndef SOM_ODValueNameSpace_xh
  92. #include <ValueNS.xh>
  93. #endif
  94.  
  95. #ifndef SOM_ODObjectIterator_xh
  96. #include <ObjctItr.xh>
  97. #endif
  98.  
  99. #ifndef _STRHSHTB_
  100. #include "StrHshTb.h"
  101. #endif
  102.  
  103. #ifndef _ODTYPES_
  104. #include <ODTypes.h>
  105. #endif
  106.  
  107. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  108. #include <StdDefs.xh>
  109. #endif
  110.  
  111. #ifndef SOM_ODTranslation_xh
  112. #include <Translt.xh>
  113. #endif
  114.  
  115. #ifndef _ODMEMORY_
  116. #include "ODMemory.h"
  117. #endif
  118.  
  119. #ifndef _ISOSTR_
  120. #include "ISOStr.h"
  121. #endif
  122.  
  123. #ifndef _EXCEPT_
  124. #include "Except.h"
  125. #endif
  126.  
  127. #ifndef SOM_ODSession_xh
  128. #include "ODSessn.xh"
  129. #endif
  130.  
  131. #ifndef _PREFS_
  132. #include "Prefs.h"
  133. #endif
  134.  
  135. #ifndef __STRING__
  136. #include <String.h>
  137. #endif
  138.  
  139. #ifndef _ODUTILS_
  140. #include <ODUtils.h>
  141. #endif
  142.  
  143. #ifndef _TEMPOBJ_
  144. #include <TempObj.h>
  145. #endif
  146.  
  147. #pragma segment ODNameSpaceManager
  148.  
  149. #include "NmSpcMgB.cpp"    // Platform-independent methods, if any
  150.  
  151. #define RegisterNameSpaceTable 0
  152.  
  153. //==============================================================================
  154. // Constants
  155. //==============================================================================
  156.  
  157. const ODULong kNumExpectedNameSpaces = 10;
  158.  
  159. //==============================================================================
  160. // ODNameSpaceManager
  161. //==============================================================================
  162.  
  163. //------------------------------------------------------------------------------
  164. // ODNameSpaceManager: InitNameSpaceManager
  165. //------------------------------------------------------------------------------
  166.  
  167. SOM_Scope void  SOMLINK ODNameSpaceManagerInitNameSpaceManager(ODNameSpaceManager *somSelf, Environment *ev,
  168.         ODSession* session)
  169. {
  170.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  171.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","InitNameSpaceManager");
  172.  
  173.     SOM_TRY
  174.  
  175.     /* Moved from somInit. SOM itself sets fields to zero
  176.     _fNameSpaceTable = kODNULL;
  177.     _fPreferences = kODNULL;
  178.     _fMaxISOStrLength = 0;
  179.     */
  180.     somSelf->InitObject(ev);
  181.         
  182.     _fSession = session;
  183.  
  184.     _fNameSpaceTable = new ODObjectNameSpace;
  185.     THROW_IF_NULL(_fNameSpaceTable); // check all SOM new's for nil
  186.  
  187.     { TempODISOStr    objName = ODISOStrFromCStr("NameSpaceTable");
  188.       _fNameSpaceTable->InitObjectNameSpace(ev, somSelf, kODNULL, 
  189.                                 kNumExpectedNameSpaces, objName);
  190. #if RegisterNameSpaceTable
  191.       _fNameSpaceTable->Register(ev, objName, (ODObject*)_fNameSpaceTable);
  192. #endif
  193.     }
  194.     
  195.     _fPreferences = new Preferences();
  196.     _fPreferences->InitPreferences(session);
  197.  
  198.     SOM_CATCH_ALL
  199.     SOM_ENDTRY
  200. }
  201.  
  202. //------------------------------------------------------------------------------
  203. // ODNameSpaceManager: HasNameSpace
  204. //------------------------------------------------------------------------------
  205.  
  206. SOM_Scope ODNameSpace*  SOMLINK ODNameSpaceManagerHasNameSpace(ODNameSpaceManager *somSelf, Environment *ev,
  207.         ODISOStr spaceName)
  208. {
  209.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  210.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","HasNameSpace");
  211.  
  212.     ODNameSpace*     theNameSpace = kODNULL;
  213.  
  214.     SOM_TRY
  215.         // Look in namespace table for spacename
  216.     _fNameSpaceTable->GetEntry (ev, spaceName, (ODObject**)&theNameSpace);
  217.             
  218.     // If this namespace is read from the Editors folder(s), make sure the namespaces
  219.     // are synched to the current Editors folder(s):
  220.     if( theNameSpace && theNameSpace->IsSynchedToEditors(ev) )
  221.         if( somSelf->SynchNSTable(ev) ) {
  222.             // Synching causes the namespaces to be recreated, so the pointer is
  223.             // no longer valid. Get a new pointer:
  224.             _fNameSpaceTable->GetEntry (ev, spaceName, (ODObject**)&theNameSpace);
  225.         }
  226.             
  227.     SOM_CATCH_ALL
  228.     SOM_ENDTRY
  229.  
  230.     return theNameSpace;
  231. }
  232.  
  233.  
  234.  
  235. //------------------------------------------------------------------------------
  236. // ODNameSpaceManager: ~ODNameSpaceManager
  237. //------------------------------------------------------------------------------
  238.  
  239. SOM_Scope void  SOMLINK ODNameSpaceManagersomUninit(ODNameSpaceManager *somSelf)
  240. {
  241.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  242.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","somUninit");
  243.  
  244.     Environment* ev = somGetGlobalEnvironment();
  245.     
  246.     // $opt: SOM_TRY should not be necessary around deletions and another somUninit.
  247.     SOM_TRY
  248.     
  249. #if RegisterNameSpaceTable
  250.         { TempODISOStr name = _fNameSpaceTable->GetName(ev);
  251.           _fNameSpaceTable->Unregister(ev, name);
  252.         }
  253. #endif
  254.     
  255.         ODDeleteObject( _fNameSpaceTable );
  256.     
  257.         ODDeleteObject( _fPreferences );
  258.  
  259.     ODNameSpaceManager_parent_ODObject_somUninit(somSelf);
  260.  
  261.     SOM_CATCH_ALL
  262.     SOM_ENDTRY
  263. }
  264.  
  265. //------------------------------------------------------------------------------
  266. // ODNameSpaceManager: Purge
  267. //------------------------------------------------------------------------------
  268.  
  269. SOM_Scope ODSize  SOMLINK ODNameSpaceManagerPurge(ODNameSpaceManager *somSelf, Environment *ev,
  270.         ODSize size)
  271. {
  272.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  273.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","Purge");
  274.  
  275.     ODSize    purgeSize = 0; ODVolatile( purgeSize );
  276.     
  277.     SOM_TRY
  278.  
  279.         purgeSize = _fPreferences->Purge(size);
  280.         purgeSize += parent_Purge( somSelf, ev, size );
  281.     SOM_CATCH_ALL
  282.         WARN("Error %ld trying to purge in ODNameSpaceManagerPurge",ErrorCode());
  283.         SetErrorCode(kODNoError);        // dh - Eat the exception; Purge should not 
  284.                                         // propagate it because clients function
  285.                                         // fine whether memory was purged or not.
  286.     SOM_ENDTRY
  287.  
  288.     return purgeSize;
  289. }
  290.  
  291. //------------------------------------------------------------------------------
  292. // ODNameSpaceManager: CreateNameSpace
  293. //------------------------------------------------------------------------------
  294.  
  295. SOM_Scope ODNameSpace*  SOMLINK ODNameSpaceManagerCreateNameSpace(ODNameSpaceManager *somSelf, Environment *ev,
  296.         
  297.                                             ODISOStr        spaceName,
  298.                                             ODNameSpace*    inheritsFrom,
  299.                                             ODULong            numExpectedEntries,
  300.                                             ODNSTypeSpec    type)
  301. {
  302.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  303.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","CreateNameSpace");
  304.  
  305.     ODNameSpace* nameSpace = kODNULL;
  306.  
  307.     SOM_TRY
  308.  
  309.     nameSpace = somSelf->HasNameSpace(ev,spaceName);
  310.     if ( nameSpace )
  311.         //THROW(kODErrKeyAlreadyExists);
  312.         nameSpace = (ODNameSpace*)kODNULL;
  313.     else
  314.     {
  315.         switch (type)
  316.         {
  317.             case kODNSDataTypeODObject:
  318.             {
  319.                 ODObjectNameSpace* objNameSpace = new ODObjectNameSpace;
  320.                 THROW_IF_NULL(objNameSpace); // check all SOM new's for nil
  321.                 objNameSpace->InitObjectNameSpace(ev,somSelf, inheritsFrom,
  322.                                             numExpectedEntries, spaceName);
  323.                 _fNameSpaceTable->Register(ev, spaceName, (ODObject*)objNameSpace);
  324.                 nameSpace = (ODNameSpace*) objNameSpace;
  325.                 break;
  326.             }
  327.  
  328.             case kODNSDataTypeODValue:
  329.             {
  330.                 ODValueNameSpace* valNameSpace = new ODValueNameSpace;
  331.                 THROW_IF_NULL(valNameSpace); // check all SOM new's for nil
  332.                 valNameSpace->InitValueNameSpace(ev,somSelf, inheritsFrom,
  333.                                             numExpectedEntries, spaceName);
  334.                 _fNameSpaceTable->Register(ev, spaceName, (ODObject*)valNameSpace);
  335.                 nameSpace =  (ODNameSpace*) valNameSpace;
  336.                 break;
  337.             }
  338.                 
  339.             default:
  340.             {
  341.                 nameSpace = (ODNameSpace*)kODNULL;
  342.                 break;
  343.             }
  344.         }
  345.     }
  346.  
  347.     SOM_CATCH_ALL
  348.     SOM_ENDTRY
  349.     return nameSpace;
  350. }
  351.  
  352.  
  353. //------------------------------------------------------------------------------
  354. // ODNameSpaceManager: DeleteNameSpace
  355. //------------------------------------------------------------------------------
  356.  
  357. SOM_Scope void  SOMLINK ODNameSpaceManagerDeleteNameSpace(ODNameSpaceManager *somSelf, Environment *ev,
  358.         ODNameSpace* nameSpace)
  359. {
  360.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  361.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","DeleteNameSpace");
  362.  
  363.     ODISOStr                nsName;
  364.     ODObject*                nsObject;
  365.     ODULong                    length;
  366.  
  367.     
  368.     SOM_TRY
  369.  
  370.     { TempODISOStr name = nameSpace->GetName(ev);
  371.       _fNameSpaceTable->Unregister(ev, name);
  372.     }
  373.  
  374.     ODObjectIterator*    iter = _fNameSpaceTable->CreateIterator(ev);
  375.     for (iter->First(ev, &nsName, &nsObject, &length);
  376.             iter->IsNotComplete(ev);
  377.             iter->Next(ev, &nsName, &nsObject, &length))
  378.     {
  379.         if (ODObjectsAreEqual(ev, ((ODNameSpace*)nsObject)->GetParent(ev), nameSpace))
  380.             ((ODObjectNameSpace*)nsObject)->NotifyDying(ev, nameSpace);
  381.     }
  382.     
  383.     ODDeleteObject( iter );
  384.  
  385.     ODDeleteObject( nameSpace );
  386.  
  387.     SOM_CATCH_ALL
  388.     SOM_ENDTRY
  389. }
  390.  
  391.  
  392. //------------------------------------------------------------------------------
  393. // ODNameSpaceManager: GetPreferences
  394. //------------------------------------------------------------------------------
  395.  
  396. SOM_Scope Preferences*  SOMLINK ODNameSpaceManagerGetPreferences(ODNameSpaceManager *somSelf, Environment *ev)
  397. {
  398.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  399.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","GetPreferences");
  400.  
  401.     return _fPreferences;
  402. }
  403.  
  404. //------------------------------------------------------------------------------
  405. // ODNameSpaceManager: SynchNSTable
  406. //------------------------------------------------------------------------------
  407.  
  408. SOM_Scope ODBoolean  SOMLINK ODNameSpaceManagerSynchNSTable(ODNameSpaceManager *somSelf, Environment *ev)
  409. {
  410.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  411.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","SynchNSTable");
  412.  
  413.     ODBoolean result = kODFalse;
  414.     
  415.     SOM_TRY
  416.  
  417.     result = _fPreferences->ScanLibsAndEditors();
  418.  
  419.     SOM_CATCH_ALL
  420.     SOM_ENDTRY
  421.     
  422.     return result;
  423. }
  424.  
  425. //------------------------------------------------------------------------------
  426. // ODNameSpaceManager: UpdatePreferences
  427. //------------------------------------------------------------------------------
  428.  
  429. SOM_Scope void  SOMLINK ODNameSpaceManagerUpdatePreferences(ODNameSpaceManager *somSelf, Environment *ev)
  430. {
  431.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  432.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","UpdatePreferences");
  433.  
  434.     SOM_TRY
  435.  
  436.     _fPreferences->UpdatePreferences();
  437.  
  438.     SOM_CATCH_ALL
  439.     SOM_ENDTRY
  440. }
  441.  
  442. //------------------------------------------------------------------------------
  443. // ODNameSpaceManager: GetMaxISOStrLength
  444. //------------------------------------------------------------------------------
  445.  
  446. SOM_Scope ODULong  SOMLINK ODNameSpaceManagerGetMaxISOStrLength(ODNameSpaceManager *somSelf, Environment *ev)
  447. {
  448.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  449.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","GetMaxISOStrLength");
  450.  
  451.     return _fMaxISOStrLength;
  452. }
  453.  
  454. //------------------------------------------------------------------------------
  455. // ODNameSpaceManager: SetMaxISOStrLength
  456. //------------------------------------------------------------------------------
  457.  
  458. SOM_Scope void  SOMLINK ODNameSpaceManagerSetMaxISOStrLength(ODNameSpaceManager *somSelf, Environment *ev,
  459.     ODULong newLength)
  460. {
  461.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  462.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","SetMaxISOStrLength");
  463.  
  464.     _fMaxISOStrLength = newLength;
  465. }
  466.  
  467. //------------------------------------------------------------------------------
  468. // ODNameSpaceManager: GetAETEs
  469. //------------------------------------------------------------------------------
  470.  
  471. SOM_Scope void  SOMLINK ODNameSpaceManagerGetAETEs(ODNameSpaceManager *somSelf, Environment *ev, 
  472.         ODSLong languageCode, AEDescList* aeteList)
  473. {
  474.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  475.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","GetAETEs");
  476.  
  477.     SOM_TRY
  478.  
  479.     _fPreferences->GetAETEs(languageCode, aeteList);
  480.  
  481.     SOM_CATCH_ALL
  482.     SOM_ENDTRY
  483. }
  484.  
  485.  
  486.