]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/XMLCORBAConv.cxx
Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / runtime / XMLCORBAConv.cxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "TypeConversions.hxx"
20 #include "XMLCORBAConv.hxx"
21 #include "CORBAXMLConv.hxx"
22 #include "CORBAPorts.hxx"
23 #include "TypeCode.hxx"
24
25 #include <libxml/parser.h>
26 #include <iostream>
27 #include <sstream>
28
29 //#define _DEVDEBUG_
30 #include "YacsTrace.hxx"
31
32 using namespace YACS::ENGINE;
33 using namespace std;
34
35 XmlCorba::XmlCorba(InputCorbaPort* p)
36   : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
37 {
38 }
39
40 void XmlCorba::put(const void *data) throw(ConversionException)
41 {
42   DEBTRACE((const char *)data);
43   put((const char *)data);
44 }
45
46 //!Convert a XML (char *) to CORBA::Any  and push it in the proxy port
47  /*!
48   *   \param data : Xml::char *
49   */
50 void XmlCorba::put(const char *data) throw(ConversionException)
51 {
52   DEBTRACE(data);
53   xmlDocPtr doc;
54   xmlNodePtr cur;
55   CORBA::Any *a=NULL;
56   
57   doc = xmlParseMemory(data, strlen(data));
58   if (doc == NULL ) 
59     {
60       stringstream msg;
61       msg << "Problem in conversion: XML Document not parsed successfully ";
62       msg << " (" << __FILE__ << ":" << __LINE__ << ")";
63       throw ConversionException(msg.str());
64     }
65   cur = xmlDocGetRootElement(doc);
66   if (cur == NULL) 
67     {
68       xmlFreeDoc(doc);
69       stringstream msg;
70       msg << "Problem in conversion: empty XML Document";
71       msg << " (" << __FILE__ << ":" << __LINE__ << ")";
72       throw ConversionException(msg.str());
73     }
74   while (cur != NULL)
75     {
76       if ((!xmlStrcmp(cur->name, (const xmlChar *)"value")))
77         {
78           try
79             {
80               a=convertXmlCorba(edGetType(),doc,cur);
81             }
82           catch(ConversionException)
83             {
84               throw;
85             }
86           catch(...)
87             {
88               stringstream msg;
89               msg << "Problem in conversion: kind= " << edGetType()->kind() ;
90               msg << " (" << __FILE__ << ":" << __LINE__ << ")";
91               throw ConversionException(msg.str());
92             }
93           break;
94         }
95       cur = cur->next;
96     }
97   xmlFreeDoc(doc);
98   if(a==NULL)
99     {
100       stringstream msg;
101       msg << "Problem in conversion: incorrect XML value";
102       msg << " (" << __FILE__ << ":" << __LINE__ << ")";
103       throw ConversionException(msg.str());
104     }
105
106   //xmlCleanupParser();
107   _port->put(a);
108   _port->setStringRef(data);
109   //delete Any that has been allocated by convertXmlCorba
110   delete a;
111 }