PLCnext API Documentation 23.6.0.37
XmlSerializationContext.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Commons/Logging.h"
9#include "Arp/System/Commons/Exceptions/KeyNotFoundException.hpp"
10#include "Arp/System/Commons/Configuration/PlaceholderExpression.hpp"
11
12namespace Arp { namespace System { namespace Commons { namespace Xml
13{
14
16
17// forwards
18class XmlReader;
19class XmlWriter;
22
23// Never, ever use Loggable class here, because XmlSerializationContext is used before logging is initialized
25class XmlSerializationContext // : private Loggable<XmlSerializationContext>
26{
27 friend class MultiXmlConfigDocument;
28
29private: // typedefs
30 typedef std::map<String, String> Attributes;
31
32public: // construction/destruction
34 XmlSerializationContext(XmlConfigDocument& document, Version docSchemaVersion = Version(1, 0));
40 ~XmlSerializationContext(void) = default;
41
42public: // operators
44 String& operator[](const String& attributeName);
46 const String& operator[](const String& attributeName)const;
47
48public: // static properties
49 static const char* IncludeXmlName;
50 static const char* IncludesXmlName;
51
52public: // setter/getter operations
58 XmlConfigDocument& GetDocument(void);
59
60public: // 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
87private: // static methods
88 static void ResolveWildcards(const String& path, MultiXmlConfigDocument& doc);
89
90private: // methods
91 void ResolveWildcards(const String& path);
92
93private: // fields
94 XmlConfigDocument& document;
95 Version documentSchemaVersion;
96 Attributes additionalAttributes;
97 PlaceholderExpression placeholderExpression;
98
99private: // static fields
100};
101
103// inline methods of class XmlContext
104
106{
107 return this->documentSchemaVersion;
108}
109
110inline XmlConfigDocument& XmlSerializationContext::GetDocument()
111{
112 return this->document;
113}
114
116{
117 return this->additionalAttributes[attributeName];
118}
119
120inline 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:36
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
XmlSerializationContext & operator=(XmlSerializationContext &arg)=default
Assignment operator.
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...
Class to write an XML File
Definition: XmlWriter.hpp:19
Arp::BasicVersion Version
The Arp Version class.
Definition: TypeSystem.h:30
@ System
System components used by the System, Device, Plc or Io domains.
Namespace for configuration related classes
Definition: CommandLineOptions.hpp:14
Root namespace for the PLCnext API