PLCnext API Documentation  20.6.0.30321
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 
22 // Never, ever use Loggable class here, because XmlSerializationContext is used before logging is initialized
24 class XmlSerializationContext // : private Loggable<XmlSerializationContext>
25 {
26 private: // typedefs
27  typedef std::map<String, String> Attributes;
28 
29 public: // construction/destruction
31  XmlSerializationContext(XmlConfigDocument& document, Version docSchemaVersion = Version(1, 0));
35  XmlSerializationContext& operator=(XmlSerializationContext& arg) = default;
37  ~XmlSerializationContext(void) = default;
38 
39 public: // operators
41  String& operator[](const String& attributeName);
43  const String& operator[](const String& attributeName)const;
44 
45 public: // static properties
46  static const char* IncludeXmlName;
47  static const char* IncludesXmlName;
48 
49 public: // setter/getter operations
53  Version GetDocumentSchemaVersion(void) const;
55  XmlConfigDocument& GetDocument(void);
56 
57 public: // operations
60  void ReadDocumentContext(XmlReader& reader);
63  void WriteDocumentContext(XmlWriter& writer)const;
68  void InvalidXmlElementOccurs(XmlReader& reader, const char* xmlElementName);
71  void MissingXmlElementOccurs(XmlReader& reader, const char* xmlElementName);
73  void ReadIncludesElement(XmlReader& reader);
75  String ResolvePath(const char* documentPath);
77  String ResolvePlaceholder(const char* input);
79  //ist used by ReadIncludesElement
80  void AddIncludeFile(const String& path);
81 
82 private: // static methods
83 
84 private: // methods
85  String ResolveRelativePath(const String& path);
86  void ResolveWildcards(const String& path);
87  void AddMultiFile(const String& path);
88 
89 private: // fields
90  XmlConfigDocument& document;
91  Version documentSchemaVersion;
92  Attributes additionalAttributes;
93  PlaceholderExpression placeholderExpression;
94 
95 private: // static fields
96 };
97 
99 // inline methods of class XmlContext
100 
102 {
103  return this->documentSchemaVersion;
104 }
105 
106 inline XmlConfigDocument& XmlSerializationContext::GetDocument()
107 {
108  return this->document;
109 }
110 
111 inline String& XmlSerializationContext::operator[](const String& attributeName)
112 {
113  return this->additionalAttributes[attributeName];
114 }
115 
116 inline const String& XmlSerializationContext::operator[](const String& attributeName)const
117 {
118  auto i = this->additionalAttributes.find(attributeName);
119  if (i == this->additionalAttributes.end())
120  {
121  throw KeyNotFoundException::Create(attributeName);
122  }
123  // else
124  return i->second;
125 }
126 
128 {
129  return this->placeholderExpression.Resolve(input);
130 }
131 
132 
133 }}}} // 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
String ResolvePlaceholder(const char *input)
summary>Adds a xml file to the list of included files
Definition: XmlSerializationContext.hpp:127
Version GetDocumentSchemaVersion(void) const
returns the document schema version stored in this context
Definition: XmlSerializationContext.hpp:101
This class represents the version of a special SDK or Arp build.
Definition: BasicVersion.hpp:34
Class handle xml configuration documents
Definition: XmlConfigDocument.hpp:19
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:111
Definition: PlaceholderExpression.hpp:15
System components used by the System, Device, Plc or Io domains.
Namespace for configuration related classes
XML context used during XML reading and writing to hold the context information
Definition: XmlSerializationContext.hpp:24