Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
DataExchange/XML/Schema.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_DataExchange_XML_Schema_h_
5#define _Stroika_Foundation_DataExchange_XML_Schema_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include "Stroika/Foundation/Containers/Sequence.h"
10#include "Stroika/Foundation/DataExchange/BadFormatException.h"
12#include "Stroika/Foundation/DataExchange/XML/Namespace.h"
13#include "Stroika/Foundation/DataExchange/XML/Resource.h"
14#include "Stroika/Foundation/Execution/Exceptions.h"
17
18/**
19 * \file
20 */
21
22namespace Stroika::Foundation::DataExchange::XML {
23 using Containers::Sequence;
24 using IO::Network::URI;
25 using Memory::BLOB;
26}
27namespace Stroika::Foundation::DataExchange::XML::DOM::Document {
28 class Ptr;
29}
30namespace Stroika::Foundation::DataExchange::XML::Providers {
31 struct IDOMProvider;
32 struct ISchemaProvider;
33};
34
35namespace Stroika::Foundation::DataExchange::XML::Schema {
36
37 /**
38 * There is more internally to a SchemaRep (perhaps should add method to extract it as a DOM)?
39 *
40 * But mostly, used for internal private data, and that is captured with dynamic_cast, but privately internally
41 */
42 struct IRep {
43 virtual const Providers::ISchemaProvider* GetProvider () const = 0;
44 virtual optional<URI> GetTargetNamespace () const = 0;
45 // not super useful, except if you want to clone
46 virtual Memory::BLOB GetData () = 0;
47 // not super useful, except if you want to clone
48 virtual Resource::ResolverPtr GetResolver () = 0;
49 };
50
51 /**
52 * This is the main way you work with Schema objects - through a smart pointer.
53 */
54 class Ptr {
55 public:
56 /**
57 */
58 Ptr (nullptr_t);
59 Ptr (shared_ptr<IRep> s);
60 Ptr (const Ptr&) = default;
61
62 public:
63 bool operator== (const Ptr& p) const = default;
64
65 public:
66 /**
67 * A schema may target either no namespace (to validate a document with no namespace), or a specific namespace.
68 */
69 nonvirtual optional<URI> GetTargetNamespace () const;
70
71 public:
72 /**
73 */
74 nonvirtual shared_ptr<IRep> GetRep () const;
75
76 public:
77 /**
78 * The schema can be best thought of as a set of rules (for validating) described by a text file (the .xsd file).
79 * This method can return that as a BLOB (for now default encoded), a String (for easy viewing/display), or as a DOM object.
80 *
81 * This can be used to extract the schema as a DOM object (with no connection then to the original schema, its a copy). Or it can
82 * be used to extract the text for the Schema (or BLOB used to construct it), or a Schema using a different backend provider.
83 *
84 * None of the resulting objects retain any tie (except possibly reference to the same IProvider) from the original schema Ptr object.
85 */
86 template <typename AS_T>
87 nonvirtual AS_T As ()
88#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
89 requires (same_as<AS_T, String>
90#if qStroika_Foundation_DataExchange_XML_SupportDOM
91 or same_as<AS_T, XML::DOM::Document::Ptr>
92#endif
93 or same_as<AS_T, Memory::BLOB>)
94#endif
95 ;
96 template <typename AS_T>
97 nonvirtual AS_T As (const Providers::ISchemaProvider& p)
98 requires (same_as<AS_T, XML::Schema::Ptr>);
99 template <typename AS_T>
100 nonvirtual AS_T As (const Providers::IDOMProvider& p)
101#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
102 requires (same_as<AS_T, XML::DOM::Document::Ptr>)
103#endif
104 ;
105
106 private:
107 shared_ptr<IRep> fRep_;
108 };
109
110 /**
111 */
112 Ptr New (const Providers::ISchemaProvider& p, const Streams::InputStream::Ptr<byte>& schemaData, const Resource::ResolverPtr& resolver = nullptr);
113#if qStroika_Foundation_DataExchange_XML_SupportSchema
114 Ptr New (const Streams::InputStream::Ptr<byte>& schemaData, const Resource::ResolverPtr& resolver = nullptr);
115#endif
116
117#if qStroika_Foundation_DataExchange_XML_SupportSchema and qStroika_Foundation_DataExchange_XML_SupportParsing
118 /**
119 */
120 void ValidateFile (const filesystem::path& externalFileName, const Ptr& schema); // throws BadFormatException exception on error
121#endif
122
123};
124
125/*
126 ********************************************************************************
127 ***************************** Implementation Details ***************************
128 ********************************************************************************
129 */
130
131#include "Schema.inl"
132
133#endif /*_Stroika_Foundation_DataExchange_XML_Schema_h_*/
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...