1 // Created on: 1997-08-08
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <CDF_StoreList.ixx>
25 #include <Standard_ErrorHandler.hxx>
26 #include <Standard_Macro.hxx>
28 #include <CDM_ReferenceIterator.hxx>
31 #include <PCDM_Document.hxx>
32 #include <PCDM_StorageDriver.hxx>
34 #include <CDF_MetaDataDriverError.hxx>
35 #include <CDF_MetaDataDriver.hxx>
37 #include <CDF_Session.hxx>
38 #include <CDF_Application.hxx>
39 #include <CDF_Timer.hxx>
41 static void CAUGHT(TCollection_ExtendedString& status,const TCollection_ExtendedString& what) {
42 Handle(Standard_Failure) F = Standard_Failure::Caught();
44 status += F->GetMessageString();
47 CDF_StoreList::CDF_StoreList(const Handle(CDM_Document)& aDocument) {
48 myMainDocument = aDocument;
52 void CDF_StoreList::Add(const Handle(CDM_Document)& aDocument) {
54 if(!myItems.Contains(aDocument) && aDocument != myMainDocument) myItems.Add(aDocument);
55 myStack.Push(aDocument);
57 CDM_ReferenceIterator it(aDocument);
58 for (;it.More();it.Next()) {
59 if(it.Document()->IsModified()) Add(it.Document());
62 Standard_Boolean CDF_StoreList::IsConsistent () const {
63 Standard_Boolean yes = Standard_True;
64 CDM_MapIteratorOfMapOfDocument it (myItems);
65 for ( ; it.More() && yes ; it.Next()) {
66 yes = it.Key()->HasRequestedFolder();
68 return yes && myMainDocument->HasRequestedFolder();
70 void CDF_StoreList::Init() {
71 myIterator = CDM_MapIteratorOfMapOfDocument(myItems);
73 Standard_Boolean CDF_StoreList::More() const {
74 return myIterator.More();
77 void CDF_StoreList::Next() {
81 Handle(CDM_Document) CDF_StoreList::Value() const {
82 return myIterator.Key();
84 PCDM_StoreStatus CDF_StoreList::Store (Handle(CDM_MetaData)& aMetaData, TCollection_ExtendedString& aStatusAssociatedText) {
86 Handle(CDF_MetaDataDriver) theMetaDataDriver = CDF_Session::CurrentSession()->MetaDataDriver();
88 PCDM_StoreStatus status = PCDM_SS_OK;
92 for (; !myStack.IsEmpty(); myStack.Pop()) {
94 Handle(CDM_Document) theDocument = myStack.Top();
95 if( theDocument == myMainDocument || theDocument->IsModified()) {
97 if(!PCDM::FindStorageDriver(theDocument)){
98 Standard_SStream aMsg;
99 aMsg <<"No storage driver does exist for this format: " << theDocument->StorageFormat() << (char)0;
100 Standard_Failure::Raise(aMsg);
103 if(!theMetaDataDriver->FindFolder(theDocument->RequestedFolder())) {
104 Standard_SStream aMsg; aMsg << "could not find the active dbunit";
105 aMsg << TCollection_ExtendedString(theDocument->RequestedFolder())<< (char)0;
106 Standard_NoSuchObject::Raise(aMsg);
108 TCollection_ExtendedString theName=theMetaDataDriver->BuildFileName(theDocument);
111 Handle(PCDM_StorageDriver) aDocumentStorageDriver = PCDM::StorageDriver(theDocument);
113 aDocumentStorageDriver->Write(theDocument,theName);
114 status = aDocumentStorageDriver->GetStoreStatus();
116 theTimer.ShowAndRestart("Driver->Write: ");
118 aMetaData = theMetaDataDriver->CreateMetaData(theDocument,theName);
119 theTimer.ShowAndStop("metadata creating: ");
121 theDocument->SetMetaData(aMetaData);
123 CDM_ReferenceIterator it(theDocument);
124 for(; it.More();it.Next()) {
125 theMetaDataDriver->CreateReference(aMetaData,it.Document()->MetaData(),it.ReferenceIdentifier(),it.DocumentVersion());
131 catch (CDF_MetaDataDriverError) {
132 CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("metadatadriver failed; reason:"));
133 status = PCDM_SS_DriverFailure;
135 catch (Standard_Failure) {
136 CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("driver failed; reason:"));
137 status = PCDM_SS_Failure;