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