7fd59977 |
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> |
5 | |
6 | |
7 | #include <CDF_StoreList.ixx> |
8 | |
9 | #include <Standard_ErrorHandler.hxx> |
10 | #include <Standard_Macro.hxx> |
11 | |
12 | #include <CDM_ReferenceIterator.hxx> |
13 | |
14 | #include <PCDM.hxx> |
15 | #include <PCDM_Document.hxx> |
16 | #include <PCDM_StorageDriver.hxx> |
17 | |
18 | #include <CDF_MetaDataDriverError.hxx> |
19 | #include <CDF_MetaDataDriver.hxx> |
20 | |
21 | #include <CDF_Session.hxx> |
22 | #include <CDF_Application.hxx> |
23 | #include <CDF_Timer.hxx> |
24 | |
25 | static void CAUGHT(TCollection_ExtendedString& status,const TCollection_ExtendedString& what) { |
26 | Handle(Standard_Failure) F = Standard_Failure::Caught(); |
27 | status += what; |
28 | status += F->GetMessageString(); |
29 | } |
30 | |
31 | CDF_StoreList::CDF_StoreList(const Handle(CDM_Document)& aDocument) { |
32 | myMainDocument = aDocument; |
33 | Add(aDocument); |
34 | } |
35 | |
36 | void CDF_StoreList::Add(const Handle(CDM_Document)& aDocument) { |
37 | |
38 | if(!myItems.Contains(aDocument) && aDocument != myMainDocument) myItems.Add(aDocument); |
39 | myStack.Push(aDocument); |
40 | |
41 | CDM_ReferenceIterator it(aDocument); |
42 | for (;it.More();it.Next()) { |
43 | if(it.Document()->IsModified()) Add(it.Document()); |
44 | } |
45 | } |
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(); |
51 | } |
52 | return yes && myMainDocument->HasRequestedFolder(); |
53 | } |
54 | void CDF_StoreList::Init() { |
55 | myIterator = CDM_MapIteratorOfMapOfDocument(myItems); |
56 | } |
57 | Standard_Boolean CDF_StoreList::More() const { |
58 | return myIterator.More(); |
59 | } |
60 | |
61 | void CDF_StoreList::Next() { |
62 | myIterator.Next(); |
63 | } |
64 | |
65 | Handle(CDM_Document) CDF_StoreList::Value() const { |
66 | return myIterator.Key(); |
67 | } |
68 | CDF_StoreStatus CDF_StoreList::Store (Handle(CDM_MetaData)& aMetaData, TCollection_ExtendedString& aStatusAssociatedText) { |
69 | |
70 | Handle(CDF_MetaDataDriver) theMetaDataDriver = CDF_Session::CurrentSession()->MetaDataDriver(); |
71 | |
72 | static CDF_StoreStatus status ; |
73 | status = CDF_SS_OK; |
74 | { |
75 | try { |
76 | OCC_CATCH_SIGNALS |
77 | for (; !myStack.IsEmpty(); myStack.Pop()) { |
78 | |
79 | Handle(CDM_Document) theDocument = myStack.Top(); |
80 | if( theDocument == myMainDocument || theDocument->IsModified()) { |
81 | |
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); |
86 | } |
87 | |
88 | |
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); |
93 | } |
94 | TCollection_ExtendedString theName=theMetaDataDriver->BuildFileName(theDocument); |
95 | |
96 | CDF_Timer theTimer; |
97 | |
98 | PCDM::StorageDriver(theDocument)->Write(theDocument,theName); |
99 | theTimer.ShowAndRestart("Driver->Write: "); |
100 | |
101 | aMetaData = theMetaDataDriver->CreateMetaData(theDocument,theName); |
102 | theTimer.ShowAndStop("metadata creating: "); |
103 | |
104 | theDocument->SetMetaData(aMetaData); |
105 | |
106 | |
107 | CDM_ReferenceIterator it(theDocument); |
108 | for(; it.More();it.Next()) { |
109 | theMetaDataDriver->CreateReference(aMetaData,it.Document()->MetaData(),it.ReferenceIdentifier(),it.DocumentVersion()); |
110 | } |
111 | |
112 | } |
113 | } |
114 | } |
115 | |
116 | catch (CDF_MetaDataDriverError) { |
117 | CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("metadatadriver failed; reason:")); |
118 | status = CDF_SS_DriverFailure; |
119 | } |
120 | catch (Standard_Failure) { |
121 | CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("driver failed; reason:")); |
122 | status = CDF_SS_Failure; |
123 | } |
124 | } |
125 | |
126 | return status; |
127 | } |