0025812: Replace dynamic loading mechanism of OCAF persistence with dynamic-link one
[occt.git] / src / XmlLDrivers / XmlLDrivers.cxx
1 // Created on: 2001-07-09
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <CDM_MessageDriver.hxx>
18 #include <Plugin_Macro.hxx>
19 #include <Standard_GUID.hxx>
20 #include <TDocStd_Application.hxx>
21 #include <TCollection_AsciiString.hxx>
22 #include <XmlLDrivers.hxx>
23 #include <XmlLDrivers_DocumentRetrievalDriver.hxx>
24 #include <XmlLDrivers_DocumentStorageDriver.hxx>
25 #include <XmlMDataStd.hxx>
26 #include <XmlMDF.hxx>
27 #include <XmlMDF_ADriverTable.hxx>
28 #include <XmlMDocStd.hxx>
29 #include <XmlMFunction.hxx>
30
31 #include <locale.h>
32 #include <time.h>
33 static Standard_GUID XmlLStorageDriver  ("13a56820-8269-11d5-aab2-0050044b1af1");
34 static Standard_GUID XmlLRetrievalDriver("13a56822-8269-11d5-aab2-0050044b1af1");
35 #define CURRENT_DOCUMENT_VERSION 8
36
37 //=======================================================================
38 //function : Factory
39 //purpose  : PLUGIN FACTORY
40 //=======================================================================
41 const Handle(Standard_Transient)& XmlLDrivers::Factory(const Standard_GUID& theGUID)
42 {
43   if (theGUID == XmlLStorageDriver)
44   {
45 #ifdef OCCT_DEBUG
46     cout << "XmlLDrivers : Storage Plugin" << endl;
47 #endif
48     static Handle(Standard_Transient) model_sd =
49       new XmlLDrivers_DocumentStorageDriver
50         ("Copyright: Open Cascade, 2001-2002"); // default copyright
51     return model_sd;
52   }
53
54   if (theGUID == XmlLRetrievalDriver)
55   {
56 #ifdef OCCT_DEBUG
57     cout << "XmlLDrivers : Retrieval Plugin" << endl;
58 #endif
59     static Handle (Standard_Transient) model_rd =
60       new XmlLDrivers_DocumentRetrievalDriver ();
61     return model_rd;
62   }
63  
64   Standard_Failure::Raise ("XmlLDrivers : unknown GUID");
65   static Handle(Standard_Transient) aNullHandle;
66   return aNullHandle;
67 }
68
69 #define SLENGTH 80
70 //=======================================================================
71 //function : CreationDate
72 //purpose  : mm/dd/yy
73 //=======================================================================
74 TCollection_AsciiString XmlLDrivers::CreationDate ()
75 {
76   Standard_Character nowstr[SLENGTH];
77   time_t nowbin;
78   struct tm *nowstruct;
79
80   if (time(&nowbin) == (time_t) - 1)
81   {
82 #ifdef OCCT_DEBUG
83     cerr << "Storage ERROR : Could not get time of day from time()" << endl;
84 #endif
85   }
86   
87   nowstruct = localtime(&nowbin);
88   
89   if (strftime(nowstr, SLENGTH, "%Y-%m-%d", nowstruct) == (size_t) 0)
90   {
91 #ifdef OCCT_DEBUG
92     cerr << "Storage ERROR : Could not get string from strftime()" << endl;
93 #endif
94   }
95
96   return nowstr;
97 }
98
99 //=======================================================================
100 //function : DefineFormat
101 //purpose  : 
102 //=======================================================================
103 void XmlLDrivers::DefineFormat (const Handle(TDocStd_Application)& theApp)
104 {
105   theApp->DefineFormat ("XmlLOcaf", "Xml Lite OCAF Document", "xmll",
106                         new XmlLDrivers_DocumentRetrievalDriver, 
107                         new XmlLDrivers_DocumentStorageDriver ("Copyright: Open Cascade, 2001-2002"));
108 }
109
110 //=======================================================================
111 //function : AttributeDrivers
112 //purpose  : 
113 //=======================================================================
114 Handle(XmlMDF_ADriverTable) XmlLDrivers::AttributeDrivers
115                 (const Handle(CDM_MessageDriver)& theMessageDriver)
116 {
117   Handle(XmlMDF_ADriverTable) aTable = new XmlMDF_ADriverTable();
118   //
119   XmlMDF        ::AddDrivers (aTable, theMessageDriver);
120   XmlMDataStd   ::AddDrivers (aTable, theMessageDriver);
121   XmlMFunction  ::AddDrivers (aTable, theMessageDriver);
122   XmlMDocStd    ::AddDrivers (aTable, theMessageDriver); 
123   //
124   return aTable;
125 }
126
127 //=======================================================================
128 //function : StorageVersion
129 //purpose  : Document storage version
130 //=======================================================================
131
132 TCollection_AsciiString XmlLDrivers::StorageVersion()
133 {
134   TCollection_AsciiString aVersionStr (CURRENT_DOCUMENT_VERSION);
135   return aVersionStr;
136 }
137
138 // Declare entry point PLUGINFACTORY
139 PLUGIN(XmlLDrivers)