0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / PCDM / PCDM.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <PCDM.ixx>
18 #include <Plugin.hxx>
19 #include <Standard_SStream.hxx>
20 #include <Standard_NoSuchObject.hxx>
21 #include <Resource_Manager.hxx>
22 #include <Standard_GUID.hxx>
23 #include <UTL.hxx>
24 #include <FSD_CmpFile.hxx>
25 #include <FSD_File.hxx>
26 #include <FSD_BinaryFile.hxx>
27 #include <PCDM_StorageDriver.hxx>
28
29 //=======================================================================
30 //function : StorageDriver
31 //purpose  : gets   in the  EuclidDesktop   resource  the plugin
32 //           identifier of the driver plugs the driver.
33 //=======================================================================
34
35 Handle(PCDM_StorageDriver) PCDM::StorageDriver(const Handle(CDM_Document)& aDocument) {
36   
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);
40   }  
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());
45   return DRIVER;
46 }
47
48 //=======================================================================
49 //function : FindStorageDriver
50 //purpose  : 
51 //=======================================================================
52
53 Standard_Boolean PCDM::FindStorageDriver(const Handle(CDM_Document)& aDocument) {
54   
55   return aDocument->FindStoragePlugin();
56 }
57
58 //=======================================================================
59 //function : Schema
60 //purpose  : returns a schema to be used during a Store or Retrieve
61 //           operation.
62 //           Schema will plug the schema defined by
63 //           the SchemaName method.
64 //=======================================================================
65
66 Handle(Storage_Schema) PCDM::Schema(const TCollection_ExtendedString& aSchemaName, const Handle(CDM_Application)& anApplication) {
67   
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);
72   }
73   Handle(Standard_Transient) t = Plugin::Load(UTL::GUID(UTL::Value(r,aSchemaName)));
74   return *((Handle(Storage_Schema)*)&t);
75   
76 }
77
78 //=======================================================================
79 //function : FileDriverType
80 //purpose  : 
81 //=======================================================================
82
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;
87   }
88   else if(FSD_File::IsGoodFileType(aFileName) == Storage_VSOk) {
89     aBaseDriver=new FSD_File;
90     return PCDM_TOFD_File;
91   }
92   else if(FSD_BinaryFile::IsGoodFileType(aFileName) == Storage_VSOk) {
93     aBaseDriver=new FSD_BinaryFile;
94     return PCDM_TOFD_File;
95   }
96   else {
97     aBaseDriver=NULL;
98     return PCDM_TOFD_Unknown;
99   }
100 }