0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / XmlMDF / XmlMDF_ReferenceDriver.cxx
CommitLineData
b311480e 1// Created on: 2001-09-04
2// Created by: Julia DOROVSKIKH
973c2be1 3// Copyright (c) 2001-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
16//AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
7fd59977 17
42cf5bc1 18#include <CDM_MessageDriver.hxx>
19#include <Standard_Type.hxx>
20#include <TDF_Attribute.hxx>
7fd59977 21#include <TDF_Reference.hxx>
22#include <TDF_Tool.hxx>
42cf5bc1 23#include <XmlMDF_ReferenceDriver.hxx>
24#include <XmlObjMgt.hxx>
25#include <XmlObjMgt_Persistent.hxx>
7fd59977 26
27//=======================================================================
28//function : XmlMDF_ReferenceDriver
29//purpose : Constructor
30//=======================================================================
31XmlMDF_ReferenceDriver::XmlMDF_ReferenceDriver
32 (const Handle(CDM_MessageDriver)& theMsgDriver)
33 : XmlMDF_ADriver (theMsgDriver, NULL)
34{}
35
36//=======================================================================
37//function : NewEmpty
38//purpose :
39//=======================================================================
40Handle(TDF_Attribute) XmlMDF_ReferenceDriver::NewEmpty() const
41{
42 return (new TDF_Reference());
43}
44
45//=======================================================================
46//function : Paste
47//purpose : persistent -> transient (retrieve)
48//=======================================================================
49Standard_Boolean XmlMDF_ReferenceDriver::Paste
50 (const XmlObjMgt_Persistent& theSource,
51 const Handle(TDF_Attribute)& theTarget,
52 XmlObjMgt_RRelocationTable& ) const
53{
54 XmlObjMgt_DOMString anXPath = XmlObjMgt::GetStringValue(theSource);
55
56 if (anXPath == NULL)
57 {
58 WriteMessage ("Cannot retrieve reference string from element");
59 return Standard_False;
60 }
61
62 TCollection_AsciiString anEntry;
63 if (XmlObjMgt::GetTagEntryString (anXPath, anEntry) == Standard_False)
64 {
65 TCollection_ExtendedString aMessage =
66 TCollection_ExtendedString ("Cannot retrieve reference from \"")
67 + anXPath + '\"';
68 WriteMessage (aMessage);
69 return Standard_False;
70 }
71
72 Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theTarget);
73
74 // find label by entry
75 TDF_Label tLab; // Null label.
76 if (anEntry.Length() > 0)
77 {
78 TDF_Tool::Label(aRef->Label().Data(), anEntry, tLab, Standard_True);
79 }
80
81 // set referenced label
82 aRef->Set(tLab);
83
84 return Standard_True;
85}
86
87//=======================================================================
88//function : Paste
89//purpose : transient -> persistent (store)
90// <label tag='1'> <This is label entry 0:4:1>
91// ...
92// <label tag='8'> <This is label entry 0:4:1:8>
93//
94// <TDF_Reference id="621"> /document/label/label[@tag="4"]/label[@tag="1"]
95// </TDF_Reference> <This is reference to label 0:4:1>
96//=======================================================================
97void XmlMDF_ReferenceDriver::Paste (const Handle(TDF_Attribute)& theSource,
98 XmlObjMgt_Persistent& theTarget,
99 XmlObjMgt_SRelocationTable& ) const
100{
101 Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theSource);
102 if (!aRef.IsNull())
103 {
104 const TDF_Label& lab = aRef->Label();
105 const TDF_Label& refLab = aRef->Get();
106 if (!lab.IsNull() && !refLab.IsNull())
107 {
108 if (lab.IsDescendant(refLab.Root()))
109 {
110 // Internal reference
111 TCollection_AsciiString anEntry;
112 TDF_Tool::Entry(refLab, anEntry);
113
114 XmlObjMgt_DOMString aDOMString;
115 XmlObjMgt::SetTagEntryString (aDOMString, anEntry);
116 // No occurrence of '&', '<' and other irregular XML characters
117 XmlObjMgt::SetStringValue (theTarget, aDOMString, Standard_True);
118 }
119 }
120 }
121}