44 _default_constraint(
"" )
71 map<string, string> props ;
77 string err =
"The specified command " + action
78 +
" is not a set context command" ;
84 def_name = props[
"name"] ;
85 if( def_name.empty() )
87 string err = action +
" command: definition name missing" ;
92 _str_cmd = (string)
"define " + def_name ;
94 int num_containers = 0 ;
102 if( child_name ==
"constraint" )
105 _default_constraint = child_value ;
107 else if( child_name ==
"container" )
109 handle_container_element( action, child_node, child_value, props ) ;
112 else if( child_name ==
"aggregate" )
114 handle_aggregate_element( action, child_node, child_value, props ) ;
120 child_value.clear() ;
122 child_value, props ) ;
125 if( num_containers < 1 )
127 string err = action +
"The define element must contain at least "
128 +
"one container element" ;
134 vector<string>::iterator i = _containers.begin() ;
135 vector<string>::iterator e = _containers.end() ;
142 if( _constraints.size() )
146 map<string,string>::iterator ci = _constraints.begin() ;
147 map<string,string>::iterator ce = _constraints.end() ;
148 for( ; ci != ce; ci++ )
151 _str_cmd += (*ci).first +
".constraint=\"" + (*ci).second +
"\"" ;
153 string attrs = _attributes[(*ci).first] ;
156 _str_cmd +=
"," + (*ci).first +
".attributes=\"" + attrs +
"\"";
182 BESXMLDefineCommand::handle_container_element(
const string &action,
185 map<string,string> &props )
187 string name = props[
"name"] ;
190 string err = action +
" command: container element missing name prop" ;
194 _containers.push_back( name ) ;
196 bool have_constraint = false ;
197 bool have_attributes = false ;
202 map<string,string> child_props ;
203 xmlNode *child_node =
207 if( child_name ==
"constraint" )
209 if( child_props.size() )
211 string err = action +
" command: constraint element "
212 +
"should not contain properties" ;
215 if( child_value.empty() )
217 string err = action +
" command: attributes element "
221 if( have_constraint )
223 string err = action +
" command: container element "
224 +
"contains multiple constraint elements" ;
227 have_constraint = true ;
228 _constraints[name] = child_value ;
230 else if( child_name ==
"attributes" )
232 if( child_props.size() )
234 string err = action +
" command: attributes element "
235 +
"should not contain properties" ;
238 if( child_value.empty() )
240 string err = action +
" command: attributes element "
244 if( have_attributes )
246 string err = action +
" command: container element "
247 +
"contains multiple attributes elements" ;
250 have_attributes = true ;
251 _attributes[name] = child_value ;
257 child_value.clear() ;
259 child_value, props ) ;
275 BESXMLDefineCommand::handle_aggregate_element(
const string &action,
278 map<string,string> &props )
280 string handler = props[
"handler"] ;
281 string cmd = props[
"cmd"] ;
282 if( handler.empty() )
284 string err = action +
" command: must specify aggregation handler" ;
289 string err = action +
" command: must specify aggregation cmd" ;
295 _str_cmd +=
" aggregate using " + handler +
" by " + cmd ;
303 vector<string>::iterator i = _containers.begin() ;
304 vector<string>::iterator e = _containers.end() ;
310 string constraint = _constraints[(*i)] ;
311 if( constraint.empty() ) constraint = _default_constraint ;
315 BESDEBUG(
"xml",
"define using container: " << endl << *d << endl ) ;
329 << (
void *)
this <<
")" << endl ;