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