PLCnext API Documentation  21.0.0.35466
XmlSerializationContext.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Logging.h"
9 #include "Arp/System/Commons/Exceptions/KeyNotFoundException.hpp"
10 #include "Arp/System/Commons/Configuration/PlaceholderExpression.hpp"
11 
12 namespace Arp { namespace System { namespace Commons { namespace Xml
13 {
14 
16 
17 // forwards
18 class XmlReader;
19 class XmlWriter;
20 class XmlConfigDocument;
21 class MultiXmlConfigDocument;
22 
23 // Never, ever use Loggable class here, because XmlSerializationContext is used before logging is initialized
25 class XmlSerializationContext // : private Loggable<XmlSerializationContext>
26 {
27  friend class MultiXmlConfigDocument;
28 
29 private: // typedefs
30  typedef std::map<String, String> Attributes;
31 
32 public: // construction/destruction
34  XmlSerializationContext(XmlConfigDocument& document, Version docSchemaVersion = Version(1, 0));
38  XmlSerializationContext& operator=(XmlSerializationContext& arg) = default;
40  ~XmlSerializationContext(void) = default;
41 
42 public: // operators
44  String& operator[](const String& attributeName);
46  const String& operator[](const String& attributeName)const;
47 
48 public: // static properties
49  static const char* IncludeXmlName;
50  static const char* IncludesXmlName;
51 
52 public: // setter/getter operations
56  Version GetDocumentSchemaVersion(void) const;
58  XmlConfigDocument& GetDocument(void);
59 
60 public: // operations
63  void ReadDocumentContext(XmlReader& reader);
66  void WriteDocumentContext(XmlWriter& writer)const;
71  void InvalidXmlElementOccurs(XmlReader& reader, const char* xmlElementName);
74  void MissingXmlElementOccurs(XmlReader& reader, const char* xmlElementName);
76  void ReadIncludesElement(XmlReader& reader);
78  String ResolvePath(const char* documentPath);
80  String ResolveRelativePath(const String& path);
82  String ResolvePlaceholder(const char* input);
84  //ist used by ReadIncludesElement
85  void AddIncludeFile(const String& path);
86 
87 private: // static methods
88  static void ResolveWildcards(const String& path, MultiXmlConfigDocument& doc);
89 
90 private: // methods
91  void ResolveWildcards(const String& path);
92 
93 private: // fields
94  XmlConfigDocument& document;
95  Version documentSchemaVersion;
96  Attributes additionalAttributes;
97  PlaceholderExpression placeholderExpression;
98 
99 private: // static fields
100 };
101 
103 // inline methods of class XmlContext
104 
106 {
107  return this->documentSchemaVersion;
108 }
109 
110 inline XmlConfigDocument& XmlSerializationContext::GetDocument()
111 {
112  return this->document;
113 }
114 
115 inline String& XmlSerializationContext::operator[](const String& attributeName)
116 {
117  return this->additionalAttributes[attributeName];
118 }
119 
120 inline const String& XmlSerializationContext::operator[](const String& attributeName)const
121 {
122  auto i = this->additionalAttributes.find(attributeName);
123  if (i == this->additionalAttributes.end())
124  {
125  throw KeyNotFoundException::Create(attributeName);
126  }
127  // else
128  return i->second;
129 }
130 
132 {
133  return this->placeholderExpression.Resolve(input);
134 }
135 
136 
137 }}}} // end of namespace Arp::System::Commons::Xml
Class to write an XML File
Definition: XmlWriter.hpp:20
static KeyNotFoundException Create(const T &keyValue)
Creates an KeyNotFoundException instance using a default message text.
Definition: KeyNotFoundException.hpp:79
special version of XmlConfigDocument to include xml configuration data from other xml files inside a ...
Definition: MultiXmlConfigDocument.hpp:25
Arp::BasicVersion Version
The Arp Version class.
Definition: TypeSystem.h:29
String ResolvePlaceholder(const char *input)
summary>Adds a xml file to the list of included files
Definition: XmlSerializationContext.hpp:131
Version GetDocumentSchemaVersion(void) const
returns the document schema version stored in this context
Definition: XmlSerializationContext.hpp:105
This class represents the version of a special SDK or Arp build.
Definition: BasicVersion.hpp:34
Class handle xml configuration documents
Definition: XmlConfigDocument.hpp:20
Root namespace for the PLCnext API
Class to read an XML File. Non buffered reader, can only read forward
Definition: XmlReader.hpp:22
String & operator[](const String &attributeName)
operator [] to get and set attributes referenced by attributeName
Definition: XmlSerializationContext.hpp:115
Definition: PlaceholderExpression.hpp:16
System components used by the System, Device, Plc or Io domains.
Namespace for configuration related classes
Definition: CommandLineOptions.hpp:12
XML context used during XML reading and writing to hold the context information
Definition: XmlSerializationContext.hpp:25