1 // Created on: 1997-08-08
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 <CDF_Application.hxx>
19 #include <CDF_MetaDataDriver.hxx>
20 #include <CDF_MetaDataDriverError.hxx>
21 #include <CDF_Session.hxx>
22 #include <CDF_StoreList.hxx>
23 #include <CDF_Timer.hxx>
24 #include <CDM_Document.hxx>
25 #include <CDM_MetaData.hxx>
26 #include <CDM_ReferenceIterator.hxx>
28 #include <PCDM_Document.hxx>
29 #include <PCDM_StorageDriver.hxx>
30 #include <Standard_ErrorHandler.hxx>
31 #include <Standard_Macro.hxx>
32 #include <Standard_NoSuchObject.hxx>
33 #include <Standard_Type.hxx>
34 #include <TCollection_ExtendedString.hxx>
36 static void CAUGHT(TCollection_ExtendedString& status,const TCollection_ExtendedString& what) {
37 Handle(Standard_Failure) F = Standard_Failure::Caught();
39 status += F->GetMessageString();
42 CDF_StoreList::CDF_StoreList(const Handle(CDM_Document)& aDocument) {
43 myMainDocument = aDocument;
47 void CDF_StoreList::Add(const Handle(CDM_Document)& aDocument) {
49 if(!myItems.Contains(aDocument) && aDocument != myMainDocument) myItems.Add(aDocument);
50 myStack.Prepend(aDocument);
52 CDM_ReferenceIterator it(aDocument);
53 for (;it.More();it.Next()) {
54 if(it.Document()->IsModified()) Add(it.Document());
57 Standard_Boolean CDF_StoreList::IsConsistent () const {
58 Standard_Boolean yes = Standard_True;
59 CDM_MapIteratorOfMapOfDocument it (myItems);
60 for ( ; it.More() && yes ; it.Next()) {
61 yes = it.Key()->HasRequestedFolder();
63 return yes && myMainDocument->HasRequestedFolder();
65 void CDF_StoreList::Init() {
66 myIterator = CDM_MapIteratorOfMapOfDocument(myItems);
68 Standard_Boolean CDF_StoreList::More() const {
69 return myIterator.More();
72 void CDF_StoreList::Next() {
76 Handle(CDM_Document) CDF_StoreList::Value() const {
77 return myIterator.Key();
79 PCDM_StoreStatus CDF_StoreList::Store (Handle(CDM_MetaData)& aMetaData, TCollection_ExtendedString& aStatusAssociatedText) {
81 Handle(CDF_MetaDataDriver) theMetaDataDriver = CDF_Session::CurrentSession()->MetaDataDriver();
83 PCDM_StoreStatus status = PCDM_SS_OK;
87 for (; !myStack.IsEmpty(); myStack.RemoveFirst()) {
89 Handle(CDM_Document) theDocument = myStack.First();
90 if( theDocument == myMainDocument || theDocument->IsModified()) {
92 if(!PCDM::FindStorageDriver(theDocument)){
93 Standard_SStream aMsg;
94 aMsg <<"No storage driver does exist for this format: " << theDocument->StorageFormat() << (char)0;
95 Standard_Failure::Raise(aMsg);
98 if(!theMetaDataDriver->FindFolder(theDocument->RequestedFolder())) {
99 Standard_SStream aMsg; aMsg << "could not find the active dbunit";
100 aMsg << TCollection_ExtendedString(theDocument->RequestedFolder())<< (char)0;
101 Standard_NoSuchObject::Raise(aMsg);
103 TCollection_ExtendedString theName=theMetaDataDriver->BuildFileName(theDocument);
106 Handle(PCDM_StorageDriver) aDocumentStorageDriver = PCDM::StorageDriver(theDocument);
108 aDocumentStorageDriver->Write(theDocument,theName);
109 status = aDocumentStorageDriver->GetStoreStatus();
111 theTimer.ShowAndRestart("Driver->Write: ");
113 aMetaData = theMetaDataDriver->CreateMetaData(theDocument,theName);
114 theTimer.ShowAndStop("metadata creating: ");
116 theDocument->SetMetaData(aMetaData);
118 CDM_ReferenceIterator it(theDocument);
119 for(; it.More();it.Next()) {
120 theMetaDataDriver->CreateReference(aMetaData,it.Document()->MetaData(),it.ReferenceIdentifier(),it.DocumentVersion());
126 catch (CDF_MetaDataDriverError) {
127 CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("metadatadriver failed; reason:"));
128 status = PCDM_SS_DriverFailure;
130 catch (Standard_Failure) {
131 CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("driver failed; reason:"));
132 status = PCDM_SS_Failure;