7 #include "fwRuntime/helper.hpp" 9 #include "fwRuntime/Convert.hpp" 11 #include <fwCore/base.hpp> 21 ::fwRuntime::ConfigurationElement::sptr _element )
23 SLM_ASSERT(
"_validator not instanced", _validator);
24 SLM_ASSERT(
"_element not instanced", _element);
26 xmlNodePtr _elementNodePtr = xmlNewNode( NULL, xmlCharStrdup( _element->getName().c_str() ) );
27 ::fwRuntime::ConfigurationElement2XML( _element, _elementNodePtr );
28 xmlDocPtr xmlDoc = xmlNewDoc(BAD_CAST
"1.0");
29 xmlNodePtr xmlNode = xmlCopyNode(_elementNodePtr, 1);
30 xmlDocSetRootElement(xmlDoc, xmlNode);
32 _validator->clearErrorLog();
34 std::pair< bool, std::string > validationResult;
35 if( !(_validator->validate( xmlNode ) ==
true) )
37 validationResult.first =
false;
38 validationResult.second = _validator->getErrorLog();
42 validationResult.first =
true;
46 return validationResult;
54 std::map<std::string, std::string> attr = _cfgElement->getAttributes();
55 for ( std::map<std::string, std::string>::iterator iter_attr_cfe = attr.begin(); iter_attr_cfe != attr.end();
58 xmlSetProp(pNode, xmlCharStrdup((iter_attr_cfe->first).c_str()),
59 xmlCharStrdup((iter_attr_cfe->second).c_str()) );
62 for(::fwRuntime::ConfigurationElement::sptr elt : _cfgElement->getElements())
64 xmlNodePtr child = xmlNewNode( NULL, xmlCharStrdup( elt->getName().c_str() ) );
66 xmlAddChild(pNode, child);
69 if( !elt->getValue().empty() )
71 xmlNodeSetContent(child, xmlCharStrdup( elt->getValue().c_str() ));
83 ConfigurationElement::sptr
getCfgAsAnExtension( ConfigurationElement::sptr config, std::string extension_pt )
85 ConfigurationElement::sptr resultConfig;
86 if( config->hasAttribute(
"config") )
88 std::string cfgContribution = config->getExistingAttributeValue(
"config");
89 std::vector< ConfigurationElement::sptr > cfgs = ::fwRuntime::getAllCfgForPoint( extension_pt );
90 OSLM_FATAL_IF(
"No configuration contribution found for extension point " << extension_pt, cfgs.empty());
93 std::vector< ConfigurationElement::sptr > matchingCfg;
94 for(ConfigurationElement::sptr elt : cfgs)
96 if( cfgContribution == elt->getExistingAttributeValue(
"id") )
98 matchingCfg.push_back( elt );
103 OSLM_FATAL_IF(
"No contribution matching the requested requirement (" << cfgContribution
104 <<
" for extension point " << extension_pt <<
" )",
105 matchingCfg.empty());
108 resultConfig = *matchingCfg.begin();
111 OSLM_WARN_IF(
"Several contribution identified by " << cfgContribution <<
"( for cfg extension point " << extension_pt <<
" )" 112 <<
" has been found : the first one is returned",
113 (matchingCfg.size() > 1));
115 SLM_WARN_IF(
"Configuration has no config attribute", !config->hasAttribute(
"config"));
123 using ::fwRuntime::ConfigurationElement;
125 typedef std::vector< ConfigurationElement::sptr > ElementContainer;
126 typedef std::back_insert_iterator< ElementContainer > Inserter;
128 ElementContainer renderElements;
129 Inserter renderInserter(renderElements);
131 ::fwRuntime::getAllConfigurationElementsForPoint(_extension_pt, renderInserter);
132 return renderElements;
139 std::vector<std::string > ids;
141 using ::fwRuntime::ConfigurationElement;
142 typedef std::vector< ConfigurationElement::sptr > ElementContainer;
143 typedef std::back_insert_iterator< ElementContainer > Inserter;
146 ElementContainer elements;
147 Inserter inserter(elements);
148 ::fwRuntime::getAllConfigurationElementsForPoint( _extension_pt, inserter);
151 for(::fwRuntime::ConfigurationElement::sptr elt : elements)
153 ids.push_back(elt->getAttributeValue(
"id"));
162 std::string info =
"";
165 using ::fwRuntime::ConfigurationElement;
166 typedef std::vector< ConfigurationElement::sptr > ElementContainer;
167 typedef std::back_insert_iterator< ElementContainer > Inserter;
170 ElementContainer elements;
171 Inserter inserter(elements);
172 ::fwRuntime::getAllConfigurationElementsForPoint( _extension_pt, inserter);
175 for(::fwRuntime::ConfigurationElement::sptr elt : elements)
177 if( elt->getName() ==
"info" && elt->hasAttribute(
"text") )
179 info = elt->getAttributeValue(
"text");
189 std::map< std::string,
192 std::map<std::string, ConfigurationElement::sptr > cfgElementMap;
194 using ::fwRuntime::ConfigurationElement;
195 typedef std::vector< ConfigurationElement::sptr > ElementContainer;
196 typedef std::back_insert_iterator< ElementContainer > Inserter;
199 ElementContainer elements;
200 Inserter inserter(elements);
201 ::fwRuntime::getAllConfigurationElementsForPoint( _extension_pt, inserter);
204 for(::fwRuntime::ConfigurationElement::sptr elt : elements)
206 cfgElementMap[elt->getAttributeValue(
"id")] = elt;
208 return cfgElementMap;
215 typedef std::vector< std::shared_ptr< Extension > > ExtensionContainer;
216 typedef std::back_insert_iterator< ExtensionContainer > Inserter;
218 ExtensionContainer extElements;
219 Inserter extInserter(extElements);
221 ::fwRuntime::getAllExtensionsForPoint( extension_pt, extInserter );
FWRUNTIME_API ConfigurationElement::sptr getCfgAsAnExtension(ConfigurationElement::sptr _config, std::string _extension_pt)
Returns the configuration element embedding the configuration to be considered for initializing an ob...
FWRUNTIME_API std::vector< ConfigurationElement::sptr > getAllCfgForPoint(std::string _extension_pt)
Returns configuration elements extending the _extension_pt extension point.
FWRUNTIME_API std::string getInfoForPoint(std::string _extension_pt)
Get information for the point.
FWRUNTIME_API std::vector< std::shared_ptr< ::fwRuntime::Extension > > getAllExtensionsForPoint(std::string extension_pt)
Returns extensions extending the _extension_pt extension point.
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
FWRUNTIME_API std::shared_ptr< ExtensionPoint > findExtensionPoint(const std::string &identifier)
Retrieves the extension point having the specified identifier.
FWRUNTIME_API std::pair< bool, std::string > validateConfigurationElement(std::shared_ptr< ::fwRuntime::io::Validator > _validator,::fwRuntime::ConfigurationElement::sptr _element)
Check configuration element (its XML representation) with respect to the validator (referencing the x...
FWRUNTIME_API std::map< std::string, ConfigurationElement::sptr > getAllIdAndConfigurationElementsForPoint(std::string _extension_pt)
Returns contribution ids and configuration elements related to a given extension point.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWRUNTIME_API void ConfigurationElement2XML(::fwRuntime::ConfigurationElement::sptr _cfgElement, xmlNodePtr pNode)
Update pNode content according to _cfgElement.
#define OSLM_WARN_IF(message, cond)
#define OSLM_FATAL_IF(message, cond)
FWRUNTIME_API std::vector< std::string > getAllIdsForPoint(std::string _extension_pt)
Returns contribution ids to a given extension point.
#define SLM_WARN_IF(message, cond)