]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/XMLCppConv.cxx
Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / runtime / XMLCppConv.cxx
1
2 #include "TypeConversions.hxx"
3 #include "XMLCppConv.hxx"
4
5
6 #include <libxml/parser.h>
7 #include <iostream>
8 #include <sstream>
9 #include "Any.hxx"
10
11 //#define _DEVDEBUG_
12 #include "YacsTrace.hxx"
13
14 using namespace std;
15
16 namespace YACS
17 {
18   namespace ENGINE
19   {
20     Any * convertXmlCpp(const TypeCode *t, xmlDocPtr doc, xmlNodePtr cur)
21     {
22       return convertXmlNeutral(t, doc, cur);
23     }
24
25     XmlCpp::XmlCpp(InputPort* p)
26       : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
27     {
28     }
29
30     void XmlCpp::put(const void *data) throw(ConversionException)
31     {
32       DEBTRACE(" XmlCpp::put(const void *data)");
33       put((const char *)data);
34     }
35
36     //!Convert received XML (char *) value to C++ (Any *) value and send it to proxy port
37     /*!
38      *   \param data : Xml::char *
39      */
40
41     void XmlCpp::put(const char *data) throw(ConversionException)
42     {
43       DEBTRACE("XmlCpp::put " << data);
44       xmlDocPtr doc;
45       xmlNodePtr cur;
46       Any *ob;
47       {
48         doc = xmlParseMemory(data, strlen(data));
49         if (doc == NULL )
50           {
51             stringstream msg;
52             msg << "Problem in conversion: XML Document not parsed successfully ";
53             msg << " (" << __FILE__ << ":" << __LINE__ << ")";
54             throw ConversionException(msg.str());
55           }
56         cur = xmlDocGetRootElement(doc);
57         if (cur == NULL)
58           {
59             xmlFreeDoc(doc);
60             stringstream msg;
61             msg << "Problem in conversion: empty XML Document";
62             msg << " (" << __FILE__ << ":" << __LINE__ << ")";
63             throw ConversionException(msg.str());
64           }
65         while (cur != NULL)
66           {
67             if ((!xmlStrcmp(cur->name, (const xmlChar *)"value")))
68               {
69                 ob=convertXmlCpp(edGetType(),doc,cur);
70                 break;
71               }
72             cur = cur->next;
73           }
74         xmlFreeDoc(doc);
75         //xmlCleanupParser();
76       }
77       _port->put(ob);
78       ob->decrRef();
79     }
80
81     int isAdaptableCppXml(const TypeCode *t1, const TypeCode *t2)
82     {
83       return isAdaptableNeutralXml(t1, t2);
84     }
85   }
86 }