0022627: Change OCCT memory management defaults
[occt.git] / src / XmlMDocStd / XmlMDocStd_XLinkDriver.cxx
CommitLineData
7fd59977 1// File: XmlMDocStd_XLinkDriver.cxx
2// Created: 04.09.01 14:47:31
3// Author: Julia DOROVSKIKH
4// Copyright: Open Cascade 2001
5// History:
6
7#include <XmlMDocStd_XLinkDriver.ixx>
8
9#include <XmlObjMgt.hxx>
10
11#include <TDocStd_XLink.hxx>
12#include <TDF_Tool.hxx>
13#include <TDF_Label.hxx>
14
15IMPLEMENT_DOMSTRING (DocEntryString, "documentEntry")
16
17//=======================================================================
18//function : XmlMDocStd_XLinkDriver
19//purpose : Constructor
20//=======================================================================
21XmlMDocStd_XLinkDriver::XmlMDocStd_XLinkDriver
22 (const Handle(CDM_MessageDriver)& theMsgDriver)
23 : XmlMDF_ADriver (theMsgDriver, NULL)
24{}
25
26//=======================================================================
27//function : NewEmpty
28//purpose :
29//=======================================================================
30Handle(TDF_Attribute) XmlMDocStd_XLinkDriver::NewEmpty() const
31{
32 return (new TDocStd_XLink());
33}
34
35//=======================================================================
36//function : Paste
37//purpose : persistent -> transient (retrieve)
38//=======================================================================
39Standard_Boolean XmlMDocStd_XLinkDriver::Paste
40 (const XmlObjMgt_Persistent& theSource,
41 const Handle(TDF_Attribute)& theTarget,
42 XmlObjMgt_RRelocationTable& ) const
43{
44 XmlObjMgt_DOMString anXPath = XmlObjMgt::GetStringValue (theSource);
45
46 if (anXPath == NULL)
47 {
48 WriteMessage ("XLink: Cannot retrieve reference string from element");
49 return Standard_False;
50 }
51
52 TCollection_AsciiString anEntry;
53 if (XmlObjMgt::GetTagEntryString (anXPath, anEntry) == Standard_False)
54 {
55 TCollection_ExtendedString aMessage =
56 TCollection_ExtendedString ("Cannot retrieve XLink reference from \"")
57 + anXPath + '\"';
58 WriteMessage (aMessage);
59 return Standard_False;
60 }
61
62 Handle(TDocStd_XLink) aRef = Handle(TDocStd_XLink)::DownCast(theTarget);
63
64 // set referenced label
65 aRef->LabelEntry(anEntry);
66
67 // document entry
68 aRef->DocumentEntry(theSource.Element().getAttribute(::DocEntryString()));
69
70 return Standard_True;
71}
72
73//=======================================================================
74//function : Paste
75//purpose : transient -> persistent (store)
76// <label tag='1'> <This is label entry 0:4:1>
77// ...
78// <label tag='8'> <This is label entry 0:4:1:8>
79//
80// <TDocStd_XLink id="621"> /document/label/label[@tag="4"]/label[@tag="1"]
81// </TDocStd_XLink> <This is reference to label 0:4:1>
82//=======================================================================
83void XmlMDocStd_XLinkDriver::Paste (const Handle(TDF_Attribute)& theSource,
84 XmlObjMgt_Persistent& theTarget,
85 XmlObjMgt_SRelocationTable& ) const
86{
87 Handle(TDocStd_XLink) aRef = Handle(TDocStd_XLink)::DownCast(theSource);
88 if (!aRef.IsNull())
89 {
90 // reference
91 TCollection_AsciiString anEntry = aRef->LabelEntry();
92 XmlObjMgt_DOMString aDOMString;
93 XmlObjMgt::SetTagEntryString (aDOMString, anEntry);
94 XmlObjMgt::SetStringValue (theTarget, aDOMString);
95
96 // document entry
97 theTarget.Element().setAttribute(::DocEntryString(),
98 aRef->DocumentEntry().ToCString());
99 }
100}