-/* $Id: router_flexml.cpp,v 1.13 2006-01-11 11:51:50 adam Exp $
+/* $Id: router_flexml.cpp,v 1.16 2006-01-19 09:41:01 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
std::string m_start_route;
- void parse_xml_config_dom(xmlDocPtr doc);
+ std::string m_dl_path;
- bool check_element_yp2(const xmlNode *ptr,
- const std::string &name);
-
- const xmlNode* jump_to(const xmlNode* node, int xml_node_type);
+ void parse_xml_config_dom(xmlDocPtr doc);
- const xmlNode* jump_to_next(const xmlNode* node, int xml_node_type);
-
- const xmlNode* jump_to_children(const xmlNode* node, int xml_node_type);
void parse_xml_filters(xmlDocPtr doc, const xmlNode *node);
void parse_xml_routes(xmlDocPtr doc, const xmlNode *node);
};
}
-const xmlNode* yp2::RouterFleXML::Rep::jump_to_children(const xmlNode* node,
- int xml_node_type)
-{
- node = node->children;
- for (; node && node->type != xml_node_type; node = node->next)
- ;
- return node;
-}
-
-const xmlNode* yp2::RouterFleXML::Rep::jump_to_next(const xmlNode* node,
- int xml_node_type)
-{
- node = node->next;
- for (; node && node->type != xml_node_type; node = node->next)
- ;
- return node;
-}
-
-const xmlNode* yp2::RouterFleXML::Rep::jump_to(const xmlNode* node,
- int xml_node_type)
-{
- for (; node && node->type != xml_node_type; node = node->next)
- ;
- return node;
-}
-
-bool yp2::RouterFleXML::Rep::check_element_yp2(const xmlNode *ptr,
- const std::string &name)
-{
- if (!yp2::xml::is_element_yp2(ptr, name))
- throw yp2::XMLError("Expected element name " + name);
- return true;
-}
-
-
void yp2::RouterFleXML::Rep::parse_xml_filters(xmlDocPtr doc,
const xmlNode *node)
{
unsigned int filter_nr = 0;
- while(node && check_element_yp2(node, "filter"))
+ while(node && yp2::xml::check_element_yp2(node, "filter"))
{
filter_nr++;
" in filter element. Got " + name);
}
+ if (!m_factory->exist(type_value))
+ {
+ std::cout << "about to load " << type_value << ", path=" <<
+ m_dl_path << "\n";
+ m_factory->add_creator_dl(type_value, m_dl_path);
+ }
yp2::filter::Base* filter_base = m_factory->create(type_value);
filter_base->configure(node);
m_id_filter_map[id_value] =
boost::shared_ptr<yp2::filter::Base>(filter_base);
- node = jump_to_next(node, XML_ELEMENT_NODE);
+ node = yp2::xml::jump_to_next(node, XML_ELEMENT_NODE);
}
}
void yp2::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc,
const xmlNode *node)
{
- check_element_yp2(node, "route");
+ yp2::xml::check_element_yp2(node, "route");
unsigned int route_nr = 0;
while(yp2::xml::is_element_yp2(node, "route"))
id_value = value;
else
throw yp2::XMLError("Only attribute 'id' allowed for"
- " element 'route'."
- " Got " + name);
+ " element 'route'."
+ " Got " + name);
}
Route route;
// process <filter> nodes in third level
- const xmlNode* node3 = jump_to_children(node, XML_ELEMENT_NODE);
+ const xmlNode* node3 = yp2::xml::jump_to_children(node, XML_ELEMENT_NODE);
unsigned int filter3_nr = 0;
- while(node3 && check_element_yp2(node3, "filter"))
+ while(node3 && yp2::xml::check_element_yp2(node3, "filter"))
{
filter3_nr++;
}
else if (type_value.length())
{
+ if (!m_factory->exist(type_value))
+ {
+ std::cout << "about to load " << type_value << ", path=" <<
+ m_dl_path << "\n";
+ m_factory->add_creator_dl(type_value, m_dl_path);
+ }
yp2::filter::Base* filter_base = m_factory->create(type_value);
filter_base->configure(node3);
route.m_list.push_back(
boost::shared_ptr<yp2::filter::Base>(filter_base));
}
- node3 = jump_to_next(node3, XML_ELEMENT_NODE);
+ node3 = yp2::xml::jump_to_next(node3, XML_ELEMENT_NODE);
}
std::map<std::string,RouterFleXML::Route>::iterator it;
+ "' already exist");
else
m_routes[id_value] = route;
- node = jump_to_next(node, XML_ELEMENT_NODE);
+ node = yp2::xml::jump_to_next(node, XML_ELEMENT_NODE);
}
}
const xmlNode* root = xmlDocGetRootElement(doc);
- check_element_yp2(root, "yp2");
+ yp2::xml::check_element_yp2(root, "yp2");
+
+ const xmlNode* node = yp2::xml::jump_to_children(root, XML_ELEMENT_NODE);
+ if (yp2::xml::is_element_yp2(node, "dlpath"))
+ {
+ m_dl_path = yp2::xml::get_text(node);
+ node = yp2::xml::jump_to_next(node, XML_ELEMENT_NODE);
+ }
// process <start> node which is expected first element node
- const xmlNode* node = jump_to_children(root, XML_ELEMENT_NODE);
- if (check_element_yp2(node, "start"))
+ if (yp2::xml::check_element_yp2(node, "start"))
{
const struct _xmlAttr *attr;
std::string id_value;
throw yp2::XMLError("Only attribute start allowed"
" in element 'start'. Got " + name);
}
- node = jump_to_next(node, XML_ELEMENT_NODE);
+ node = yp2::xml::jump_to_next(node, XML_ELEMENT_NODE);
}
- // process <filters> node which is expected second element node
- check_element_yp2(node, "filters");
-
- parse_xml_filters(doc, jump_to_children(node, XML_ELEMENT_NODE));
+ // process <filters> node if given
+ if (yp2::xml::is_element_yp2(node, "filters"))
+ {
+ parse_xml_filters(doc, yp2::xml::jump_to_children(node,
+ XML_ELEMENT_NODE));
+ node = yp2::xml::jump_to_next(node, XML_ELEMENT_NODE);
+ }
// process <routes> node which is expected third element node
- node = jump_to_next(node, XML_ELEMENT_NODE);
- check_element_yp2(node, "routes");
+ yp2::xml::check_element_yp2(node, "routes");
- parse_xml_routes(doc, jump_to_children(node, XML_ELEMENT_NODE));
+ parse_xml_routes(doc, yp2::xml::jump_to_children(node, XML_ELEMENT_NODE));
- node = jump_to_next(node, XML_ELEMENT_NODE);
+ node = yp2::xml::jump_to_next(node, XML_ELEMENT_NODE);
if (node)
{
throw yp2::XMLError("Unexpected element "