1 // File: CDF_StoreList.cxx
2 // Created: Fri Aug 8 16:03:07 1997
3 // Author: Jean-Louis Frenkel
4 // <rmi@frilox.paris1.matra-dtv.fr>
7 #include <CDF_StoreList.ixx>
9 #include <Standard_ErrorHandler.hxx>
10 #include <Standard_Macro.hxx>
12 #include <CDM_ReferenceIterator.hxx>
15 #include <PCDM_Document.hxx>
16 #include <PCDM_StorageDriver.hxx>
18 #include <CDF_MetaDataDriverError.hxx>
19 #include <CDF_MetaDataDriver.hxx>
21 #include <CDF_Session.hxx>
22 #include <CDF_Application.hxx>
23 #include <CDF_Timer.hxx>
25 static void CAUGHT(TCollection_ExtendedString& status,const TCollection_ExtendedString& what) {
26 Handle(Standard_Failure) F = Standard_Failure::Caught();
28 status += F->GetMessageString();
31 CDF_StoreList::CDF_StoreList(const Handle(CDM_Document)& aDocument) {
32 myMainDocument = aDocument;
36 void CDF_StoreList::Add(const Handle(CDM_Document)& aDocument) {
38 if(!myItems.Contains(aDocument) && aDocument != myMainDocument) myItems.Add(aDocument);
39 myStack.Push(aDocument);
41 CDM_ReferenceIterator it(aDocument);
42 for (;it.More();it.Next()) {
43 if(it.Document()->IsModified()) Add(it.Document());
46 Standard_Boolean CDF_StoreList::IsConsistent () const {
47 Standard_Boolean yes = Standard_True;
48 CDM_MapIteratorOfMapOfDocument it (myItems);
49 for ( ; it.More() && yes ; it.Next()) {
50 yes = it.Key()->HasRequestedFolder();
52 return yes && myMainDocument->HasRequestedFolder();
54 void CDF_StoreList::Init() {
55 myIterator = CDM_MapIteratorOfMapOfDocument(myItems);
57 Standard_Boolean CDF_StoreList::More() const {
58 return myIterator.More();
61 void CDF_StoreList::Next() {
65 Handle(CDM_Document) CDF_StoreList::Value() const {
66 return myIterator.Key();
68 CDF_StoreStatus CDF_StoreList::Store (Handle(CDM_MetaData)& aMetaData, TCollection_ExtendedString& aStatusAssociatedText) {
70 Handle(CDF_MetaDataDriver) theMetaDataDriver = CDF_Session::CurrentSession()->MetaDataDriver();
72 static CDF_StoreStatus status ;
77 for (; !myStack.IsEmpty(); myStack.Pop()) {
79 Handle(CDM_Document) theDocument = myStack.Top();
80 if( theDocument == myMainDocument || theDocument->IsModified()) {
82 if(!PCDM::FindStorageDriver(theDocument)){
83 Standard_SStream aMsg;
84 aMsg <<"No storage driver does exist for this format: " << theDocument->StorageFormat() << (char)0;
85 Standard_Failure::Raise(aMsg);
89 if(!theMetaDataDriver->FindFolder(theDocument->RequestedFolder())) {
90 Standard_SStream aMsg; aMsg << "could not find the active dbunit";
91 aMsg << TCollection_ExtendedString(theDocument->RequestedFolder())<< (char)0;
92 Standard_NoSuchObject::Raise(aMsg);
94 TCollection_ExtendedString theName=theMetaDataDriver->BuildFileName(theDocument);
98 PCDM::StorageDriver(theDocument)->Write(theDocument,theName);
99 theTimer.ShowAndRestart("Driver->Write: ");
101 aMetaData = theMetaDataDriver->CreateMetaData(theDocument,theName);
102 theTimer.ShowAndStop("metadata creating: ");
104 theDocument->SetMetaData(aMetaData);
107 CDM_ReferenceIterator it(theDocument);
108 for(; it.More();it.Next()) {
109 theMetaDataDriver->CreateReference(aMetaData,it.Document()->MetaData(),it.ReferenceIdentifier(),it.DocumentVersion());
116 catch (CDF_MetaDataDriverError) {
117 CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("metadatadriver failed; reason:"));
118 status = CDF_SS_DriverFailure;
120 catch (Standard_Failure) {
121 CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("driver failed; reason:"));
122 status = CDF_SS_Failure;