Commit | Line | Data |
---|---|---|
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 | } | |
15e8b082 | 68 | PCDM_StoreStatus CDF_StoreList::Store (Handle(CDM_MetaData)& aMetaData, TCollection_ExtendedString& aStatusAssociatedText) { |
7fd59977 | 69 | |
70 | Handle(CDF_MetaDataDriver) theMetaDataDriver = CDF_Session::CurrentSession()->MetaDataDriver(); | |
71 | ||
15e8b082 | 72 | PCDM_StoreStatus status = PCDM_SS_OK; |
7fd59977 | 73 | { |
74 | try { | |
75 | OCC_CATCH_SIGNALS | |
76 | for (; !myStack.IsEmpty(); myStack.Pop()) { | |
15e8b082 M |
77 | |
78 | Handle(CDM_Document) theDocument = myStack.Top(); | |
79 | if( theDocument == myMainDocument || theDocument->IsModified()) { | |
80 | ||
81 | if(!PCDM::FindStorageDriver(theDocument)){ | |
82 | Standard_SStream aMsg; | |
83 | aMsg <<"No storage driver does exist for this format: " << theDocument->StorageFormat() << (char)0; | |
84 | Standard_Failure::Raise(aMsg); | |
85 | } | |
86 | ||
87 | if(!theMetaDataDriver->FindFolder(theDocument->RequestedFolder())) { | |
88 | Standard_SStream aMsg; aMsg << "could not find the active dbunit"; | |
89 | aMsg << TCollection_ExtendedString(theDocument->RequestedFolder())<< (char)0; | |
90 | Standard_NoSuchObject::Raise(aMsg); | |
91 | } | |
92 | TCollection_ExtendedString theName=theMetaDataDriver->BuildFileName(theDocument); | |
93 | ||
94 | CDF_Timer theTimer; | |
95 | Handle(PCDM_StorageDriver) aDocumentStorageDriver = PCDM::StorageDriver(theDocument); | |
96 | ||
97 | aDocumentStorageDriver->Write(theDocument,theName); | |
98 | status = aDocumentStorageDriver->GetStoreStatus(); | |
99 | ||
100 | theTimer.ShowAndRestart("Driver->Write: "); | |
101 | ||
102 | aMetaData = theMetaDataDriver->CreateMetaData(theDocument,theName); | |
103 | theTimer.ShowAndStop("metadata creating: "); | |
104 | ||
105 | theDocument->SetMetaData(aMetaData); | |
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 | } | |
7fd59977 | 112 | } |
113 | } | |
114 | ||
115 | catch (CDF_MetaDataDriverError) { | |
116 | CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("metadatadriver failed; reason:")); | |
15e8b082 | 117 | status = PCDM_SS_DriverFailure; |
7fd59977 | 118 | } |
119 | catch (Standard_Failure) { | |
120 | CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("driver failed; reason:")); | |
15e8b082 | 121 | status = PCDM_SS_Failure; |
7fd59977 | 122 | } |
123 | } | |
124 | ||
125 | return status; | |
126 | } |