home *** CD-ROM | disk | FTP | other *** search
- /*
- File: BndNSUtl.cpp
-
- Contains: Binding Namespace Utilities
-
- Owned by: Reggie Adkins
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <6> 7/16/96 RA Compile stand alone
- <5> 6/27/96 TJ Added GetgBinding to enable others to get
- the binding session.
- <4> 6/24/96 RA T10025: Adjustments for CORBA compliant
- API.
- <3> 6/21/96 RA T10025: Deprecated most utils for
- implementors, obsoleted most for parts
- <2> 5/23/96 RA 1330687: BndNSUtl should use
- platformFile->read instead of FSRead
-
- To Do:
- */
-
- #ifndef _BNDNSUTL_
- #include "BndNSUtl.h"
- #endif
-
- #ifndef _EDITRSET_
- #include "EditrSet.h"
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef _STORAGEU_
- #include "StorageU.xh"
- #endif
-
- #ifndef _STDDEFS_
- #include "StdDefs.xh"
- #endif
-
- #ifndef _STDPROPS_
- #include "StdProps.xh"
- #endif
-
- #ifndef _STDTYPES_
- #include "StdTypes.xh"
- #endif
-
- #ifndef _PART_
- #include "Part.xh"
- #endif
-
- #ifndef SOM_ODValueIterator_xh
- #include <ValueItr.xh>
- #endif
-
- #ifndef SOM_ODObjectIterator_xh
- #include <ObjctItr.xh>
- #endif
-
- #ifndef _ISOSTR_
- #include "ISOStr.h"
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- //#ifndef SOM_ODNameSpaceManager_xh
- //#include <NmSpcMg.xh>
- //#endif
-
- #ifndef SOM_ODTypeList_xh
- #include <TypeList.xh>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _UTILERRS_
- #include <UtilErrs.h>
- #endif
-
- #ifndef SOM_ODTypeListIterator_xh
- #include <TypLsItr.xh>
- #endif
-
- #ifndef SOM_ODBinding_xh
- #include <ODBindng.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #include <somcls.xh>
- #include <somcm.xh>
-
- ODStatic ODBinding* gBinding = kODNULL;
- ODStatic ODSession* gSession = kODNULL;
-
- //------------------------------------------------------------------------------
- // InitBindingNamespaceUtils
- //------------------------------------------------------------------------------
- // New in OD 1.1, you must call this before calling any of the routines
- // below that take an ODNameSpaceManager* as a param.
- // These routines have been reimplemented as methods on the ODBinding object.
- // The routines below are deprecated in OD 1.1. Their new implementation will
- // work but you should really be calling the new ODBinding API's directly.
- // If you want to use these depricated routines to afford a degree of source
- // compatibility, you must add a call to InitBindingNamespaceUtils before
- // making any calls to these utils.
-
- void InitBindingNamespaceUtils(ODSession* session)
- {
- ASSERT_NOT_NULL(session);
-
- Environment* ev = somGetGlobalEnvironment();
-
- gSession = session;
- gBinding = session->GetBinding(ev);
- }
-
- ODBinding* GetgBinding()
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- return gBinding;
- }
- #ifdef _OD_IMPL_
-
- //------------------------------------------------------------------------------
- // GetSysPrefEditorForKind
- //------------------------------------------------------------------------------
- // Returns the system-wide preferred editor for the argument data kind.
- // A null value is returned if no preference has been specified.
- // This routine checks to ensure that the preferred editor actually exists;
- // if it does not, the preference is canceled and null is returned.
-
- ODEditor GetSysPrefEditorForKind(ODNameSpaceManager* theNmSpcMgr,
- ODType kind)
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
-
- return gBinding->GetSysPrefEditorForKind(ev, (ODKind)kind);
- }
-
- //------------------------------------------------------------------------------
- // GetSysPrefEditorForCategory
- //------------------------------------------------------------------------------
- ODEditor GetSysPrefEditorForCategory(ODNameSpaceManager* theNmSpcMgr,
- ODType category)
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
-
- return gBinding->GetSysPrefEditorForCategory(ev, category);
- }
-
- //------------------------------------------------------------------------------
- // SetSysPrefEditorForKind
- //------------------------------------------------------------------------------
- ODEditor SetSysPrefEditorForKind(ODNameSpaceManager* theNmSpcMgr,
- ODType kind, ODEditor editorString)
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
-
- return gBinding->SetSysPrefEditorForKind(ev, editorString, kind);
- }
-
- //------------------------------------------------------------------------------
- // SetSysPrefEditorForCategory
- //------------------------------------------------------------------------------
- ODEditor SetSysPrefEditorForCategory(ODNameSpaceManager* theNmSpcMgr,
- ODType category,ODEditor editorString)
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
-
- return gBinding->SetSysPrefEditorForCategory(ev, editorString, category);
- }
-
- //------------------------------------------------------------------------------
- // GetCategoriesOfKind
- //
- // lookup kind in kindcategory namespace and return categories supported
- //------------------------------------------------------------------------------
-
- ODTypeList* GetCategoriesOfKind(ODNameSpaceManager* theNmSpcMgr,
- ODType kind)
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
-
- return gBinding->GetAllCategoriesForKind(ev, kind);
- }
-
- #endif
-
- //------------------------------------------------------------------------------
- // GetUserKindFromKind
- //------------------------------------------------------------------------------
- ODBoolean GetUserKindFromKind( ODNameSpaceManager* theNmSpcMgr,
- ODType kind, ODName** name )
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
-
- ODName* userString = new ODName;
-
- ODBoolean result = gBinding->GetUserStringForKind(ev, kind, userString);
-
- *name = userString;
-
- return result;
- }
-
-
- //------------------------------------------------------------------------------
- // GetUserEditorFromEditor
- //------------------------------------------------------------------------------
- ODBoolean GetUserEditorFromEditor( ODNameSpaceManager* theNmSpcMgr,
- ODEditor editor, ODName** name )
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
-
- ODName* userString = new ODName;
-
- ODBoolean result = gBinding->GetUserStringForEditor(ev, editor, userString);
-
- *name = userString;
-
- return result;
- }
-
-
- //------------------------------------------------------------------------------
- // GetUserCatFromCat
- //------------------------------------------------------------------------------
- ODBoolean GetUserCatFromCat( ODNameSpaceManager* theNmSpcMgr,
- ODType category, ODName** name )
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
-
- ODName* userString = new ODName;
-
- ODBoolean result = gBinding->GetUserStringForCategory(ev, category, userString);
-
- *name = userString;
-
- return result;
- }
-
- #ifdef _OD_IMPL_
-
- //------------------------------------------------------------------------------
- // ODGetODOSTypeForKind
- //------------------------------------------------------------------------------
- ODOSType ODGetODOSTypeForKind(ODNameSpaceManager* theNmSpcMgr,
- ODType kind)
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
-
- return gBinding->GetODOSTypeForKind(ev,kind);
- }
-
- //------------------------------------------------------------------------------
- // EditorSupportsKind
- //------------------------------------------------------------------------------
- ODBoolean EditorSupportsKind( ODNameSpaceManager* theNmSpcMgr,
- ODEditor editor, ODType kind )
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
-
- return gBinding->EditorSupportsKind(ev,editor,kind);
- }
-
-
- //------------------------------------------------------------------------------
- // GetAllEditorsForCategory
- //
- // lookup kinds in editorkinds namespace and return editors supported
- //------------------------------------------------------------------------------
-
- ODBoolean GetAllEditorsForCategory( ODNameSpaceManager* theNmSpcMgr,
- ODType category, EditorSet* theEditorSet )
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
- ODTypeList* editorList = gSession->GetStorageSystem(ev)->CreateTypeList(ev,kODNULL);
- ODBoolean retVal = kODFalse;
-
- retVal = gBinding->GetAllEditorsForCategory(ev,category,editorList);
-
- //For each element in editorList, add to theEditorSet for compatibility
- if (editorList)
- {
- ODTypeListIterator* iter = editorList->CreateTypeListIterator(ev) ;
- for (ODEditor editor = iter->First(ev);
- iter->IsNotComplete(ev);
- editor = iter->Next(ev))
- {
- theEditorSet->AddEditor(editor);
- retVal = kODTrue;
- }
- ODDeleteObject( iter );
- }
- ODDeleteObject( editorList );
-
- return retVal;
- }
-
-
- //------------------------------------------------------------------------------
- // GetAllEditorsForKind
- //
- // lookup kinds in editorkinds namespace and return editors supported
- //------------------------------------------------------------------------------
-
- ODBoolean GetAllEditorsForKind(ODNameSpaceManager* theNmSpcMgr,
- ODType kind, EditorSet* theEditorSet)
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
- ODTypeList* editorList = gSession->GetStorageSystem(ev)->CreateTypeList(ev,kODNULL);
- ODBoolean retVal = kODFalse;
-
- retVal = gBinding->GetAllEditorsForKind(ev,kind,editorList);
-
- //For each element in editorList, add to theEditorSet for compatibility
- if (editorList)
- {
- // iterate through editorKinds typelist
- ODTypeListIterator* iter = editorList->CreateTypeListIterator(ev) ;
- for (ODEditor editor = iter->First(ev);
- iter->IsNotComplete(ev);
- editor = iter->Next(ev))
- {
- theEditorSet->AddEditor(editor);
- retVal = kODTrue;
- }
-
- ODDeleteObject( iter );
- }
- ODDeleteObject( editorList );
-
- return retVal;
- }
-
- //------------------------------------------------------------------------------
- // GetAllKindsForEditor
- //------------------------------------------------------------------------------
-
- void GetAllKindsForEditor(ODNameSpaceManager* theNmSpcMgr,
- ODTypeList* kindsList, ODEditor editor)
- {
- ASSERTM(gBinding, kODErrAssertionFailed, "Need to call InitBindingNamespaceUtils first");
-
- Environment* ev = somGetGlobalEnvironment();
-
- gBinding->GetAllKindsForEditor(ev,editor,kindsList);
- }
-
- //------------------------------------------------------------------------------
- // ReadSize
- //------------------------------------------------------------------------------
-
- ODULong ReadSize(PlatformFile* file, ODStorageUnitView* view)
- {
- ODULong data;
- ODSLong length = sizeof(data);
- ODSLong savedLength = length;
- Environment* ev = somGetGlobalEnvironment ();
-
- if (view)
- length = StorageUnitViewGetValue(view, ev, length, &data);
- else
- file->Read(&data, &length);
-
- if (savedLength != length)
- THROW(kODErrReadErr);
-
- return data;
- }
-
- //------------------------------------------------------------------------------
- // ReadBytes
- //------------------------------------------------------------------------------
-
- void ReadBytes(PlatformFile* file, ODStorageUnitView* view,
- ODPtr bytes, ODULong* length)
- {
- ODSLong savedLength = *length;
- Environment* ev = somGetGlobalEnvironment ();
-
- if (view)
- *length = StorageUnitViewGetValue(view, ev, *length, bytes);
- else
- file->Read(bytes, (long*)length);
-
- if (savedLength != (ODSLong)*length)
- THROW(kODErrReadErr);
- }
-
- #endif
-
- //------------------------------------------------------------------------------
- // ODGetEditorSetFromResFile
- //------------------------------------------------------------------------------
-
- EditorSet* ODGetEditorSetFromResFile(ODSShort resRefNum)
- {
- EditorSet* theEditorSet = kODNULL;
- ODBoolean editorFound = kODFalse;
-
- if( resRefNum != -1 ) {
- TRY{
- LOG("* Reading 'nmap's from file %hd\n",resRefNum);
- ODSShort nmapCount = Count1Resources( kODNameMappings );
- for (short i=1; i<=nmapCount; i++)
- {
- // Get the Resource
- ODHandle nmap = (ODHandle)Get1IndResource(kODNameMappings, i);
- ODError result = ResError();
-
- if ( nmap != nil && !result )
- {
- ODLockHandle((ODHandle) nmap);
-
- theEditorSet = ODGetEditorSetFromNMAP(nmap);
-
- ReleaseResource( nmap );
- }
-
- if (theEditorSet)
- break;
- }
- }CATCH_ALL{
- WARN("Error %ld reading nmaps for file %hd",ErrorCode(),resRefNum);
- }ENDTRY
- }
- return theEditorSet;
- }
-
- //------------------------------------------------------------------------------
- // ODGetEditorSetFromNMAP
- //------------------------------------------------------------------------------
-
- EditorSet* ODGetEditorSetFromNMAP( ODHandle nmap )
- {
- ODISOStr nameSpaceName = kODNULL; ODVolatile(nameSpaceName);
- ODUShort nameLen;
- ODISOStr editor;
- ODUShort editorLen;
- ODSize bufferPos=(ODSize)*nmap;
- ODUShort editorCount;
- ODSize sizeShort = sizeof(ODUShort);
- Environment* ev = somGetGlobalEnvironment ();
- EditorSet* theEditorSet = kODNULL;
-
- ODBlockMove((ODPtr)bufferPos, (ODPtr)&nameLen, sizeShort);
- bufferPos += sizeShort;
-
- TRY
- nameSpaceName = (ODISOStr)ODNewPtrClear((ODSize)nameLen+1, kDefaultHeapID);
- ODBlockMove((ODPtr)bufferPos, (ODPtr)nameSpaceName, (ODSize)nameLen);
- bufferPos += (ODSize)nameLen;
-
- if (ODISOStrEqual( nameSpaceName, kODEditorUserString ))
- {
- ODBlockMove((ODPtr)bufferPos, (ODPtr)&editorCount, sizeShort);
- bufferPos += sizeShort;
-
- if ( editorCount > 0 )
- {
- theEditorSet = new EditorSet() ;
- theEditorSet->InitEditorSet();
-
- for(ODUShort i=0; i < editorCount; i++)
- {
- ODBlockMove((ODPtr)bufferPos, (ODPtr)&editorLen, sizeShort);
- bufferPos += sizeShort;
-
- editor = (ODISOStr)ODNewPtrClear((ODSize)editorLen+1, kDefaultHeapID);
- ODBlockMove((ODPtr)bufferPos, (ODPtr)editor, (ODSize)editorLen);
- bufferPos += (ODSize)editorLen;
-
- theEditorSet->AddEditor(editor);
-
- // skip over the corresponding UserString in the nmap
- bufferPos += sizeShort;
- bufferPos += sizeof(ScriptCode);
- bufferPos += sizeof(LangCode);
- ODBlockMove((ODPtr)bufferPos, (ODPtr)&nameLen, sizeShort);
- bufferPos += sizeShort;
- bufferPos += nameLen;
- }
- }
- }
- CATCH_ALL
- WARN("Error %ld in Read_nmap_buffer",ErrorCode());
- ENDTRY
- ODDisposePtr((ODPtr)nameSpaceName);
- return theEditorSet;
- }
-
-