// @mfunc Constructor. OMXMLStoredObjectFactory::OMXMLStoredObjectFactory( const OMStoredObjectEncoding& encoding, const OMUniqueObjectIdentification& signature, const wchar_t* name, const wchar_t* description) : OMStoredObjectFactory(encoding, signature, name, description) { TRACE("OMXMLStoredObjectFactory::OMXMLStoredObjectFactory"); PRECONDITION("Valid name", validWideString(name)); PRECONDITION("Valid name", validWideString(description)); PRECONDITION("Valid encoding", encoding != nullOMStoredObjectEncoding); }
OMStoredObject* OMGSF_SSStoredObjectFactory::createFile (const wchar_t* fileName, const OMByteOrder byteOrder, const OMUniqueObjectIdentification& signature) { TRACE("OMGSF_SSStoredObjectFactory::createFile"); PRECONDITION("Valid file name", validWideString(fileName)); // choose sector size based on signature from factory ULONG sectorSize=0; if( OMSignature_Aaf512Binary == signature ) sectorSize=512; else if( OMSignature_Aaf4KBinary == signature ) sectorSize=4096; PRECONDITION("Valid Signature", sectorSize!=0 ); SSCHAR omFileName[FILENAME_MAX]; #ifndef OM_UNICODE_APIS convertWideStringToString(omFileName, fileName, FILENAME_MAX); #else copyWideString (omFileName, fileName, FILENAME_MAX); #endif IStorage* storage = 0; HRESULT status = OMGSFIStorage::StgCreateStorageEx( omFileName, OMFile::writeOnlyMode, (void **)&storage, sectorSize); checkStatus(status); ASSERT("StgCreateStorageEx() succeeded", SUCCEEDED(status)); return OMSSStoredObject::create(storage, byteOrder); }
OMStoredObject* OMGSF_SSStoredObjectFactory::openFile (const wchar_t* fileName, const OMFile::OMAccessMode mode) { TRACE("OMGSF_SSStoredObjectFactory::openFile"); PRECONDITION("Valid file name", validWideString(fileName)); PRECONDITION("Valid mode", (mode == OMFile::modifyMode) || (mode == OMFile::readOnlyMode)); if (mode == OMFile::modifyMode) { ASSERT("Unimplemented GSF open in Read Modify mode not reached", false); return 0; } SSCHAR omFileName[FILENAME_MAX]; #ifndef OM_UNICODE_APIS convertWideStringToString(omFileName, fileName, FILENAME_MAX); #else copyWideString (omFileName, fileName, FILENAME_MAX); #endif IStorage* storage = 0; HRESULT status = OMGSFIStorage::StgOpenStorageEx( omFileName, OMFile::readOnlyMode, (void **)&storage); checkStatus(status); ASSERT("StgOpenStorageEx() succeeded", SUCCEEDED(status)); return OMSSStoredObject::open(storage, mode); }
// @mfunc Assignment operator. // @parm The new value for this <c OMWideStringProperty>. // @rdesc The <c OMWideStringProperty> resulting from the assignment. OMWideStringProperty& OMWideStringProperty::operator = (const wchar_t* value) { TRACE("OMWideStringProperty::operator ="); PRECONDITION("Valid string", validWideString(value)); assign(value); return *this; }
// @mfunc Open a new <c OMFile> for modify access, the // <c OMFile> is named <p fileName>, use the <c OMClassFactory> // <p factory> to create the objects. The file must not already // exist. The byte ordering on the newly created file is given // by <p byteOrder>. The client root <c OMStorable> in the newly // created file is given by <p clientRoot>. // @parm The name of the file to create. // @parm The factory to use for creating objects. // @parm TBS // @parm The byte order to use for the newly created file. // @parm The client root <c OMStorable> in the newly created file. // @parm TBS // @parm TBS // @rdesc The newly created <c OMFile>. OMFile* OMFile::openNewModify(const wchar_t* fileName, const OMClassFactory* factory, void* clientOnRestoreContext, const OMByteOrder byteOrder, OMStorable* clientRoot, const OMStoredObjectEncoding& encoding, OMDictionary* dictionary) { TRACE("OMFile::openNewModify"); PRECONDITION("Valid file name", validWideString(fileName)); PRECONDITION("Valid class factory", factory != 0); PRECONDITION("Valid byte order", ((byteOrder == littleEndian) || (byteOrder == bigEndian))); PRECONDITION("Valid client root", clientRoot != 0); PRECONDITION("Valid dictionary ", dictionary != 0); OMFile* newFile = 0; if (compatibleNamedFile(modifyMode, encoding)) { OMStoredObjectFactory* f = findFactory(encoding); ASSERT("Recognized file encoding", f != 0); OMStoredObject* store = f->createModify(fileName, byteOrder); OMRootStorable* root = new OMRootStorable(clientRoot, dictionary); ASSERT("Valid heap pointer", root != 0); newFile = new OMFile(fileName, clientOnRestoreContext, encoding, modifyMode, store, factory, dictionary, root); ASSERT("Valid heap pointer", newFile != 0); } else { OMRootStorable* root = new OMRootStorable(clientRoot, dictionary); ASSERT("Valid heap pointer", root != 0); OMRawStorage* store = OMCachedDiskRawStorage::openNewModify(fileName); ASSERT("Valid raw storage", store != 0); newFile = new OMFile(store, clientOnRestoreContext, encoding, modifyMode, factory, dictionary, root, byteOrder); ASSERT("Valid heap pointer", newFile != 0); newFile->open(); } POSTCONDITION("File is open", newFile->isOpen()); return newFile; }
// @mfunc Open an existing <c OMFile> for read-only access, the // <c OMFile> is named <p fileName>, use the <c OMClassFactory> // <p factory> to create the objects. The file must already // exist. // @parm The name of the file to open. // @parm The factory to use for creating objects. // @parm Specifies the use of lazy or eager loading. // @rdesc The newly opened <c OMFile>. OMFile* OMFile::openExistingRead(const wchar_t* fileName, const OMClassFactory* factory, void* clientOnRestoreContext, const OMLoadMode loadMode, OMDictionary* dictionary) { TRACE("OMFile::openExistingRead"); PRECONDITION("Valid file name", validWideString(fileName)); PRECONDITION("Valid class factory", factory != 0); PRECONDITION("Valid dictionary", dictionary != 0); OMStoredObjectEncoding encoding; #if defined(OM_DEBUG) bool result = #endif isRecognized(fileName, encoding); ASSERT("Recognized file", result); // tjb - error OMStoredObjectFactory* f = findFactory(encoding); ASSERT("Recognized file encoding", f != 0); OMFile* newFile = 0; if (compatibleNamedFile(readOnlyMode, encoding)) { OMStoredObject* store = f->openRead(fileName); newFile = new OMFile(fileName, clientOnRestoreContext, encoding, readOnlyMode, store, factory, dictionary, loadMode); ASSERT("Valid heap pointer", newFile != 0); } else { OMRawStorage* store = OMCachedDiskRawStorage::openExistingRead(fileName); ASSERT("Valid raw storage", store != 0); newFile = new OMFile(store, clientOnRestoreContext, nullOMStoredObjectEncoding, // don't care readOnlyMode, factory, dictionary, loadMode); ASSERT("Valid heap pointer", newFile != 0); newFile->open(); } POSTCONDITION("File is open", newFile->isOpen()); return newFile; }
OMPropertyId* OMFile::path(const wchar_t* propertyPathName) const { TRACE("OMFile::path"); wchar_t delimiter = L'/'; PRECONDITION("Valid property path name", validWideString(propertyPathName)); PRECONDITION("Path name is absolute", propertyPathName[0] == delimiter); PRECONDITION("Valid root", _root != 0); // Allocate result // size_t count = countWideCharacter(propertyPathName, delimiter); OMPropertyId* result = new OMPropertyId[count + 1]; ASSERT("Valid heap pointer", result != 0); // Parse path name // wchar_t* path = saveWideString(propertyPathName); wchar_t* element = path; element++; // skip first '/' const OMStorable* storable = _root; OMProperty* property = 0; size_t index = 0; wchar_t* end = findWideCharacter(element, delimiter); while (end != 0) { *end = 0; property = storable->findProperty(element); result[index] = property->propertyId(); index = index + 1; storable = storable->find(element); ASSERT("Valid storable pointer", storable != 0); element = ++end; end = findWideCharacter(element, delimiter); } if ((element != 0) && (lengthOfWideString(element) > 0)) { property = storable->findProperty(element); result[index] = property->propertyId(); index = index + 1; } result[index] = 0; delete [] path; return result; }
// @mfunc Constructor. Create an <c OMFile> object representing // a new named external file. // @parm The name of this <c OMFile>. // @parm The encoding of this <c OMFile>. // @parm The access mode of this <c OMFile>. // @parm The <c OMStoredObject> in which to store the root // <c OMStorable> object. // @parm The <c OMClassFactory> to use to restore objects from // this <c OMFile>. // @parm The root <c OMStorable> object to save in this file. OMFile::OMFile(const wchar_t* fileName, void* clientOnRestoreContext, OMStoredObjectEncoding encoding, const OMAccessMode mode, OMStoredObject* store, const OMClassFactory* factory, OMDictionary* dictionary, OMRootStorable* root) : _root(root), _rootStore(store), _dictionary(dictionary), _classFactory(factory), _referencedProperties(0), _mode(mode), _loadMode(lazyLoad), _fileName(0), _encoding(encoding), _clientOnSaveContext(0), _clientOnRestoreContext(clientOnRestoreContext), _rawStorage(0), _isOpen(false), _isClosed(false), _isNew(true), _isValid(true), _byteOrder(unspecified) { TRACE("OMFile::OMFile"); PRECONDITION("Valid file name", validWideString(fileName)); PRECONDITION("Valid root", _root != 0); PRECONDITION("Valid dictionary", _dictionary != 0); _fileName = saveWideString(fileName); _root->attach(this); _root->setStore(_rootStore); _isOpen = true; POSTCONDITION("File is open", _isOpen); }