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