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 | |
7fd59977 | 17 | |
42cf5bc1 | 18 | #include <CDF_Application.hxx> |
19 | #include <CDF_MetaDataDriver.hxx> | |
20 | #include <CDF_MetaDataDriverError.hxx> | |
21 | #include <CDF_Session.hxx> | |
22 | #include <CDF_StoreList.hxx> | |
23 | #include <CDF_Timer.hxx> | |
24 | #include <CDM_Document.hxx> | |
25 | #include <CDM_MetaData.hxx> | |
7fd59977 | 26 | #include <CDM_ReferenceIterator.hxx> |
7fd59977 | 27 | #include <PCDM.hxx> |
28 | #include <PCDM_Document.hxx> | |
29 | #include <PCDM_StorageDriver.hxx> | |
42cf5bc1 | 30 | #include <Standard_ErrorHandler.hxx> |
31 | #include <Standard_Macro.hxx> | |
32 | #include <Standard_NoSuchObject.hxx> | |
33 | #include <Standard_Type.hxx> | |
34 | #include <TCollection_ExtendedString.hxx> | |
7fd59977 | 35 | |
92efcf78 | 36 | IMPLEMENT_STANDARD_RTTIEXT(CDF_StoreList,Standard_Transient) |
37 | ||
7fd59977 | 38 | static void CAUGHT(TCollection_ExtendedString& status,const TCollection_ExtendedString& what) { |
39 | Handle(Standard_Failure) F = Standard_Failure::Caught(); | |
40 | status += what; | |
41 | status += F->GetMessageString(); | |
42 | } | |
43 | ||
44 | CDF_StoreList::CDF_StoreList(const Handle(CDM_Document)& aDocument) { | |
45 | myMainDocument = aDocument; | |
46 | Add(aDocument); | |
47 | } | |
48 | ||
49 | void CDF_StoreList::Add(const Handle(CDM_Document)& aDocument) { | |
50 | ||
51 | if(!myItems.Contains(aDocument) && aDocument != myMainDocument) myItems.Add(aDocument); | |
6af4fe1c | 52 | myStack.Prepend(aDocument); |
7fd59977 | 53 | |
54 | CDM_ReferenceIterator it(aDocument); | |
55 | for (;it.More();it.Next()) { | |
56 | if(it.Document()->IsModified()) Add(it.Document()); | |
57 | } | |
58 | } | |
59 | Standard_Boolean CDF_StoreList::IsConsistent () const { | |
60 | Standard_Boolean yes = Standard_True; | |
61 | CDM_MapIteratorOfMapOfDocument it (myItems); | |
62 | for ( ; it.More() && yes ; it.Next()) { | |
63 | yes = it.Key()->HasRequestedFolder(); | |
64 | } | |
65 | return yes && myMainDocument->HasRequestedFolder(); | |
66 | } | |
67 | void CDF_StoreList::Init() { | |
68 | myIterator = CDM_MapIteratorOfMapOfDocument(myItems); | |
69 | } | |
70 | Standard_Boolean CDF_StoreList::More() const { | |
71 | return myIterator.More(); | |
72 | } | |
73 | ||
74 | void CDF_StoreList::Next() { | |
75 | myIterator.Next(); | |
76 | } | |
77 | ||
78 | Handle(CDM_Document) CDF_StoreList::Value() const { | |
79 | return myIterator.Key(); | |
80 | } | |
15e8b082 | 81 | PCDM_StoreStatus CDF_StoreList::Store (Handle(CDM_MetaData)& aMetaData, TCollection_ExtendedString& aStatusAssociatedText) { |
7fd59977 | 82 | |
83 | Handle(CDF_MetaDataDriver) theMetaDataDriver = CDF_Session::CurrentSession()->MetaDataDriver(); | |
84 | ||
15e8b082 | 85 | PCDM_StoreStatus status = PCDM_SS_OK; |
7fd59977 | 86 | { |
87 | try { | |
88 | OCC_CATCH_SIGNALS | |
6af4fe1c | 89 | for (; !myStack.IsEmpty(); myStack.RemoveFirst()) { |
15e8b082 | 90 | |
6af4fe1c | 91 | Handle(CDM_Document) theDocument = myStack.First(); |
15e8b082 M |
92 | if( theDocument == myMainDocument || theDocument->IsModified()) { |
93 | ||
94 | if(!PCDM::FindStorageDriver(theDocument)){ | |
95 | Standard_SStream aMsg; | |
96 | aMsg <<"No storage driver does exist for this format: " << theDocument->StorageFormat() << (char)0; | |
97 | Standard_Failure::Raise(aMsg); | |
98 | } | |
99 | ||
100 | if(!theMetaDataDriver->FindFolder(theDocument->RequestedFolder())) { | |
101 | Standard_SStream aMsg; aMsg << "could not find the active dbunit"; | |
102 | aMsg << TCollection_ExtendedString(theDocument->RequestedFolder())<< (char)0; | |
103 | Standard_NoSuchObject::Raise(aMsg); | |
104 | } | |
105 | TCollection_ExtendedString theName=theMetaDataDriver->BuildFileName(theDocument); | |
106 | ||
107 | CDF_Timer theTimer; | |
108 | Handle(PCDM_StorageDriver) aDocumentStorageDriver = PCDM::StorageDriver(theDocument); | |
109 | ||
110 | aDocumentStorageDriver->Write(theDocument,theName); | |
111 | status = aDocumentStorageDriver->GetStoreStatus(); | |
112 | ||
113 | theTimer.ShowAndRestart("Driver->Write: "); | |
114 | ||
115 | aMetaData = theMetaDataDriver->CreateMetaData(theDocument,theName); | |
116 | theTimer.ShowAndStop("metadata creating: "); | |
117 | ||
118 | theDocument->SetMetaData(aMetaData); | |
119 | ||
120 | CDM_ReferenceIterator it(theDocument); | |
121 | for(; it.More();it.Next()) { | |
122 | theMetaDataDriver->CreateReference(aMetaData,it.Document()->MetaData(),it.ReferenceIdentifier(),it.DocumentVersion()); | |
123 | } | |
124 | } | |
7fd59977 | 125 | } |
126 | } | |
127 | ||
128 | catch (CDF_MetaDataDriverError) { | |
129 | CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("metadatadriver failed; reason:")); | |
15e8b082 | 130 | status = PCDM_SS_DriverFailure; |
7fd59977 | 131 | } |
132 | catch (Standard_Failure) { | |
133 | CAUGHT(aStatusAssociatedText,TCollection_ExtendedString("driver failed; reason:")); | |
15e8b082 | 134 | status = PCDM_SS_Failure; |
7fd59977 | 135 | } |
136 | } | |
137 | ||
138 | return status; | |
139 | } |