-/* $Id: router_flexml.cpp,v 1.6 2005-12-08 22:32:57 adam Exp $
+/* $Id: router_flexml.cpp,v 1.8 2006-01-04 14:15:45 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "config.hpp"
#include "router_flexml.hpp"
+#include "filter_factory.hpp"
+#include "factory_static.hpp"
#include <iostream>
#include <map>
friend class RouterFleXML;
Rep();
- typedef std::map<std::string, boost::shared_ptr<const yp2::filter::Base> >
- IdFilterMap ;
- typedef std::list<std::string> FilterIdList;
- typedef std::map<std::string, FilterIdList > IdRouteMap ;
+ typedef std::map<std::string,
+ boost::shared_ptr<const yp2::filter::Base > >
+ IdFilterMap ;
- bool m_xinclude;
IdFilterMap m_id_filter_map;
- FilterIdList m_filter_id_list;
- IdRouteMap m_id_route_map;
void create_filter(std::string type,
const xmlDoc * xmldoc,
const xmlNode* jump_to_next(const xmlNode* node, int xml_node_type);
const xmlNode* jump_to_children(const xmlNode* node, int xml_node_type);
+ bool m_xinclude;
+ private:
+ FilterFactory *m_factory; // TODO shared_ptr
};
}
filter_nr++;
std::cout << "processing /yp2/filters/filter["
<< filter_nr << "]" << std::endl;
+
+ const struct _xmlAttr *attr;
+ std::string id_value;
+ std::string type_value;
+ for (attr = node2->properties; attr; attr = attr->next)
+ {
+ std::string name = std::string((const char *) attr->name);
+ std::string value;
+
+ if (attr->children && attr->children->type == XML_TEXT_NODE)
+ value = std::string((const char *)attr->children->content);
+
+ if (name == "id")
+ id_value = value;
+ else if (name == "type")
+ type_value = value;
+ else
+ throw XMLError("Error. Only attribute id or type allowed in filter element. Got " + name);
+
+ std::cout << "attr " << name << "=" << value << "\n";
+
+ //const xmlNode *val;
+ }
+
+ yp2::filter::Base* filter_base = m_factory->create(type_value);
+
+ filter_base->configure(node2);
+
+ if (m_id_filter_map.find(id_value) != m_id_filter_map.end())
+ throw XMLError("Filter " + id_value + " already defined");
+
+ m_id_filter_map[id_value] =
+ boost::shared_ptr<yp2::filter::Base>(filter_base);
+
node2 = jump_to_next(node2, XML_ELEMENT_NODE);
}
{
}
-yp2::RouterFleXML::RouterFleXML(std::string xmlconf)
+yp2::RouterFleXML::RouterFleXML(std::string xmlconf, yp2::FilterFactory &factory)
: m_p(new Rep)
{
+
+ m_p->m_factory = &factory;
+
LIBXML_TEST_VERSION;
xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(),