38 #ifndef PI_PROPERTIES_XMLRPCDESERIALIZER 39 #define PI_PROPERTIES_XMLRPCDESERIALIZER 41 #include <xercesc/util/PlatformUtils.hpp> 42 #include <xercesc/util/TransService.hpp> 43 #include <xercesc/sax2/SAX2XMLReader.hpp> 44 #include <xercesc/sax2/XMLReaderFactory.hpp> 45 #include <xercesc/sax2/DefaultHandler.hpp> 46 #include <xercesc/sax2/Attributes.hpp> 47 #include <xercesc/util/XMLUniDefs.hpp> 48 #include <xercesc/framework/LocalFileInputSource.hpp> 57 #include "../Property.hpp" 69 #ifdef XERCES_CPP_NAMESPACE 70 using namespace XERCES_CPP_NAMESPACE;
80 enum State { STATE_NAME, STATE_BOOLEAN, STATE_CHAR, STATE_INT, STATE_DOUBLE,
STATE_STRING, STATE_PROPERTIES};
89 const XMLCh*
const localname,
90 const XMLCh*
const qname )
92 char *ln = XMLString::transcode( localname );
93 if ( !strcmp( ln,
"xmlrpc" ) )
98 if ( !strcmp( ln,
"boolean" ) )
101 std::stringstream buffer;
109 if ( !strcmp( ln,
"char" ) )
115 if ( !strcmp( ln,
"int" ) )
121 if ( !strcmp( ln,
"double" ) )
127 if ( !strcmp( ln,
"string" ) )
133 if ( !strcmp( ln,
"name" ) )
140 const XMLCh*
const localname,
141 const XMLCh*
const qname,
142 const Attributes& attributes )
144 char *ln = XMLString::transcode( localname );
145 if ( !strcmp( ln,
"boolean" ) )
146 state_stack.push( STATE_BOOLEAN );
148 if ( !strcmp( ln,
"char" ) )
149 state_stack.push( STATE_CHAR );
151 if ( !strcmp( ln,
"int" ) )
152 state_stack.push( STATE_INT );
154 if ( !strcmp( ln,
"double" ) )
155 state_stack.push( STATE_DOUBLE );
157 if ( !strcmp( ln,
"string" ) )
158 state_stack.push( STATE_STRING );
160 if ( !strcmp( ln,
"xmlrpc" ) )
161 state_stack.push( STATE_PROPERTIES );
163 if ( !strcmp( ln,
"name" ) )
164 state_stack.push( STATE_NAME );
167 void warning(
const SAXParseException& exception )
169 cerr <<
"\nWarning\n";
171 void error(
const SAXParseException& exception )
175 void fatalError(
const SAXParseException& exception )
177 cerr <<
"\nFatal error\n";
180 void characters(
const XMLCh*
const chars,
const unsigned int length )
183 switch ( state_stack.top() )
186 name = XMLString::transcode( chars );
190 value.sv = XMLString::transcode( chars );
194 string_value = XMLString::transcode( chars );
201 case STATE_PROPERTIES:
242 XMLPlatformUtils::Initialize();
243 name = XMLString::transcode( filename.c_str() );
244 fis =
new LocalFileInputSource( name );
251 XMLPlatformUtils::Terminate();
258 XMLPlatformUtils::Initialize();
260 catch (
const XMLException & toCatch )
262 cerr <<
"Error during initialization! :\n" <<
endl;
266 cerr <<
"other exception" <<
endl;
269 SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
275 parser->setContentHandler( &handler );
276 parser->setErrorHandler( &handler );
285 parser->parse( *fis );
286 errorCount = parser->getErrorCount();
288 catch (
const XMLException & toCatch )
290 cerr <<
"\nAn XML parsing error occurred\n Error: " <<
endl;
291 XMLPlatformUtils::Terminate();
296 cerr <<
"General error" <<
endl;
297 XMLPlatformUtils::Terminate();
void characters(const XMLCh *const chars, const unsigned int length)
void add(base::PropertyBase *p)
std::stack< State > state_stack
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attributes)
A container for holding references to properties.
XMLRPCDemarshaller(const std::string filename)
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
basic_ostreams & endl(basic_ostreams &s)
An interface for extracting properties from a format.
virtual bool deserialize(PropertyBag &v)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
SAX2XMLRPCHandler(PropertyBag &b)