0025812: Replace dynamic loading mechanism of OCAF persistence with dynamic-link one
[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
18 #include <CDM_Application.hxx>
19 #include <CDM_Document.hxx>
20 #include <FSD_BinaryFile.hxx>
21 #include <FSD_CmpFile.hxx>
22 #include <FSD_File.hxx>
23 #include <PCDM.hxx>
24 #include <PCDM_StorageDriver.hxx>
25 #include <Plugin.hxx>
26 #include <Resource_Manager.hxx>
27 #include <Standard_GUID.hxx>
28 #include <Standard_NoSuchObject.hxx>
29 #include <Standard_SStream.hxx>
30 #include <Storage_Schema.hxx>
31 #include <TCollection_AsciiString.hxx>
32 #include <TCollection_ExtendedString.hxx>
33 #include <UTL.hxx>
34
35 //=======================================================================
36 //function : FileDriverType
37 //purpose  : 
38 //=======================================================================
39
40 PCDM_TypeOfFileDriver PCDM::FileDriverType(const TCollection_AsciiString& aFileName, PCDM_BaseDriverPointer& aBaseDriver) {
41   if(FSD_CmpFile::IsGoodFileType(aFileName) == Storage_VSOk) {
42     aBaseDriver=new FSD_CmpFile;
43     return PCDM_TOFD_CmpFile;
44   }
45   else if(FSD_File::IsGoodFileType(aFileName) == Storage_VSOk) {
46     aBaseDriver=new FSD_File;
47     return PCDM_TOFD_File;
48   }
49   else if(FSD_BinaryFile::IsGoodFileType(aFileName) == Storage_VSOk) {
50     aBaseDriver=new FSD_BinaryFile;
51     return PCDM_TOFD_File;
52   }
53   else {
54     aBaseDriver=NULL;
55     return PCDM_TOFD_Unknown;
56   }
57 }
58
59 //=======================================================================
60 //function : FileDriverType
61 //purpose  : 
62 //=======================================================================
63
64 PCDM_TypeOfFileDriver PCDM::FileDriverType (Standard_IStream& theIStream, PCDM_BaseDriverPointer& theBaseDriver)
65 {
66   TCollection_AsciiString aReadMagicNumber;
67
68   // read magic number from the file
69   if (theIStream.good())
70   {
71     aReadMagicNumber = Storage_BaseDriver::ReadMagicNumber (theIStream);
72   }
73
74   if(aReadMagicNumber == FSD_CmpFile::MagicNumber())
75   {
76     theBaseDriver = new FSD_CmpFile;
77     return PCDM_TOFD_CmpFile;
78   }
79   else if (aReadMagicNumber == FSD_File::MagicNumber())
80   {
81     theBaseDriver = new FSD_File;
82     return PCDM_TOFD_File;
83   }
84   else if (aReadMagicNumber == FSD_BinaryFile::MagicNumber())
85   {
86     theBaseDriver = new FSD_BinaryFile;
87     return PCDM_TOFD_File;
88   }
89   else if (aReadMagicNumber.Search ("<?xml") != -1)
90   {
91     // skip xml declaration
92     char aChar = ' ';
93     while (theIStream.good() && !theIStream.eof() && aChar != '>')
94     {
95       theIStream.get(aChar);
96     }
97
98     return PCDM_TOFD_XmlFile;
99   }
100
101   theBaseDriver = NULL;
102   return PCDM_TOFD_Unknown;
103 }
104