14#include "arcane/utils/ScopedPtr.h"
15#include "arcane/utils/TraceAccessor.h"
16#include "arcane/utils/NotImplementedException.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/Array.h"
20#include "arcane/core/XmlNode.h"
21#include "arcane/core/IXmlDocumentHolder.h"
22#include "arcane/core/ICaseDocument.h"
23#include "arcane/core/CaseNodeNames.h"
24#include "arcane/core/CaseOptionError.h"
25#include "arcane/core/DomUtils.h"
36class CaseDocumentFragment
44 ~CaseDocumentFragment()
46 delete m_case_node_names;
66 bool hasError()
const override;
67 bool hasWarnings()
const override;
78 CaseNodeNames* m_case_node_names =
nullptr;
79 ScopedPtrT<IXmlDocumentHolder> m_doc_holder;
80 XmlNode m_document_node;
83 String m_default_category;
84 UniqueArray<CaseOptionError> m_errors;
85 UniqueArray<CaseOptionError> m_warnings;
89 void _assignLanguage(
const String& langname);
90 void _printErrorsOrWarnings(std::ostream& o, ConstArrayView<CaseOptionError> errors);
106 ~CaseDocument()
override;
108 void build()
override;
122 bool hasError()
const override {
return m_fragment.hasError(); }
123 bool hasWarnings()
const override {
return m_fragment.hasWarnings(); }
124 void printErrors(std::ostream& o)
override { m_fragment.printErrors(o); }
125 void printWarnings(std::ostream& o)
override { m_fragment.printWarnings(o); }
167 if (!m_fragment.m_language.
null())
174 CaseDocumentFragment m_fragment;
176 XmlNode m_arcane_elem;
177 XmlNode m_configuration_elem;
178 XmlNode m_timeloop_elem;
179 XmlNode m_title_elem;
180 XmlNode m_description_elem;
181 XmlNode m_modules_elem;
182 XmlNode m_services_elem;
183 XmlNodeList m_mesh_elems;
184 XmlNode m_functions_elem;
185 XmlNode m_meshes_elem;
189 String m_code_version;
190 String m_code_unit_system;
194 XmlNode _forceCreateChild(XmlNode& parent,
const String& us);
228 doc->setLanguage(lang);
236CaseDocumentFragment::
240, m_doc_holder(document)
241, m_document_node(m_doc_holder->documentNode())
251, m_fragment(tm, document)
266void CaseDocumentFragment::
271 m_root_elem = m_document_node.documentElement();
272 if (m_root_elem.null()) {
274 if (m_language.null())
275 m_language = String(
"fr");
276 _assignLanguage(m_language);
278 m_root_elem = m_document_node.createAndAppendElement(cnn->root, String());
279 m_root_elem.setAttrValue(cnn->lang_attribute, m_language);
282 m_language = m_root_elem.attrValue(cnn->lang_attribute);
284 if (m_language.null()) {
285 ARCANE_FATAL(
"Attribute '{0}' not specified in the element <{1}>",
286 cnn->lang_attribute, m_root_elem.name());
289 _assignLanguage(m_language);
301 m_arcane_elem = _forceCreateChild(m_fragment.m_root_elem,
"arcane");
302 m_configuration_elem = _forceCreateChild(m_arcane_elem,
"configuration");
309 m_timeloop_elem = _forceCreateChild(m_arcane_elem, cnn->timeloop);
310 m_title_elem = _forceCreateChild(m_arcane_elem, cnn->title);
311 m_description_elem = _forceCreateChild(m_arcane_elem, cnn->description);
312 m_modules_elem = _forceCreateChild(m_arcane_elem, cnn->modules);
313 m_services_elem = _forceCreateChild(m_arcane_elem, cnn->services);
315 XmlNode& root_elem = m_fragment.m_root_elem;
317 _forceCreateChild(root_elem, cnn->mesh);
318 m_mesh_elems = root_elem.
children(cnn->mesh);
320 m_functions_elem = _forceCreateChild(root_elem, cnn->functions);
321 m_meshes_elem = root_elem.
child(cnn->meshes);
323 m_user_class = root_elem.
attrValue(cnn->user_class);
324 m_code_name = root_elem.
attrValue(cnn->code_name);
325 m_code_version = root_elem.
attrValue(cnn->code_version);
326 m_code_unit_system = root_elem.
attrValue(cnn->code_unit);
341void CaseDocumentFragment::
342_assignLanguage(
const String& langname)
344 delete m_case_node_names;
351XmlNode CaseDocument::
352_forceCreateChild(XmlNode& parent,
const String& name)
354 XmlNode node(parent.child(name));
356 node = parent.createAndAppendElement(name, String());
366 m_user_class = value;
367 m_fragment.m_root_elem.setAttrValue(
caseNodeNames()->user_class, value);
377 m_fragment.m_root_elem.setAttrValue(
caseNodeNames()->code_name, value);
386 m_code_version = value;
387 m_fragment.m_root_elem.setAttrValue(
caseNodeNames()->code_version, value);
396 m_code_unit_system = value;
397 m_fragment.m_root_elem.setAttrValue(
caseNodeNames()->code_unit, value);
409 m_errors.add(case_error);
418 m_warnings.add(case_error);
424bool CaseDocumentFragment::
427 return m_errors.size() != 0;
433bool CaseDocumentFragment::
436 return m_warnings.size() != 0;
445 _printErrorsOrWarnings(o, m_errors);
454 _printErrorsOrWarnings(o, m_warnings);
470void CaseDocumentFragment::
475 o <<
"TraceFile: " <<
error.trace().file() <<
":" <<
error.trace().line() <<
'\n';
476 o <<
"TraceFunc: " <<
error.trace().name() <<
'\n';
478 o <<
'<' <<
error.nodeName() <<
"> : " <<
error.message() <<
'\n';
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
void printWarnings(std::ostream &o) override
Writes the warnings to the stream o.
CaseNodeNames * caseNodeNames() override
Returns the instance containing the names of XML nodes by language.
String language() const override
Language used in the dataset.
void printErrors(std::ostream &o) override
Writes the errors to the stream o.
String defaultCategory() const override
Category used for default values.
IXmlDocumentHolder * documentHolder() override
Returns the XML document of the dataset. This pointer remains the property of this class and is destr...
void addError(const CaseOptionError &case_error) override
Adds an error to the dataset.
void clearErrorsAndWarnings() override
Clears the recorded error and warning messages.
XmlNode documentNode() override
Returns the document node.
void addWarning(const CaseOptionError &case_error) override
Adds a warning to the dataset.
XmlNode rootElement() override
Returns the root element.
Class managing an XML document of the dataset.
XmlNode rootElement() override
Returns the root element.
XmlNode meshesElement() override
Element containing the list of meshes (new mechanism) (can be null).
String codeUnitSystem() const override
Name of the document's unit system.
XmlNode arcaneElement() override
Returns the information element for Arcane.
String codeName() const override
Name of the case code.
ICaseDocument * clone() override
Clones the document.
void setDefaultCategory(const String &v) override
Sets the category used for default values.
const XmlNodeList & meshElements() override
Returns the root element of the mesh information.
XmlNode descriptionElement() override
Returns the element containing the case description.
void addWarning(const CaseOptionError &case_error) override
Adds a warning to the dataset.
void setUserClass(const String &value) override
Sets the name of the case usage class.
XmlNode functionsElement() override
Returns the root element of the functions.
String userClass() const override
Name of the case usage class.
XmlNode documentNode() override
Returns the document node.
XmlNode modulesElement() override
Returns the element containing the module descriptions.
CaseNodeNames * caseNodeNames() override
Returns the instance containing the names of XML nodes by language.
void setCodeVersion(const String &value) override
Sets the version number of the code.
void setCodeUnitSystem(const String &value) override
Sets the name of the document's unit system.
XmlNode timeloopElement() override
Returns the element containing the time loop choice.
String defaultCategory() const override
Category used for default values.
XmlNode configurationElement() override
Returns the configuration information element.
XmlNode titleElement() override
Returns the element containing the case title.
void printWarnings(std::ostream &o) override
Writes the warnings to the stream o.
IXmlDocumentHolder * documentHolder() override
Returns the XML document of the dataset. This pointer remains the property of this class and is destr...
void addError(const CaseOptionError &case_error) override
Adds an error to the dataset.
ICaseDocumentFragment * fragment() override
Fragment corresponding to this document.
void build() override
Constructs the instance.
void setCodeName(const String &value) override
Sets the name of the case code.
XmlNode servicesElement() override
Returns the element containing the service descriptions.
String codeVersion() const override
Version number of the code corresponding to the case.
void printErrors(std::ostream &o) override
Writes the errors to the stream o.
String language() const override
Language used in the dataset.
void clearErrorsAndWarnings() override
Clears the recorded error and warning messages.
XML node names of an Arcane dataset.
Constant view of an array of type T.
Interface of a part of a dataset.
Interface of a class managing an XML document of the dataset.
Manager of a DOM document.
Exception when a function is not implemented.
Unicode character string.
bool null() const
Returns true if the string is null.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
TraceMessage error() const
Flow for an error message.
List of nodes of a DOM tree.
String attrValue(const String &name, bool throw_exception=false) const
Value of attribute name.
XmlNode child(const String &name) const
Child node of this node with name name.
XmlNodeList children(const String &name) const
Set of child nodes of this node having the name name.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
bool arcaneIsCheck()
True if running in check mode.