1 // Created on: 1997-08-07
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <CDM_Document.hxx>
19 #include <FSD_CmpFile.hxx>
21 #include <PCDM_Document.hxx>
22 #include <PCDM_DriverError.hxx>
23 #include <PCDM_ReadWriter.hxx>
24 #include <PCDM_SequenceOfDocument.hxx>
25 #include <PCDM_StorageDriver.hxx>
26 #include <Resource_Manager.hxx>
27 #include <Standard_ErrorHandler.hxx>
28 #include <Standard_NoSuchObject.hxx>
29 #include <Standard_NotImplemented.hxx>
30 #include <Standard_Type.hxx>
31 #include <Storage_Data.hxx>
32 #include <Storage_OpenMode.hxx>
33 #include <Storage_Schema.hxx>
34 #include <TCollection_AsciiString.hxx>
35 #include <TCollection_ExtendedString.hxx>
36 #include <TColStd_SequenceOfExtendedString.hxx>
39 IMPLEMENT_STANDARD_RTTIEXT(PCDM_StorageDriver,PCDM_Writer)
41 #define STORAGE_VERSION "STORAGE_VERSION:"
45 void PCDM_StorageDriver::Write(const Handle(CDM_Document)& aDocument, const TCollection_ExtendedString& aFileName)
47 Handle(Storage_Schema) theSchema=PCDM::Schema(SchemaName(),aDocument->Application());
49 TColStd_SequenceOfExtendedString theExtensions;
50 aDocument->Extensions(theExtensions);
51 LoadExtensions(theSchema,theExtensions);
54 Handle(Storage_Data) theData = new Storage_Data;
56 static Standard_Boolean Failure;
57 Failure=Standard_False;
58 Standard_SStream aMsg; aMsg << "error during Make:";
59 PCDM_SequenceOfDocument thePersistentDocuments;
61 try { OCC_CATCH_SIGNALS Make(aDocument,thePersistentDocuments);}
62 catch (Standard_Failure) {
63 aMsg << Standard_Failure::Caught()<<(char)0;
64 Failure=Standard_True;
68 if(Failure) PCDM_DriverError::Raise(aMsg);
70 if(thePersistentDocuments.IsEmpty()) {
71 aMsg << "the storage driver: " << DynamicType()->Name() << "returned no documents to store" << (char) 0;
72 PCDM_DriverError::Raise(aMsg);
76 for(; i<=thePersistentDocuments.Length(); i++) {
77 theData->AddRoot(thePersistentDocuments(i));
80 TCollection_AsciiString ligne(STORAGE_VERSION);
81 ligne+=PCDM_ReadWriter::Writer()->Version();
82 theData->AddToUserInfo(ligne);
84 PCDM_ReadWriter::WriteFileFormat(theData,aDocument);
85 PCDM_ReadWriter::Writer()->WriteReferenceCounter(theData,aDocument);
86 PCDM_ReadWriter::Writer()->WriteReferences(theData,aDocument,aFileName);
87 PCDM_ReadWriter::Writer()->WriteExtensions(theData,aDocument);
88 PCDM_ReadWriter::Writer()->WriteVersion(theData,aDocument);
90 // add document comments
91 TColStd_SequenceOfExtendedString aComments;
92 aDocument->Comments(aComments);
93 Standard_Integer aLen = aComments.Length();
94 for (i = 1; i <= aLen; i++)
96 theData->AddToComments(aComments(i));
100 PCDM_ReadWriter::Open(theFile,aFileName,Storage_VSWrite);
101 theSchema->Write(theFile,theData);
104 if ( theData->ErrorStatus() != Storage_VSOk )
105 PCDM_DriverError::Raise(theData->ErrorStatusExtension().ToCString());
108 //void PCDM_StorageDriver::LoadExtensions(const Handle(Storage_Schema)& aSchema, const TColStd_SequenceOfExtendedString& Extensions) {}
109 void PCDM_StorageDriver::LoadExtensions(const Handle(Storage_Schema)& , const TColStd_SequenceOfExtendedString& ) {}
112 //Handle(PCDM_Document) PCDM_StorageDriver::Make(const Handle(CDM_Document)& aDocument) {
113 Handle(PCDM_Document) PCDM_StorageDriver::Make(const Handle(CDM_Document)& ) {
114 Handle(PCDM_Document) voidDocument;
115 Standard_SStream aMsg;
116 aMsg << "No Make method were implemented in this Driver" << DynamicType()->Name() << (char) 0;
117 Standard_NotImplemented::Raise(aMsg);
121 void PCDM_StorageDriver::Make(const Handle(CDM_Document)& aDocument, PCDM_SequenceOfDocument& Documents) {
122 Documents.Append(Make(aDocument));
125 //=======================================================================
126 //function : SetFormat
128 //=======================================================================
130 void PCDM_StorageDriver::SetFormat (const TCollection_ExtendedString& aformat)
136 //=======================================================================
137 //function : GetFormat
139 //=======================================================================
141 TCollection_ExtendedString PCDM_StorageDriver::GetFormat () const
146 //=======================================================================
149 //=======================================================================
151 Standard_Boolean PCDM_StorageDriver::IsError () const
156 //=======================================================================
157 //function : SetIsError
159 //=======================================================================
160 void PCDM_StorageDriver::SetIsError(const Standard_Boolean theIsError)
162 myIsError = theIsError;
165 //=======================================================================
166 //function : GetStoreStatus
168 //=======================================================================
170 PCDM_StoreStatus PCDM_StorageDriver::GetStoreStatus () const
172 return myStoreStatus;
174 //=======================================================================
175 //function : SetStoreStatus
177 //=======================================================================
178 void PCDM_StorageDriver::SetStoreStatus(const PCDM_StoreStatus theStoreStatus)
180 myStoreStatus = theStoreStatus;