0024624: Lost word in license statement in source files
[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
28 //=======================================================================
29 //function : StorageDriver
30 //purpose  : gets   in the  EuclidDesktop   resource  the plugin
31 //           identifier of the driver plugs the driver.
32 //=======================================================================
33
34 Handle(PCDM_StorageDriver) PCDM::StorageDriver(const Handle(CDM_Document)& aDocument) {
35   
36   if(!PCDM::FindStorageDriver(aDocument)) {    
37     Standard_SStream aMsg; aMsg << "could not find the storage driver plugin resource for the format: " << aDocument->StorageFormat()<<(char) 0;
38     Standard_NoSuchObject::Raise(aMsg);
39   }  
40   //return Handle(PCDM_StorageDriver)::DownCast(Plugin::Load(aDocument->StoragePlugin()));
41   Handle(PCDM_StorageDriver) DRIVER = 
42     Handle(PCDM_StorageDriver)::DownCast(Plugin::Load(aDocument->StoragePlugin()));
43   if (!DRIVER.IsNull()) DRIVER->SetFormat(aDocument->StorageFormat());
44   return DRIVER;
45 }
46
47 //=======================================================================
48 //function : FindStorageDriver
49 //purpose  : 
50 //=======================================================================
51
52 Standard_Boolean PCDM::FindStorageDriver(const Handle(CDM_Document)& aDocument) {
53   
54   return aDocument->FindStoragePlugin();
55 }
56
57 //=======================================================================
58 //function : Schema
59 //purpose  : returns a schema to be used during a Store or Retrieve
60 //           operation.
61 //           Schema will plug the schema defined by
62 //           the SchemaName method.
63 //=======================================================================
64
65 Handle(Storage_Schema) PCDM::Schema(const TCollection_ExtendedString& aSchemaName, const Handle(CDM_Application)& anApplication) {
66   
67   Handle(Resource_Manager) r = anApplication->Resources();
68   if(!UTL::Find(r,aSchemaName)) {
69     Standard_SStream aMsg; aMsg << "could not find the plugin resource for the schema: " << TCollection_ExtendedString(aSchemaName) << (char)0;
70     Standard_NoSuchObject::Raise(aMsg);
71   }
72   Handle(Standard_Transient) t = Plugin::Load(UTL::GUID(UTL::Value(r,aSchemaName)));
73   return *((Handle(Storage_Schema)*)&t);
74   
75 }
76
77 //=======================================================================
78 //function : FileDriverType
79 //purpose  : 
80 //=======================================================================
81
82 PCDM_TypeOfFileDriver PCDM::FileDriverType(const TCollection_AsciiString& aFileName, PCDM_BaseDriverPointer& aBaseDriver) {
83   if(FSD_CmpFile::IsGoodFileType(aFileName) == Storage_VSOk) {
84     aBaseDriver=new FSD_CmpFile;
85     return PCDM_TOFD_CmpFile;
86   }
87   else if(FSD_File::IsGoodFileType(aFileName) == Storage_VSOk) {
88     aBaseDriver=new FSD_File;
89     return PCDM_TOFD_File;
90   }
91   else if(FSD_BinaryFile::IsGoodFileType(aFileName) == Storage_VSOk) {
92     aBaseDriver=new FSD_BinaryFile;
93     return PCDM_TOFD_File;
94   }
95   else {
96     aBaseDriver=NULL;
97     return PCDM_TOFD_Unknown;
98   }
99 }