PLCnext API Documentation  22.9.0.33
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;
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));
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
66  void WriteDocumentContext(XmlWriter& writer)const;
71  void InvalidXmlElementOccurs(XmlReader& reader, const char* xmlElementName);
74  void MissingXmlElementOccurs(XmlReader& reader, const char* xmlElementName);
78  String ResolvePath(const char* documentPath);
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
This class represents the version of a special SDK or Arp build.
Definition: BasicVersion.hpp:35
Definition: PlaceholderExpression.hpp:17
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:26
Class handle xml configuration documents
Definition: XmlConfigDocument.hpp:21
Class to read an XML File. Non buffered reader, can only read forward
Definition: XmlReader.hpp:25
XML context used during XML reading and writing to hold the context information
Definition: XmlSerializationContext.hpp:26
String & operator[](const String &attributeName)
operator [] to get and set attributes referenced by attributeName
Definition: XmlSerializationContext.hpp:115
XmlSerializationContext(XmlConfigDocument &document, Version docSchemaVersion=Version(1, 0))
Constructs an XmlContext instance.
void MissingXmlElementOccurs(XmlReader &reader, const char *xmlElementName)
summary>Reads the include xml tags inside a configuration file to include further xml files
String ResolveRelativePath(const String &path)
summary>resolves a string with a placeholder (Enviroment variables)
~XmlSerializationContext(void)=default
Destructs this instance and frees all resouces.
void WriteDocumentContext(XmlWriter &writer) const
String ResolvePlaceholder(const char *input)
summary>Adds a xml file to the list of included files
Definition: XmlSerializationContext.hpp:131
XmlSerializationContext(XmlSerializationContext &arg)=default
Copy contructor.
String ResolvePath(const char *documentPath)
summary>resolves a relative path into an absolute relative to the document path
void ReadDocumentContext(XmlReader &reader)
reads the document context i.e. schema version from the XMlReader
void InvalidXmlElementOccurs(XmlReader &reader, const char *xmlElementName)
Version GetDocumentSchemaVersion(void) const
returns the document schema version stored in this context
Definition: XmlSerializationContext.hpp:105
void ReadIncludesElement(XmlReader &reader)
summary>resolves a relative path into an absolute relative to the document path and replaces all plac...
XmlSerializationContext & operator=(XmlSerializationContext &arg)=default
Assignment operator.
Class to write an XML File
Definition: XmlWriter.hpp:21
Arp::BasicVersion Version
The Arp Version class.
Definition: TypeSystem.h:29
@ System
System components used by the System, Device, Plc or Io domains.
Namespace for configuration related classes
Definition: CommandLineOptions.hpp:13
Root namespace for the PLCnext API