home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ScriptID.h
-
- Contains: ScriptingIDManager header
-
- Owned by: Craig Carper
-
- Copyright: © 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <1> 11/19/96 CC first checked in
- To Do:
- */
-
- #ifndef _SCRIPTID_
- #define _SCRIPTID_
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef SOM_CMDraft_xh
- #include <CMDraft.xh>
- #endif
-
- #ifndef _DRAFPRIV_
- #include "DrafPriv.h"
- #endif
-
- #ifndef SOM_CMStorageUnit_xh
- #include <CMSU.xh>
- #endif
-
- #ifndef _OPENHASH_
- #include "OpenHash.h"
- #endif
-
- class ODPersistentObject;
-
- class ScriptingIDManager
- {
- // ScriptingIDManager is a helper class for CMDraft. It provides a mapping between
- // scripting IDs (known also as persistent IDs) and underlying container manager
- // object IDs. A table is stored in the draft properties storage unit to allow
- // fast access to an object given a scripting ID. Scripting IDs are assigned on
- // demand, starting from 1. When retrieving an object from a scripting ID, if
- // the scripting ID is unknown the object is located by container manager id; this
- // allows existing scripts to work with existing documents. Existing scripts will
- // stop working if targeted frames are moved, and scripts created using OpenDoc 1.2
- // will not work on earlier versions of OpenDoc.
-
- public:
-
- ScriptingIDManager() { fScriptingTable = kODNULL; }
-
- ~ScriptingIDManager();
-
- void InitScriptingIDManager(Environment* ev,
- ODMemoryHeapID heapID,
- CMDraft* draft);
- // Initializes a table mapping scripting ids to persistent objects.
- // This table is stored in the draft properties storage unit.
- // Exceptions thrown: kODErrOutOfMemory.
-
- ODPersistentObjectID GetScriptingID(
- Environment *ev,
- CMObjectID objectID);
- // Returns the scripting ID for a persistent object. If a scripting
- // ID is not already associated with the object, one is assigned and
- // returned.
- // Exceptions thrown: kODErrIllegalNullIDInput.
-
- ODPersistentObject* AcquirePersistentObject(
- Environment *ev,
- ODPersistentObjectID scriptingID,
- ODObjectType* objectType);
- // Returns a persistent object corresponding to a scripting id.
- // The objectType argument is used for consistency checking only,
- // and must be kODFrameObject or kODPartObject.
- // If there are multiple frame objects with the same scripting id,
- // this method returns one with a false in-limbo flag; if all
- // are in-limbo, an kODErrInvalidPersistentObjectID exception is thrown.
- // If the scripting id is found in the table, but the associated container suite
- // object does not exist, the entry is removed from the table and a
- // kODErrInvalidPersistentObjectID exception is returned.
- // If the scripting id cannot be found in the table, the object is located
- // by container suite id.
- // Exceptions thrown: kODErrInvalidObjectType, kODErrIllegalNullIDInput,
- // kODErrInvalidPersistentObjectID.
-
- ODPersistentObjectID TransferScriptingID(
- Environment* ev,
- CMObjectID fromCMID,
- CMObjectID toCMID);
- // Transfers the scripting id from one persistent object to another.
- // Both objects must have an object type of kODFrameObject.
- // If fromCMID has not been assigned a scripting ID, it is assigned one,
- // and the new id transferred to the scripting ID of toCMID.
- // Exceptions thrown: kODErrInvalidObjectType, kODErrOutOfMemory.
-
- void DropScriptingID(Environment* ev,
- CMObjectID cmid);
- // Removes the entry for cmid from the scripting table. It is not an error
- // to call this method with an object that as not been assigned a scripting id.
- // This method should only be called just before an object is removed from the
- // draft.
- // Exceptions thrown: kODErrInvalidObjectType, kODErrOutOfMemory.
-
- void Save(Environment* ev);
- // Writes the current scripting ID table into the draft properties storage unit.
- // Exceptions thrown: kODErrOutOfMemory.
-
- private:
-
- ODBoolean SearchForScriptingID(
- Environment *ev,
- CMObjectID objectID,
- ODPersistentObjectID& persistentID);
-
- ODPersistentObjectID AssignScriptingID(
- Environment* ev,
- CMObjectID cmid);
-
- protected:
-
- ODBoolean fDirty;
- CMDraft* fDraft;
- ODMemoryHeapID fHeapID;
- ODPersistentObjectID fLastScriptingID;
- OpenHashTable* fScriptingTable;
- };
-
- #endif // _SCRIPTID_
-