0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / PCDM / PCDM_StorageDriver.cxx
CommitLineData
b311480e 1// Created on: 1997-08-07
2// Created by: Jean-Louis Frenkel
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <PCDM_StorageDriver.ixx>
18#include <Storage_Data.hxx>
19#include <Storage_OpenMode.hxx>
20#include <Storage_Schema.hxx>
21#include <TColStd_SequenceOfExtendedString.hxx>
22#include <FSD_CmpFile.hxx>
23#include <TCollection_AsciiString.hxx>
24#include <Standard_ErrorHandler.hxx>
25#include <PCDM_ReadWriter.hxx>
26#include <Resource_Manager.hxx>
27#include <Standard_NotImplemented.hxx>
28#include <PCDM_SequenceOfDocument.hxx>
29#include <PCDM.hxx>
30#include <locale.h>
31
32#define STORAGE_VERSION "STORAGE_VERSION:"
33
34
35
91322f44 36void PCDM_StorageDriver::Write(const Handle(CDM_Document)& aDocument, const TCollection_ExtendedString& aFileName)
37{
7fd59977 38 Handle(Storage_Schema) theSchema=PCDM::Schema(SchemaName(),aDocument->Application());
39
40 TColStd_SequenceOfExtendedString theExtensions;
41 aDocument->Extensions(theExtensions);
42 LoadExtensions(theSchema,theExtensions);
43
44
45 Handle(Storage_Data) theData = new Storage_Data;
46
47 static Standard_Boolean Failure;
48 Failure=Standard_False;
49 Standard_SStream aMsg; aMsg << "error during Make:";
50 PCDM_SequenceOfDocument thePersistentDocuments;
51 {
52 try { OCC_CATCH_SIGNALS Make(aDocument,thePersistentDocuments);}
53 catch (Standard_Failure) {
54 aMsg << Standard_Failure::Caught()<<(char)0;
55 Failure=Standard_True;
56 }
57 }
58
59 if(Failure) PCDM_DriverError::Raise(aMsg);
60
61 if(thePersistentDocuments.IsEmpty()) {
62 aMsg << "the storage driver: " << DynamicType()->Name() << "returned no documents to store" << (char) 0;
63 PCDM_DriverError::Raise(aMsg);
64 }
65
66 Standard_Integer i=1;
67 for(; i<=thePersistentDocuments.Length(); i++) {
68 theData->AddRoot(thePersistentDocuments(i));
69 }
70
71 TCollection_AsciiString ligne(STORAGE_VERSION);
72 ligne+=PCDM_ReadWriter::Writer()->Version();
73 theData->AddToUserInfo(ligne);
74
75 PCDM_ReadWriter::WriteFileFormat(theData,aDocument);
76 PCDM_ReadWriter::Writer()->WriteReferenceCounter(theData,aDocument);
77 PCDM_ReadWriter::Writer()->WriteReferences(theData,aDocument,aFileName);
78 PCDM_ReadWriter::Writer()->WriteExtensions(theData,aDocument);
79 PCDM_ReadWriter::Writer()->WriteVersion(theData,aDocument);
80
81 // add document comments
82 TColStd_SequenceOfExtendedString aComments;
83 aDocument->Comments(aComments);
84 Standard_Integer aLen = aComments.Length();
85 for (i = 1; i <= aLen; i++)
86 {
87 theData->AddToComments(aComments(i));
88 }
89
90 FSD_CmpFile theFile;
91 PCDM_ReadWriter::Open(theFile,aFileName,Storage_VSWrite);
92 theSchema->Write(theFile,theData);
93 theFile.Close();
94
7fd59977 95 if ( theData->ErrorStatus() != Storage_VSOk )
96 PCDM_DriverError::Raise(theData->ErrorStatusExtension().ToCString());
97}
98
99//void PCDM_StorageDriver::LoadExtensions(const Handle(Storage_Schema)& aSchema, const TColStd_SequenceOfExtendedString& Extensions) {}
100void PCDM_StorageDriver::LoadExtensions(const Handle(Storage_Schema)& , const TColStd_SequenceOfExtendedString& ) {}
101
102
103//Handle(PCDM_Document) PCDM_StorageDriver::Make(const Handle(CDM_Document)& aDocument) {
104Handle(PCDM_Document) PCDM_StorageDriver::Make(const Handle(CDM_Document)& ) {
105 Handle(PCDM_Document) voidDocument;
106 Standard_SStream aMsg;
107 aMsg << "No Make method were implemented in this Driver" << DynamicType()->Name() << (char) 0;
108 Standard_NotImplemented::Raise(aMsg);
109 return voidDocument;
110}
111
112void PCDM_StorageDriver::Make(const Handle(CDM_Document)& aDocument, PCDM_SequenceOfDocument& Documents) {
113 Documents.Append(Make(aDocument));
114}
115
116//=======================================================================
117//function : SetFormat
118//purpose :
119//=======================================================================
120
121void PCDM_StorageDriver::SetFormat (const TCollection_ExtendedString& aformat)
122{
123 myFormat = aformat;
124}
125
126
127//=======================================================================
128//function : GetFormat
129//purpose :
130//=======================================================================
131
132TCollection_ExtendedString PCDM_StorageDriver::GetFormat () const
133{
134 return myFormat;
135}
15e8b082
M
136
137//=======================================================================
138//function : IsError
139//purpose :
140//=======================================================================
141
142Standard_Boolean PCDM_StorageDriver::IsError () const
143{
144 return myIsError;
145}
146
147//=======================================================================
148//function : SetIsError
149//purpose :
150//=======================================================================
151void PCDM_StorageDriver::SetIsError(const Standard_Boolean theIsError)
152{
153 myIsError = theIsError;
154}
155
156//=======================================================================
157//function : GetStoreStatus
158//purpose :
159//=======================================================================
160
161PCDM_StoreStatus PCDM_StorageDriver::GetStoreStatus () const
162{
163 return myStoreStatus;
164}
165//=======================================================================
166//function : SetStoreStatus
167//purpose :
168//=======================================================================
169void PCDM_StorageDriver::SetStoreStatus(const PCDM_StoreStatus theStoreStatus)
170{
171 myStoreStatus = theStoreStatus;
172}