1 // Created on: 2001-08-01
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <CDM_MessageDriver.hxx>
18 #include <Standard_Type.hxx>
19 #include <TDataStd_Name.hxx>
20 #include <TDF_Attribute.hxx>
21 #include <XmlMDataStd_NameDriver.hxx>
22 #include <XmlObjMgt.hxx>
23 #include <XmlObjMgt_Persistent.hxx>
24 #include <XmlObjMgt_RRelocationTable.hxx>
25 #include <XmlObjMgt_SRelocationTable.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_NameDriver,XmlMDF_ADriver)
28 IMPLEMENT_DOMSTRING (AttributeIDString, "nameguid")
29 //=======================================================================
30 //function : XmlMDataStd_NameDriver
31 //purpose : Constructor
32 //=======================================================================
33 XmlMDataStd_NameDriver::XmlMDataStd_NameDriver
34 (const Handle(CDM_MessageDriver)& theMsgDriver)
35 : XmlMDF_ADriver (theMsgDriver, NULL)
38 //=======================================================================
39 //function : NewEmpty()
41 //=======================================================================
42 Handle(TDF_Attribute) XmlMDataStd_NameDriver::NewEmpty () const
44 return (new TDataStd_Name());
47 //=======================================================================
50 //=======================================================================
51 Standard_Boolean XmlMDataStd_NameDriver::Paste
52 (const XmlObjMgt_Persistent& theSource,
53 const Handle(TDF_Attribute)& theTarget,
54 XmlObjMgt_RRelocationTable& ) const
56 if(!theTarget.IsNull()) {
57 TCollection_ExtendedString aString;
58 if (XmlObjMgt::GetExtendedString (theSource, aString))
60 Handle(TDataStd_Name)::DownCast(theTarget) -> Set (aString);
63 const XmlObjMgt_Element& anElement = theSource;
64 XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
65 if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
66 aGUID = TDataStd_Name::GetID(); //default case
68 aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
70 Handle(TDataStd_Name)::DownCast(theTarget)->SetID(aGUID);
74 WriteMessage("error retrieving ExtendedString for type TDataStd_Name");
75 return Standard_False;
78 //=======================================================================
81 //=======================================================================
82 void XmlMDataStd_NameDriver::Paste (const Handle(TDF_Attribute)& theSource,
83 XmlObjMgt_Persistent& theTarget,
84 XmlObjMgt_SRelocationTable& ) const
86 Handle(TDataStd_Name) aName = Handle(TDataStd_Name)::DownCast(theSource);
87 if (aName.IsNull()) return;
88 XmlObjMgt::SetExtendedString (theTarget, aName -> Get());
89 if(aName->ID() != TDataStd_Name::GetID()) {
91 Standard_Character aGuidStr [Standard_GUID_SIZE_ALLOC];
92 Standard_PCharacter pGuidStr = aGuidStr;
93 aName->ID().ToCString (pGuidStr);
94 theTarget.Element().setAttribute (::AttributeIDString(), aGuidStr);