home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / Storage / ScriptID.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  4.3 KB  |  139 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ScriptID.h
  3.  
  4.     Contains:    ScriptingIDManager header
  5.  
  6.     Owned by:    Craig Carper
  7.  
  8.     Copyright:    © 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <1>      11/19/96    CC        first checked in
  13.     To Do:
  14. */
  15.  
  16. #ifndef _SCRIPTID_
  17. #define _SCRIPTID_
  18.  
  19. #ifndef _ODTYPES_
  20. #include <ODTypes.h>
  21. #endif
  22.  
  23. #ifndef _ODMEMORY_
  24. #include "ODMemory.h"
  25. #endif
  26.  
  27. #ifndef SOM_CMDraft_xh
  28. #include <CMDraft.xh>
  29. #endif
  30.  
  31. #ifndef _DRAFPRIV_
  32. #include  "DrafPriv.h"
  33. #endif
  34.  
  35. #ifndef SOM_CMStorageUnit_xh
  36. #include <CMSU.xh>
  37. #endif
  38.  
  39. #ifndef _OPENHASH_
  40. #include "OpenHash.h"
  41. #endif
  42.  
  43. class ODPersistentObject;
  44.  
  45. class ScriptingIDManager 
  46. {
  47. // ScriptingIDManager is a helper class for CMDraft.  It provides a mapping between 
  48. // scripting IDs (known also as persistent IDs) and underlying container manager 
  49. // object IDs.  A table is stored in the draft properties storage unit to allow 
  50. // fast access to an object given a scripting ID.  Scripting IDs are assigned on
  51. // demand, starting from 1.  When retrieving an object from a scripting ID, if
  52. // the scripting ID is unknown the object is located by container manager id; this
  53. // allows existing scripts to work with existing documents.  Existing scripts will
  54. // stop working if targeted frames are moved, and scripts created using OpenDoc 1.2
  55. // will not work on earlier versions of OpenDoc.
  56.  
  57. public:
  58.  
  59.     ScriptingIDManager() { fScriptingTable = kODNULL; }
  60.     
  61.     ~ScriptingIDManager();
  62.  
  63.     void InitScriptingIDManager(Environment* ev,
  64.                             ODMemoryHeapID heapID,
  65.                             CMDraft* draft);
  66.     // Initializes a table mapping scripting ids to persistent objects.
  67.     // This table is stored in the draft properties storage unit.
  68.     // Exceptions thrown: kODErrOutOfMemory.
  69.  
  70.     ODPersistentObjectID GetScriptingID(
  71.                             Environment *ev,
  72.                             CMObjectID objectID);
  73.     // Returns the scripting ID for a persistent object.  If a scripting
  74.     // ID is not already associated with the object, one is assigned and
  75.     // returned.
  76.     // Exceptions thrown: kODErrIllegalNullIDInput.
  77.  
  78.     ODPersistentObject* AcquirePersistentObject(
  79.                             Environment *ev,
  80.                             ODPersistentObjectID scriptingID,
  81.                             ODObjectType* objectType);
  82.     // Returns a persistent object corresponding to a scripting id.
  83.     // The objectType argument is used for consistency checking only,
  84.     // and must be kODFrameObject or kODPartObject.
  85.     // If there are multiple frame objects with the same scripting id,
  86.     // this method returns one with a false in-limbo flag; if all
  87.     // are in-limbo, an kODErrInvalidPersistentObjectID exception is thrown.
  88.     // If the scripting id is found in the table, but the associated container suite
  89.     // object does not exist, the entry is removed from the table and a
  90.     // kODErrInvalidPersistentObjectID exception is returned.
  91.     // If the scripting id cannot be found in the table, the object is located
  92.     // by container suite id.
  93.     // Exceptions thrown: kODErrInvalidObjectType, kODErrIllegalNullIDInput,
  94.     // kODErrInvalidPersistentObjectID.
  95.  
  96.     ODPersistentObjectID TransferScriptingID(
  97.                             Environment* ev,
  98.                             CMObjectID fromCMID,
  99.                             CMObjectID toCMID);
  100.     // Transfers the scripting id from one persistent object to another.
  101.     // Both objects must have an object type of kODFrameObject.
  102.     // If fromCMID has not been assigned a scripting ID, it is assigned one,
  103.     // and the new id transferred to the scripting ID of toCMID.
  104.     // Exceptions thrown: kODErrInvalidObjectType, kODErrOutOfMemory.
  105.  
  106.     void DropScriptingID(Environment* ev,
  107.                             CMObjectID cmid);
  108.     // Removes the entry for cmid from the scripting table. It is not an error
  109.     // to call this method with an object that as not been assigned a scripting id.
  110.     // This method should only be called just before an object is removed from the
  111.     // draft.
  112.     // Exceptions thrown: kODErrInvalidObjectType, kODErrOutOfMemory.
  113.  
  114.     void Save(Environment* ev);
  115.     // Writes the current scripting ID table into the draft properties storage unit.
  116.     // Exceptions thrown: kODErrOutOfMemory.
  117.  
  118. private:
  119.  
  120.     ODBoolean SearchForScriptingID(
  121.                             Environment *ev,
  122.                             CMObjectID objectID,
  123.                             ODPersistentObjectID& persistentID);
  124.  
  125.     ODPersistentObjectID AssignScriptingID(
  126.                             Environment* ev,
  127.                             CMObjectID cmid);
  128.  
  129. protected:
  130.  
  131.     ODBoolean                fDirty;
  132.     CMDraft*                fDraft;
  133.       ODMemoryHeapID             fHeapID;
  134.       ODPersistentObjectID    fLastScriptingID;
  135.     OpenHashTable*            fScriptingTable;
  136. };
  137.  
  138. #endif    // _SCRIPTID_
  139.