Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1997-08-08 |
2 | // Created by: Jean-Louis Frenkel | |
3 | // Copyright (c) 1997-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
17 | #include <CDF_StoreList.ixx> | |
18 | ||
19 | #include <Standard_ErrorHandler.hxx> | |
20 | #include <Standard_Macro.hxx> | |
21 | ||
22 | #include <CDM_ReferenceIterator.hxx> | |
23 | ||
24 | #include <PCDM.hxx> | |
25 | #include <PCDM_Document.hxx> | |
26 | #include <PCDM_StorageDriver.hxx> | |
27 | ||
28 | #include <CDF_MetaDataDriverError.hxx> | |
29 | #include <CDF_MetaDataDriver.hxx> | |
30 | ||
31 | #include <CDF_Session.hxx> | |
32 | #include <CDF_Application.hxx> | |
33 | #include <CDF_Timer.hxx> | |
34 | ||
35 | static void CAUGHT(TCollection_ExtendedString& status,const TCollection_ExtendedString& what) { | |
36 | Handle(Standard_Failure) F = Standard_Failure::Caught(); | |
37 | status += what; | |
38 | status += F->GetMessageString(); | |
39 | } | |
40 | ||
41 | CDF_StoreList::CDF_StoreList(const Handle(CDM_Document)& aDocument) { | |
42 | myMainDocument = aDocument; | |
43 | Add(aDocument); | |
44 | } | |
45 | ||
46 | void CDF_StoreList::Add(const Handle(CDM_Document)& aDocument) { | |
47 | ||
48 | if(!myItems.Contains(aDocument) && aDocument != myMainDocument) myItems.Add(aDocument); | |
49 | myStack.Push(aDocument); | |
50 | ||
51 | CDM_ReferenceIterator it(aDocument); | |
52 | for (;it.More();it.Next()) { | |
53 | if(it.Document()->IsModified()) Add(it.Document()); | |
54 | } | |
55 | } | |
56 | Standard_Boolean CDF_StoreList::IsConsistent () const { | |
57 | Standard_Boolean yes = Standard_True; | |
58 | CDM_MapIteratorOfMapOfDocument it (myItems); | |
59 | for ( ; it.More() && yes ; it.Next()) { | |
60 | yes = it.Key()->HasRequestedFolder(); | |
61 | } | |
62 | return yes && myMainDocument->HasRequestedFolder(); | |
63 | } | |
64 | void CDF_StoreList::Init() { | |
65 | myIterator = CDM_MapIteratorOfMapOfDocument(myItems); | |
66 | } | |
67 | Standard_Boolean CDF_StoreList::More() const { | |
68 | return myIterator.More(); | |
69 | } | |
70 | ||
71 | void CDF_StoreList::Next() { | |
72 | myIterator.Next(); | |
73 | } | |
74 | ||
75 | Handle(CDM_Document) CDF_StoreList::Value() const { | |
76 | return myIterator.Key(); | |
77 | } | |
15e8b082 | 78 | PCDM_StoreStatus CDF_StoreList::Store (Handle(CDM_MetaData)& aMetaData, TCollection_ExtendedString& aStatusAssociatedText) { |
7fd59977 | 79 | |
80 | Handle(CDF_MetaDataDriver) theMetaDataDriver = CDF_Session::CurrentSession()->MetaDataDriver(); | |
81 | ||
15e8b082 | 82 | PCDM_StoreStatus status = PCDM_SS_OK; |
7fd59977 | 83 | { |
84 | try { | |
85 | OCC_CATCH_SIGNALS | |
86 | for (; !myStack.IsEmpty(); myStack.Pop()) { | |
15e8b082 M |
87 | |
88 | Handle(CDM_Document) theDocument = myStack.Top(); | |
89 | if( theDocument == myMainDocument || theDocument->IsModified()) { | |
90 | ||
91 | if(!PCDM::FindStorageDriver(theDocument)){ | |
92 | Standard_SStream aMsg; | |
93 | aMsg <<"No storage driver does exist for this format: " << theDocument->StorageFormat() << (char)0; | |
94 | Standard_Failure::Raise(aMsg); | |
95 | } | |
96 | ||
97 | if(!theMetaDataDriver->FindFolder(theDocument->RequestedFolder())) { | |
98 | Standard_SStream aMsg; aMsg << "could not find the active dbunit"; | |
99 | aMsg << TCollection_ExtendedString(theDocument->RequestedFolder())<< (char)0; | |
100 | Standard_NoSuchObject::Raise(aMsg); | |
101 | } | |
102 | TCollection_ExtendedString theName=theMetaDataDriver->BuildFileName(theDocument); | |
103 | ||
104 | CDF_Timer theTimer; | |
105 | Handle(PCDM_StorageDriver) aDocumentStorageDriver = PCDM::StorageDriver(theDocument); | |
106 | ||
107 | aDocumentStorageDriver->Write(theDocument,theName); | |
108 | status = aDocumentStorageDriver->GetStoreStatus(); | |
109 | ||
110 | theTimer.ShowAndRestart("Driver->Write: "); | |
111 | ||
112 | aMetaData = theMetaDataDriver->CreateMetaData(theDocument,theName); | |
113 | theTimer.ShowAndStop("metadata creating: "); | |
114 | ||
115 | theDocument->SetMetaData(aMetaData); | |
116 | ||
117 | CDM_ReferenceIterator it(theDocument); | |
118 | for(; it.More();it.Next()) { | |
119 | theMetaDataDriver->CreateReference(aMetaData,it.Document()->MetaData(),it.ReferenceIdentifier(),it.DocumentVersion()); | |
120 | } | |
121 | } | |
7fd59977 | 122 | } |
123 | } | |
124 | ||
125 | catch (CDF_MetaDataDriverError) { | |
126 | CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("metadatadriver failed; reason:")); | |
15e8b082 | 127 | status = PCDM_SS_DriverFailure; |
7fd59977 | 128 | } |
129 | catch (Standard_Failure) { | |
130 | CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("driver failed; reason:")); | |
15e8b082 | 131 | status = PCDM_SS_Failure; |
7fd59977 | 132 | } |
133 | } | |
134 | ||
135 | return status; | |
136 | } |