1 // Created on: 1997-11-05
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <Standard_SStream.hxx>
20 #include <Standard_NoSuchObject.hxx>
21 #include <Resource_Manager.hxx>
22 #include <Standard_GUID.hxx>
24 #include <FSD_CmpFile.hxx>
25 #include <FSD_File.hxx>
26 #include <FSD_BinaryFile.hxx>
27 #include <PCDM_StorageDriver.hxx>
29 //=======================================================================
30 //function : StorageDriver
31 //purpose : gets in the EuclidDesktop resource the plugin
32 // identifier of the driver plugs the driver.
33 //=======================================================================
35 Handle(PCDM_StorageDriver) PCDM::StorageDriver(const Handle(CDM_Document)& aDocument) {
37 if(!PCDM::FindStorageDriver(aDocument)) {
38 Standard_SStream aMsg; aMsg << "could not find the storage driver plugin resource for the format: " << aDocument->StorageFormat()<<(char) 0;
39 Standard_NoSuchObject::Raise(aMsg);
41 //return Handle(PCDM_StorageDriver)::DownCast(Plugin::Load(aDocument->StoragePlugin()));
42 Handle(PCDM_StorageDriver) DRIVER =
43 Handle(PCDM_StorageDriver)::DownCast(Plugin::Load(aDocument->StoragePlugin()));
44 if (!DRIVER.IsNull()) DRIVER->SetFormat(aDocument->StorageFormat());
48 //=======================================================================
49 //function : FindStorageDriver
51 //=======================================================================
53 Standard_Boolean PCDM::FindStorageDriver(const Handle(CDM_Document)& aDocument) {
55 return aDocument->FindStoragePlugin();
58 //=======================================================================
60 //purpose : returns a schema to be used during a Store or Retrieve
62 // Schema will plug the schema defined by
63 // the SchemaName method.
64 //=======================================================================
66 Handle(Storage_Schema) PCDM::Schema(const TCollection_ExtendedString& aSchemaName, const Handle(CDM_Application)& anApplication) {
68 Handle(Resource_Manager) r = anApplication->Resources();
69 if(!UTL::Find(r,aSchemaName)) {
70 Standard_SStream aMsg; aMsg << "could not find the plugin resource for the schema: " << TCollection_ExtendedString(aSchemaName) << (char)0;
71 Standard_NoSuchObject::Raise(aMsg);
73 Handle(Standard_Transient) t = Plugin::Load(UTL::GUID(UTL::Value(r,aSchemaName)));
74 return *((Handle(Storage_Schema)*)&t);
78 //=======================================================================
79 //function : FileDriverType
81 //=======================================================================
83 PCDM_TypeOfFileDriver PCDM::FileDriverType(const TCollection_AsciiString& aFileName, PCDM_BaseDriverPointer& aBaseDriver) {
84 if(FSD_CmpFile::IsGoodFileType(aFileName) == Storage_VSOk) {
85 aBaseDriver=new FSD_CmpFile;
86 return PCDM_TOFD_CmpFile;
88 else if(FSD_File::IsGoodFileType(aFileName) == Storage_VSOk) {
89 aBaseDriver=new FSD_File;
90 return PCDM_TOFD_File;
92 else if(FSD_BinaryFile::IsGoodFileType(aFileName) == Storage_VSOk) {
93 aBaseDriver=new FSD_BinaryFile;
94 return PCDM_TOFD_File;
98 return PCDM_TOFD_Unknown;