123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896 |
- #pragma once
- #include <source_location>
- #include "AbstractElement.h"
- #include "Array.h"
- #include "JSON.h"
- #include "Trie.h"
- #include "XML.h"
- namespace Framework
- {
- namespace Validator
- {
- class ValidationResult : public Framework::ReferenceCounter
- {
- public:
- __declspec(dllexport) ValidationResult();
- __declspec(dllexport) virtual ~ValidationResult();
- virtual bool isValid() const = 0;
- __declspec(dllexport) void logInvalidInfo(
- std::source_location location
- = std::source_location::current()) const;
- virtual Text getInvalidInfo(int indent = 0) const = 0;
- virtual JSON::JSONValue* getValidPart(
- RCArray<ValidationResult>* zRemovedPartsValidationResults)
- = 0;
- virtual Text getPath() const = 0;
- virtual void addBasePath(Text basePath) = 0;
- virtual bool isDifferent(const ValidationResult* zResult) const = 0;
- };
- class TypeMissmatch : public ValidationResult
- {
- private:
- Text path;
- AbstractElement* foundValue;
- XML::Element* expected;
- ValidationResult* reason;
- public:
- __declspec(dllexport) TypeMissmatch(Text path,
- AbstractElement* zFoundValue,
- XML::Element* expected,
- ValidationResult* reason);
- __declspec(dllexport) ~TypeMissmatch();
- __declspec(dllexport) bool isValid() const override;
- __declspec(dllexport) Text
- getInvalidInfo(int indent) const override;
- protected:
- __declspec(dllexport) JSON::JSONValue* getValidPart(
- RCArray<ValidationResult>* zRemovedPartsValidationResults)
- override;
- __declspec(dllexport) Text getPath() const override;
- __declspec(dllexport) bool isDifferent(
- const ValidationResult* zResult) const override;
- __declspec(dllexport) void addBasePath(Text basePath) override;
- };
- class UnknownValue : public ValidationResult
- {
- private:
- Text path;
- AbstractElement* foundValue;
- public:
- __declspec(dllexport)
- UnknownValue(Text path, AbstractElement* zFoundValue);
- __declspec(dllexport) ~UnknownValue();
- __declspec(dllexport) bool isValid() const override;
- __declspec(dllexport) Text
- getInvalidInfo(int indent) const override;
- __declspec(dllexport) JSON::JSONValue* getValidPart(
- RCArray<ValidationResult>* zRemovedPartsValidationResults)
- override;
- __declspec(dllexport) Text getPath() const override;
- __declspec(dllexport) bool isDifferent(
- const ValidationResult* zResult) const override;
- __declspec(dllexport) void addBasePath(Text basePath) override;
- };
- class MissingValue : public ValidationResult
- {
- private:
- Text path;
- XML::Element* expected;
- public:
- __declspec(dllexport)
- MissingValue(Text path, XML::Element* expected);
- __declspec(dllexport) ~MissingValue();
- __declspec(dllexport) bool isValid() const override;
- __declspec(dllexport) Text
- getInvalidInfo(int indent) const override;
- __declspec(dllexport) JSON::JSONValue* getValidPart(
- RCArray<ValidationResult>* zRemovedPartsValidationResults)
- override;
- __declspec(dllexport) Text getPath() const override;
- __declspec(dllexport) bool isDifferent(
- const ValidationResult* zResult) const override;
- __declspec(dllexport) void addBasePath(Text basePath) override;
- };
- class MissingOneOf : public ValidationResult
- {
- private:
- Text path;
- RCArray<XML::Element> expected;
- public:
- __declspec(dllexport) MissingOneOf(Text path, XML::Editor expected);
- __declspec(dllexport) ~MissingOneOf();
- __declspec(dllexport) bool isValid() const override;
- __declspec(dllexport) Text
- getInvalidInfo(int indent) const override;
- __declspec(dllexport) JSON::JSONValue* getValidPart(
- RCArray<ValidationResult>* zRemovedPartsValidationResults)
- override;
- __declspec(dllexport) Text getPath() const override;
- __declspec(dllexport) bool isDifferent(
- const ValidationResult* zResult) const override;
- __declspec(dllexport) void addBasePath(Text basePath) override;
- };
- class NoTypeMatching : public ValidationResult
- {
- private:
- Text path;
- AbstractElement* foundValue;
- RCArray<XML::Element> expected;
- RCArray<ValidationResult> reasons;
- public:
- __declspec(dllexport) NoTypeMatching(Text path,
- AbstractElement* zFoundValue,
- RCArray<XML::Element>& expected,
- RCArray<ValidationResult>& reasons);
- __declspec(dllexport) ~NoTypeMatching();
- __declspec(dllexport) bool isValid() const override;
- __declspec(dllexport) Text
- getInvalidInfo(int indent) const override;
- __declspec(dllexport) JSON::JSONValue* getValidPart(
- RCArray<ValidationResult>* zRemovedPartsValidationResults)
- override;
- __declspec(dllexport) Text getPath() const override;
- __declspec(dllexport) bool isDifferent(
- const ValidationResult* zResult) const override;
- __declspec(dllexport) void addBasePath(Text basePath) override;
- };
- class ValidationPathNotFound : public ValidationResult
- {
- private:
- Text path;
- AbstractElement* foundValue;
- Text validationPath;
- public:
- __declspec(dllexport) ValidationPathNotFound(
- Text path, AbstractElement* zFoundValue, Text validationPath);
- __declspec(dllexport) ~ValidationPathNotFound();
- __declspec(dllexport) bool isValid() const override;
- __declspec(dllexport) Text
- getInvalidInfo(int indent) const override;
- __declspec(dllexport) JSON::JSONValue* getValidPart(
- RCArray<ValidationResult>* zRemovedPartsValidationResults)
- override;
- __declspec(dllexport) Text getPath() const override;
- __declspec(dllexport) bool isDifferent(
- const ValidationResult* zResult) const override;
- __declspec(dllexport) void addBasePath(Text basePath) override;
- };
- class ValidValue : public ValidationResult
- {
- private:
- Text path;
- AbstractElement* value;
- public:
- __declspec(dllexport)
- ValidValue(Text path, AbstractElement* zValue);
- __declspec(dllexport) ~ValidValue();
- __declspec(dllexport) bool isValid() const override;
- __declspec(dllexport) Text
- getInvalidInfo(int indent) const override;
- __declspec(dllexport) JSON::JSONValue* getValidPart(
- RCArray<ValidationResult>* zRemovedPartsValidationResults)
- override;
- __declspec(dllexport) Text getPath() const override;
- __declspec(dllexport) bool isDifferent(
- const ValidationResult* zResult) const override;
- __declspec(dllexport) void addBasePath(Text basePath) override;
- };
- template<typename T> class StringValidationBuilder;
- template<typename T> class NumberValidationBuilder;
- template<typename T> class BoolValidationBuilder;
- template<typename T> class ObjectValidationBuilder;
- template<typename T> class ArrayValidationBuilder;
- template<typename T> class OneOfValidationBuilder;
- class DataValidator : public Framework::ReferenceCounter
- {
- private:
- XML::Element* constraints;
- RCTrie<XML::Element>* typeConstraints;
- public:
- __declspec(dllexport) DataValidator(XML::Element* constraints);
- __declspec(dllexport) DataValidator(XML::Element* constraints,
- RCTrie<XML::Element>* typeConstraints);
- __declspec(dllexport) ~DataValidator();
- __declspec(dllexport) ValidationResult* validate(
- AbstractElement* zValue) const;
- __declspec(dllexport) ValidationResult* validate(
- ElementPath* path, AbstractElement* zValue) const;
- __declspec(dllexport) bool isValid(AbstractElement* zValue) const;
- /**
- * returns the valid part of the json by performing the
- * following operations in the specified order untill no further
- * changes are made:
- * - invalid or unknown object properties are removed
- * - missing object properties with default values are added if
- * missing
- * - invalid array elements are removed
- *
- * @param zValue the json value to to extract the valid part
- * without increased reference counter
- * @return the valid part or 0 if no valid part exists
- */
- __declspec(dllexport) JSON::JSONValue* getValidParts(
- JSON::JSONValue* zValue,
- RCArray<ValidationResult>* zRemovedPartsValidationResults)
- const;
- __declspec(dllexport) XML::Element* zConstraints();
- private:
- __declspec(dllexport) ValidationResult* validate(
- ElementPath* pathToValidate,
- AbstractElement* zValue,
- XML::Element* zConstraints,
- Text path) const;
- __declspec(dllexport) ValidationResult* validateMultipleTypes(
- ElementPath* pathToValidate,
- AbstractElement* zChildValue,
- XML::Element* zPossibleChildConstraints,
- Text childPath) const;
- public:
- __declspec(dllexport) static StringValidationBuilder<
- DataValidator>* buildForString();
- __declspec(dllexport) static NumberValidationBuilder<
- DataValidator>* buildForNumber();
- __declspec(dllexport) static BoolValidationBuilder<
- DataValidator>* buildForBool();
- __declspec(dllexport) static ObjectValidationBuilder<
- DataValidator>* buildForObject();
- __declspec(dllexport) static ArrayValidationBuilder<
- DataValidator>* buildForArray();
- __declspec(dllexport) static OneOfValidationBuilder<
- DataValidator>* buildForOneOf();
- __declspec(dllexport) static DataValidator* buildForObjectReference(
- Text objectId);
- };
- template<typename T> class StringValidationBuilder
- {
- private:
- XML::Element element;
- std::function<T*(XML::Element& element)> builder;
- public:
- StringValidationBuilder(
- std::function<T*(XML::Element& element)> builder)
- : element("<string/>"),
- builder(builder)
- {}
- StringValidationBuilder<T>* withExactMatch(Text value)
- {
- element.setAttribute("equals", value);
- return this;
- }
- StringValidationBuilder<T>* whichContainsMatch(Text value)
- {
- element.setAttribute("contains", value);
- return this;
- }
- StringValidationBuilder<T>* whichStartsWithMatch(Text value)
- {
- element.setAttribute("startsWith", value);
- return this;
- }
- StringValidationBuilder<T>* whichEndsWithMatch(Text value)
- {
- element.setAttribute("endsWith", value);
- return this;
- }
- StringValidationBuilder<T>* whichIsOneOf(RCArray<Text> values)
- {
- JSON::JSONArray arr;
- for (Text* str : values)
- arr.addValue(new JSON::JSONString(str->getText()));
- element.setAttribute("oneOf", arr.toString());
- return this;
- }
- StringValidationBuilder<T>* whichIsOneOf(
- std::initializer_list<Text> values)
- {
- JSON::JSONArray arr;
- for (Text str : values)
- arr.addValue(new JSON::JSONString(str));
- element.setAttribute("oneOf", arr.toString());
- return this;
- }
- StringValidationBuilder<T>* whichIs(Text value)
- {
- JSON::JSONArray arr;
- arr.addValue(new JSON::JSONString(value));
- element.setAttribute("oneOf", arr.toString());
- return this;
- }
- StringValidationBuilder<T>* withDefault(Text value)
- {
- element.setAttribute(
- "default", JSON::JSONString(value).toString());
- return this;
- }
- StringValidationBuilder<T>* withDefaultNull()
- {
- element.setAttribute("default", "null");
- return this;
- }
- StringValidationBuilder<T>* whichCanBeNull()
- {
- element.setAttribute("nullable", "true");
- return this;
- }
- StringValidationBuilder<T>* whichIsOptional()
- {
- element.setAttribute("optional", "true");
- return this;
- }
- T* finishString()
- {
- T* result = builder(element);
- delete this;
- return result;
- }
- };
- template<typename T> class NumberValidationBuilder
- {
- private:
- XML::Element element;
- std::function<T*(XML::Element& element)> builder;
- public:
- NumberValidationBuilder(
- std::function<T*(XML::Element& element)> builder)
- : element("<number/>"),
- builder(builder)
- {}
- NumberValidationBuilder<T>* whichIs(double value)
- {
- element.setAttribute("equals", Text(value));
- return this;
- }
- NumberValidationBuilder<T>* whichIsLessOrEqual(double value)
- {
- element.setAttribute("lessOrEqual", Text(value));
- return this;
- }
- NumberValidationBuilder<T>* whichIsGreaterOrEqual(double value)
- {
- element.setAttribute("greaterOrEqual", Text(value));
- return this;
- }
- NumberValidationBuilder<T>* whichIsLessThen(double value)
- {
- element.setAttribute("less", Text(value));
- return this;
- }
- NumberValidationBuilder<T>* whichIsGreaterThen(double value)
- {
- element.setAttribute("greater", Text(value));
- return this;
- }
- NumberValidationBuilder<T>* withDefault(double value)
- {
- element.setAttribute(
- "default", JSON::JSONNumber(value).toString());
- return this;
- }
- NumberValidationBuilder<T>* withDefaultNull()
- {
- element.setAttribute("default", "null");
- return this;
- }
- NumberValidationBuilder<T>* whichCanBeNull()
- {
- element.setAttribute("nullable", "true");
- return this;
- }
- NumberValidationBuilder<T>* whichIsOptional()
- {
- element.setAttribute("optional", "true");
- return this;
- }
- T* finishNumber()
- {
- T* result = builder(element);
- delete this;
- return result;
- }
- };
- template<typename T> class BoolValidationBuilder
- {
- private:
- XML::Element element;
- std::function<T*(XML::Element& element)> builder;
- public:
- BoolValidationBuilder(
- std::function<T*(XML::Element& element)> builder)
- : element("<bool/>"),
- builder(builder)
- {}
- BoolValidationBuilder<T>* whichIs(bool value)
- {
- element.setAttribute("equals", value ? "true" : "false");
- return this;
- }
- BoolValidationBuilder<T>* withDefault(bool value)
- {
- element.setAttribute(
- "default", JSON::JSONBool(value).toString());
- return this;
- }
- BoolValidationBuilder<T>* withDefaultNull()
- {
- element.setAttribute("default", "null");
- return this;
- }
- BoolValidationBuilder<T>* whichCanBeNull()
- {
- element.setAttribute("nullable", "true");
- return this;
- }
- BoolValidationBuilder<T>* whichIsOptional()
- {
- element.setAttribute("optional", "true");
- return this;
- }
- T* finishBool()
- {
- T* result = builder(element);
- delete this;
- return result;
- }
- };
- template<typename T> class ArrayValidationBuilder;
- template<typename T> class ObjectValidationBuilder
- {
- private:
- XML::Element element;
- std::function<T*(XML::Element& element)> builder;
- public:
- ObjectValidationBuilder(
- std::function<T*(XML::Element& element)> builder)
- : element("<object></object>"),
- builder(builder)
- {}
- ObjectValidationBuilder<T>* setObjectReferenceId(Text id)
- {
- element.setAttribute("id", id);
- return this;
- }
- NumberValidationBuilder<ObjectValidationBuilder<T>>*
- withRequiredNumber(Text name)
- {
- return new NumberValidationBuilder<ObjectValidationBuilder<T>>(
- [this, name](XML::Element& e) {
- if (!element.selectChildsByAttribute("name", name)
- .exists())
- {
- XML::Element* attr
- = new XML::Element("<value></value>");
- attr->setAttribute("name", name);
- element.addChild(attr);
- }
- element.selectChildsByAttribute("name", name)
- .addChild(e.dublicate());
- return this;
- });
- }
- StringValidationBuilder<ObjectValidationBuilder<T>>*
- withRequiredString(Text name)
- {
- return new StringValidationBuilder<ObjectValidationBuilder<T>>(
- [this, name](XML::Element& e) {
- if (!element.selectChildsByAttribute("name", name)
- .exists())
- {
- XML::Element* attr
- = new XML::Element("<value></value>");
- attr->setAttribute("name", name);
- element.addChild(attr);
- }
- element.selectChildsByAttribute("name", name)
- .addChild(e.dublicate());
- return this;
- });
- }
- BoolValidationBuilder<ObjectValidationBuilder<T>>* withRequiredBool(
- Text name)
- {
- return new BoolValidationBuilder<ObjectValidationBuilder<T>>(
- [this, name](XML::Element& e) {
- if (!element.selectChildsByAttribute("name", name)
- .exists())
- {
- XML::Element* attr
- = new XML::Element("<value></value>");
- attr->setAttribute("name", name);
- element.addChild(attr);
- }
- element.selectChildsByAttribute("name", name)
- .addChild(e.dublicate());
- return this;
- });
- }
- ArrayValidationBuilder<ObjectValidationBuilder<T>>*
- withRequiredArray(Text name)
- {
- return new ArrayValidationBuilder<ObjectValidationBuilder<T>>(
- [this, name](XML::Element& e) {
- if (!element.selectChildsByAttribute("name", name)
- .exists())
- {
- XML::Element* attr
- = new XML::Element("<value></value>");
- attr->setAttribute("name", name);
- element.addChild(attr);
- }
- element.selectChildsByAttribute("name", name)
- .addChild(e.dublicate());
- return this;
- });
- }
- ObjectValidationBuilder<ObjectValidationBuilder<T>>*
- withRequiredObject(Text name)
- {
- return new ObjectValidationBuilder<ObjectValidationBuilder<T>>(
- [this, name](XML::Element& e) {
- if (!element.selectChildsByAttribute("name", name)
- .exists())
- {
- XML::Element* attr
- = new XML::Element("<value></value>");
- attr->setAttribute("name", name);
- element.addChild(attr);
- }
- element.selectChildsByAttribute("name", name)
- .addChild(e.dublicate());
- return this;
- });
- }
- ObjectValidationBuilder<T>* withRequiredAttribute(
- Text name, DataValidator* validator)
- {
- if (!element.selectChildsByAttribute("name", name).exists())
- {
- XML::Element* attr = new XML::Element("<value></value>");
- attr->setAttribute("name", name);
- element.addChild(attr);
- }
- element.selectChildsByAttribute("name", name)
- .addChild(validator->zConstraints()->dublicate());
- validator->release();
- return this;
- }
- ObjectValidationBuilder<T>* withDefault(JSON::JSONObject* obj)
- {
- element.setAttribute("default", obj->toString());
- obj->release();
- return this;
- }
- ObjectValidationBuilder<T>* withDefaultNull()
- {
- element.setAttribute("default", "null");
- return this;
- }
- ObjectValidationBuilder<T>* whichCanBeNull()
- {
- element.setAttribute("nullable", "true");
- return this;
- }
- ObjectValidationBuilder<T>* whichIsOptional()
- {
- element.setAttribute("optional", "true");
- return this;
- }
- ArrayValidationBuilder<T>* typeOfValuesSpecifiedByAttribute(
- Text valueName, Text attributeName)
- {
- if (!element.selectChildsByAttribute("name", valueName)
- .exists())
- {
- XML::Element* attr = new XML::Element("<value></value>");
- attr->setAttribute("name", valueName);
- element.addChild(attr);
- }
- element.selectChildsByAttribute("name", valueName)
- .setAttribute("typeSpecifiedBy", attributeName);
- return this;
- }
- ObjectValidationBuilder<T>* removeInvalidEntries()
- {
- element.setAttribute("removeInvalidEntries", "true");
- return this;
- }
- ObjectValidationBuilder<T>* allowAdditionalAttriutes()
- {
- element.setAttribute("allowAdditionalAttributes", "true");
- return this;
- }
- T* finishObject()
- {
- T* result = builder(element);
- delete this;
- return result;
- }
- };
- template<typename T> class ArrayValidationBuilder
- {
- private:
- XML::Element element;
- std::function<T*(XML::Element& element)> builder;
- public:
- ArrayValidationBuilder(
- std::function<T*(XML::Element& element)> builder)
- : element("<array></array>"),
- builder(builder)
- {}
- StringValidationBuilder<ArrayValidationBuilder<T>>*
- addAcceptedStringInArray()
- {
- return new StringValidationBuilder<ArrayValidationBuilder<T>>(
- [this](XML::Element& e) {
- element.addChild(e.dublicate());
- return this;
- });
- }
- NumberValidationBuilder<ArrayValidationBuilder<T>>*
- addAcceptedNumberInArray()
- {
- return new NumberValidationBuilder<ArrayValidationBuilder<T>>(
- [this](XML::Element& e) {
- element.addChild(e.dublicate());
- return this;
- });
- }
- BoolValidationBuilder<ArrayValidationBuilder<T>>*
- addAcceptedBooleanInArray()
- {
- return new BoolValidationBuilder<ArrayValidationBuilder<T>>(
- [this](XML::Element& e) {
- element.addChild(e.dublicate());
- return this;
- });
- }
- ObjectValidationBuilder<ArrayValidationBuilder<T>>*
- addAcceptedObjectInArray()
- {
- return new ObjectValidationBuilder<ArrayValidationBuilder<T>>(
- [this](XML::Element& e) {
- element.addChild(e.dublicate());
- return this;
- });
- }
- ArrayValidationBuilder<ArrayValidationBuilder<T>>*
- addAcceptedArrayInArray()
- {
- return new ArrayValidationBuilder<ArrayValidationBuilder<T>>(
- [this](XML::Element& e) {
- element.addChild(e.dublicate());
- return this;
- });
- }
- ArrayValidationBuilder<T>* addAcceptedTypeInArray(
- DataValidator* validator)
- {
- element.addChild(validator->zConstraints()->dublicate());
- validator->release();
- return this;
- }
- ArrayValidationBuilder<T>* acceptNullsInArray()
- {
- element.setAttribute("nullsEnabled", "true");
- return this;
- }
- ArrayValidationBuilder<T>* withDefault(JSON::JSONArray* array)
- {
- element.setAttribute("default", array->toString());
- array->release();
- return this;
- }
- ArrayValidationBuilder<T>* withDefaultNull()
- {
- element.setAttribute("default", "null");
- return this;
- }
- ArrayValidationBuilder<T>* whichCanBeNull()
- {
- element.setAttribute("nullable", "true");
- return this;
- }
- ArrayValidationBuilder<T>* whichIsOptional()
- {
- element.setAttribute("optional", "true");
- return this;
- }
- ArrayValidationBuilder<T>* typeSpecifiedByAttribute(Text name)
- {
- element.setAttribute("typeSpecifiedBy", name);
- return this;
- }
- ArrayValidationBuilder<T>* removeInvalidEntries()
- {
- element.setAttribute("removeInvalidEntries", "true");
- return this;
- }
- T* finishArray()
- {
- T* result = builder(element);
- delete this;
- return result;
- }
- };
- template<typename T> class OneOfValidationBuilder
- {
- private:
- XML::Element element;
- std::function<T*(XML::Element& element)> builder;
- public:
- OneOfValidationBuilder(
- std::function<T*(XML::Element& element)> builder)
- : element("<oneOf></oneOf>"),
- builder(builder)
- {}
- StringValidationBuilder<OneOfValidationBuilder<T>>*
- addAcceptedStringInArray()
- {
- return new StringValidationBuilder<OneOfValidationBuilder<T>>(
- [this](XML::Element& e) {
- element.addChild(e.dublicate());
- return this;
- });
- }
- NumberValidationBuilder<OneOfValidationBuilder<T>>*
- addAcceptedNumberInArray()
- {
- return new NumberValidationBuilder<OneOfValidationBuilder<T>>(
- [this](XML::Element& e) {
- element.addChild(e.dublicate());
- return this;
- });
- }
- BoolValidationBuilder<OneOfValidationBuilder<T>>*
- addAcceptedBooleanInArray()
- {
- return new BoolValidationBuilder<OneOfValidationBuilder<T>>(
- [this](XML::Element& e) {
- element.addChild(e.dublicate());
- return this;
- });
- }
- ObjectValidationBuilder<OneOfValidationBuilder<T>>*
- addAcceptedObjectInArray()
- {
- return new ObjectValidationBuilder<OneOfValidationBuilder<T>>(
- [this](XML::Element& e) {
- element.addChild(e.dublicate());
- return this;
- });
- }
- ArrayValidationBuilder<OneOfValidationBuilder<T>>*
- addAcceptedArrayInArray()
- {
- return new ArrayValidationBuilder<OneOfValidationBuilder<T>>(
- [this](XML::Element& e) {
- element.addChild(e.dublicate());
- return this;
- });
- }
- OneOfValidationBuilder<T>* addAcceptedType(DataValidator* validator)
- {
- element.addChild(validator->zConstraints()->dublicate());
- validator->release();
- return this;
- }
- OneOfValidationBuilder<T>* typeSpecifiedByAttribute(Text name)
- {
- element.setAttribute("typeSpecifiedBy", name);
- return this;
- }
- T* finishOneOf()
- {
- T* result = builder(element);
- delete this;
- return result;
- }
- };
- } // namespace Validator
- } // namespace Framework
|