0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / XmlMDocStd / XmlMDocStd_XLinkDriver.cxx
1 // Created on: 2001-09-04
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <CDM_MessageDriver.hxx>
18 #include <Standard_Type.hxx>
19 #include <TDF_Attribute.hxx>
20 #include <TDF_Label.hxx>
21 #include <TDF_Tool.hxx>
22 #include <TDocStd_XLink.hxx>
23 #include <XmlMDocStd_XLinkDriver.hxx>
24 #include <XmlObjMgt.hxx>
25 #include <XmlObjMgt_Persistent.hxx>
26
27 IMPLEMENT_DOMSTRING (DocEntryString, "documentEntry")
28
29 //=======================================================================
30 //function : XmlMDocStd_XLinkDriver
31 //purpose  : Constructor
32 //=======================================================================
33 XmlMDocStd_XLinkDriver::XmlMDocStd_XLinkDriver
34                         (const Handle(CDM_MessageDriver)& theMsgDriver)
35       : XmlMDF_ADriver (theMsgDriver, NULL)
36 {}
37
38 //=======================================================================
39 //function : NewEmpty
40 //purpose  : 
41 //=======================================================================
42 Handle(TDF_Attribute) XmlMDocStd_XLinkDriver::NewEmpty() const
43 {
44   return (new TDocStd_XLink());
45 }
46
47 //=======================================================================
48 //function : Paste
49 //purpose  : persistent -> transient (retrieve)
50 //=======================================================================
51 Standard_Boolean XmlMDocStd_XLinkDriver::Paste
52                 (const XmlObjMgt_Persistent&  theSource,
53                  const Handle(TDF_Attribute)& theTarget,
54                  XmlObjMgt_RRelocationTable&  ) const
55 {
56   XmlObjMgt_DOMString anXPath = XmlObjMgt::GetStringValue (theSource);
57
58   if (anXPath == NULL)
59   {
60     WriteMessage ("XLink: Cannot retrieve reference string from element");
61     return Standard_False;
62   }
63
64   TCollection_AsciiString anEntry;
65   if (XmlObjMgt::GetTagEntryString (anXPath, anEntry) == Standard_False)
66   {
67     TCollection_ExtendedString aMessage =
68       TCollection_ExtendedString ("Cannot retrieve XLink reference from \"")
69         + anXPath + '\"';
70     WriteMessage (aMessage);
71     return Standard_False;
72   }
73
74   Handle(TDocStd_XLink) aRef = Handle(TDocStd_XLink)::DownCast(theTarget);
75
76   // set referenced label
77   aRef->LabelEntry(anEntry);
78
79   // document entry
80   aRef->DocumentEntry(theSource.Element().getAttribute(::DocEntryString()));
81
82   return Standard_True;
83 }
84
85 //=======================================================================
86 //function : Paste
87 //purpose  : transient -> persistent (store)
88 //           <label tag='1'>     <This is label entry 0:4:1>
89 //           ...
90 //           <label tag='8'>     <This is label entry 0:4:1:8>
91 //
92 //           <TDocStd_XLink id="621"> /document/label/label[@tag="4"]/label[@tag="1"]
93 //           </TDocStd_XLink>    <This is reference to label 0:4:1>
94 //=======================================================================
95 void XmlMDocStd_XLinkDriver::Paste (const Handle(TDF_Attribute)& theSource,
96                                     XmlObjMgt_Persistent&        theTarget,
97                                     XmlObjMgt_SRelocationTable&  ) const
98 {
99   Handle(TDocStd_XLink) aRef = Handle(TDocStd_XLink)::DownCast(theSource);
100   if (!aRef.IsNull())
101   {
102     // reference
103     TCollection_AsciiString anEntry = aRef->LabelEntry();
104     XmlObjMgt_DOMString aDOMString;
105     XmlObjMgt::SetTagEntryString (aDOMString, anEntry);
106     XmlObjMgt::SetStringValue (theTarget, aDOMString);
107
108     // document entry
109     theTarget.Element().setAttribute(::DocEntryString(),
110                                       aRef->DocumentEntry().ToCString());
111   }
112 }