12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763 |
- #include "JSON.h"
- #include "Datei.h"
- using namespace Framework;
- using namespace JSON;
- #pragma region JSONValue
- JSONValue::JSONValue()
- : ReferenceCounter()
- {
- this->type = JSONType::NULL_;
- }
- JSONValue::~JSONValue() {}
- JSONValue::JSONValue(JSONType type)
- : ReferenceCounter()
- {
- this->type = type;
- }
- JSONType JSONValue::getType() const
- {
- return type;
- }
- Text JSONValue::toString() const
- {
- return Text("null");
- }
- JSONValue* JSONValue::clone() const
- {
- return new JSONValue();
- }
- JSONBool* JSONValue::asBool() const
- {
- return (JSONBool*)this;
- }
- JSONNumber* JSONValue::asNumber() const
- {
- return (JSONNumber*)this;
- }
- JSONString* JSONValue::asString() const
- {
- return (JSONString*)this;
- }
- JSONArray* JSONValue::asArray() const
- {
- return (JSONArray*)this;
- }
- JSONObject* JSONValue::asObject() const
- {
- return (JSONObject*)this;
- }
- #pragma endregion Content
- #pragma region JSONBool
- JSONBool::JSONBool(bool b)
- : JSONValue(JSONType::BOOLEAN)
- {
- this->b = b;
- }
- bool JSONBool::getBool() const
- {
- return b;
- }
- Text JSONBool::toString() const
- {
- if (b)
- return Text("true");
- else
- return Text("false");
- }
- JSONValue* JSONBool::clone() const
- {
- return new JSONBool(b);
- }
- #pragma endregion Content
- #pragma region JSONNumber
- JSONNumber::JSONNumber(double num)
- : JSONValue(JSONType::NUMBER)
- {
- number = num;
- }
- double JSONNumber::getNumber() const
- {
- return number;
- }
- Text JSONNumber::toString() const
- {
- return Text(number);
- }
- JSONValue* JSONNumber::clone() const
- {
- return new JSONNumber(number);
- }
- #pragma endregion Content
- #pragma region JSONString
- JSONString::JSONString(Text string)
- : JSONValue(JSONType::STRING)
- {
- this->string = string;
- this->string.ersetzen("\\\"", "\"");
- this->string.ersetzen("\\n", "\n");
- }
- Text JSONString::getString() const
- {
- return string;
- }
- Text JSONString::toString() const
- {
- Text esc = string;
- esc.ersetzen("\"", "\\\"");
- esc.ersetzen("\n", "\\n");
- return Text(Text("\"") += esc.getText()) += "\"";
- }
- JSONValue* JSONString::clone() const
- {
- Text esc = string;
- esc.ersetzen("\"", "\\\"");
- esc.ersetzen("\n", "\\n");
- return new JSONString(esc);
- }
- #pragma endregion Content
- #pragma region JSONArray
- JSONArray::JSONArray()
- : JSONValue(JSONType::ARRAY)
- {
- array = new RCArray<JSONValue>();
- }
- JSONArray::JSONArray(Text string)
- : JSONValue(JSONType::ARRAY)
- {
- array = new RCArray<JSONValue>();
- string = Parser::removeWhitespace(string);
- if (string.getText()[0] == '['
- && string.getText()[string.getLength() - 1] == ']')
- {
- string.remove(0, 1);
- string.remove(string.getLength() - 1, string.getLength());
- while (string.getLength())
- {
- int end = Parser::findObjectEndInArray(string);
- Text* objStr = string.getTeilText(0, end);
- string.remove(0, end + 1);
- array->add(Parser::getValue(*objStr));
- objStr->release();
- }
- }
- }
- JSONArray::JSONArray(const JSONArray& arr)
- : JSONValue(JSONType::ARRAY)
- {
- array = dynamic_cast<RCArray<JSONValue>*>(arr.array->getThis());
- }
- JSONArray::~JSONArray()
- {
- array->release();
- }
- JSONArray& JSONArray::operator=(const JSONArray& arr)
- {
- array->release();
- array = dynamic_cast<RCArray<JSONValue>*>(arr.array->getThis());
- return *this;
- }
- void JSONArray::addValue(JSONValue* value)
- {
- array->add(value);
- }
- void JSONArray::setValue(int i, JSONValue* value)
- {
- array->set(value, i);
- }
- void JSONArray::removeValue(int i)
- {
- array->remove(i);
- }
- JSONValue* JSONArray::getValue(int i) const
- {
- return array->get(i);
- }
- JSONValue* JSONArray::zValue(int i) const
- {
- return array->z(i);
- }
- int JSONArray::getLength() const
- {
- return array->getEintragAnzahl();
- }
- bool JSONArray::isValueOfType(int i, JSONType type) const
- {
- return i >= 0 && i < array->getEintragAnzahl()
- && array->z(i)->getType() == type;
- }
- Iterator<JSONValue*> JSONArray::begin() const
- {
- return array->begin();
- }
- Iterator<JSONValue*> JSONArray::end() const
- {
- return array->end();
- }
- Text JSONArray::toString() const
- {
- Text str = "[";
- for (auto i = array->begin(); i; i++)
- {
- str += i->toString();
- if (i.hasNext()) str += ",";
- }
- str += "]";
- return str;
- }
- JSONValue* JSONArray::clone() const
- {
- JSONArray* arr = new JSONArray();
- for (JSONValue* value : *this)
- {
- arr->addValue(value->clone());
- }
- return arr;
- }
- #pragma endregion Content
- #pragma region JSONObject
- JSONObject::JSONObject()
- : JSONValue(JSONType::OBJECT)
- {
- fields = new Array<Text>();
- values = new RCArray<JSONValue>();
- }
- JSONObject::JSONObject(Text string)
- : JSONValue(JSONType::OBJECT)
- {
- fields = new Array<Text>();
- values = new RCArray<JSONValue>();
- string = Parser::removeWhitespace(string);
- if (string.getText()[0] == '{'
- && string.getText()[string.getLength() - 1] == '}')
- {
- string.remove(0, 1);
- string.remove(string.getLength() - 1, string.getLength());
- while (string.getLength())
- {
- int endField = Parser::findFieldEndInObject(string);
- Text* fieldName = string.getTeilText(0, endField);
- string.remove(0, endField + 1);
- fieldName->remove(0, 1);
- fieldName->remove(
- fieldName->getLength() - 1, fieldName->getLength());
- int endValue = Parser::findValueEndInObject(string);
- Text* value = string.getTeilText(0, endValue);
- string.remove(0, endValue + 1);
- fields->add(Text(fieldName->getText()));
- values->add(Parser::getValue(*value));
- fieldName->release();
- value->release();
- }
- }
- }
- JSONObject::JSONObject(const JSONObject& obj)
- : JSONValue(JSONType::OBJECT)
- {
- fields = dynamic_cast<Array<Text>*>(obj.fields->getThis());
- values = dynamic_cast<RCArray<JSONValue>*>(obj.values->getThis());
- }
- JSONObject::~JSONObject()
- {
- fields->release();
- values->release();
- }
- JSONObject& JSONObject::operator=(const JSONObject& obj)
- {
- fields->release();
- values->release();
- fields = dynamic_cast<Array<Text>*>(obj.fields->getThis());
- values = dynamic_cast<RCArray<JSONValue>*>(obj.values->getThis());
- return *this;
- }
- bool JSONObject::addValue(Text field, JSONValue* value)
- {
- if (hasValue(field)) return 0;
- fields->add(field);
- values->add(value);
- return 1;
- }
- bool JSONObject::removeValue(Text field)
- {
- for (int i = 0; i < fields->getEintragAnzahl(); i++)
- {
- if (fields->get(i).istGleich(field))
- {
- fields->remove(i);
- values->remove(i);
- return 1;
- }
- }
- return 0;
- }
- bool JSONObject::hasValue(Text field)
- {
- for (int i = 0; i < fields->getEintragAnzahl(); i++)
- {
- if (fields->get(i).istGleich(field)) return 1;
- }
- return 0;
- }
- JSONValue* JSONObject::getValue(Text field)
- {
- for (int i = 0; i < fields->getEintragAnzahl(); i++)
- {
- if (fields->get(i).istGleich(field)) return values->get(i);
- }
- return 0;
- }
- JSONValue* JSONObject::zValue(Text field)
- {
- for (int i = 0; i < fields->getEintragAnzahl(); i++)
- {
- if (fields->get(i).istGleich(field)) return values->z(i);
- }
- return 0;
- }
- Iterator<Text> JSONObject::getFields()
- {
- return fields->begin();
- }
- Iterator<JSONValue*> JSONObject::getValues()
- {
- return values->begin();
- }
- int JSONObject::getFieldCount() const
- {
- return fields->getEintragAnzahl();
- }
- bool JSONObject::isValueOfType(Text field, JSONType type) const
- {
- for (int i = 0; i < fields->getEintragAnzahl(); i++)
- {
- if (fields->get(i).istGleich(field))
- return values->z(i)->getType() == type;
- }
- return 0;
- }
- Text JSONObject::toString() const
- {
- Text str = "{";
- Iterator<Text> k = fields->begin();
- for (auto v = values->begin(); k && v; k++, v++)
- {
- str += "\"";
- str += k._.getText();
- str += "\":";
- str += v->toString().getText();
- if (v.hasNext()) str += ",";
- }
- str += "}";
- return str;
- }
- JSONValue* JSONObject::clone() const
- {
- JSONObject* obj = new JSONObject();
- auto field = fields->begin();
- auto value = values->begin();
- for (; field && value; field++, value++)
- {
- obj->addValue(field.val(), value->clone());
- }
- return obj;
- }
- #pragma endregion Content
- JSONValue* JSON::loadJSONFromFile(Text path)
- {
- Datei d;
- d.setDatei(path);
- if (!d.open(Datei::Style::lesen))
- {
- return new JSONValue();
- }
- int size = (int)d.getSize();
- char* buffer = new char[size + 1];
- buffer[size] = 0;
- d.lese(buffer, size);
- d.close();
- JSONValue* result = Parser::getValue(buffer);
- delete[] buffer;
- return result;
- }
- #pragma region Parser
- int Parser::findObjectEndInArray(const char* str)
- {
- return findValueEndInObject(str);
- }
- Text Parser::removeWhitespace(const char* str)
- {
- int wsc = 0;
- int i = 0;
- bool esc = 0;
- bool strO = 0;
- for (; str[i]; i++)
- {
- switch (str[i])
- {
- case '\\':
- if (strO)
- esc = !esc;
- else
- esc = 0;
- break;
- case '"':
- if (!esc) strO = !strO;
- esc = 0;
- break;
- case ' ':
- case '\n':
- case '\t':
- case '\r':
- if (!strO) wsc++;
- esc = 0;
- break;
- default:
- esc = 0;
- break;
- }
- }
- Text ret;
- i = 0;
- esc = 0;
- strO = 0;
- for (; str[i]; i++)
- {
- switch (str[i])
- {
- case '\\':
- if (strO)
- esc = !esc;
- else
- esc = 0;
- ret.append(str[i]);
- break;
- case '"':
- if (!esc) strO = !strO;
- esc = 0;
- ret.append(str[i]);
- break;
- case ' ':
- case '\n':
- case '\t':
- case '\r':
- if (strO) ret.append(str[i]);
- esc = 0;
- break;
- default:
- ret.append(str[i]);
- esc = 0;
- break;
- }
- }
- return ret;
- }
- JSONValue* Parser::getValue(const char* str)
- {
- Text string = Parser::removeWhitespace(str);
- if (string.istGleich("true")) return new JSONBool(1);
- if (string.istGleich("false")) return new JSONBool(0);
- if (string.getText()[0] == '"')
- {
- string.remove(0, 1);
- string.remove(string.getLength() - 1, string.getLength());
- return new JSONString(string);
- }
- if (string.getText()[0] == '[') return new JSONArray(string);
- if (string.getText()[0] == '{') return new JSONObject(string);
- if (Text((int)string).istGleich(string.getText()))
- return new JSONNumber((double)string);
- if (string.anzahlVon('.') == 1)
- {
- bool isNumber = 1;
- for (const char* c = (*string.getText() == '-') ? string.getText() + 1
- : string.getText();
- *c;
- c++)
- isNumber &= (*c >= '0' && *c <= '9') || *c == '.';
- if (isNumber) return new JSONNumber((double)string);
- }
- return new JSONValue();
- }
- int Parser::findFieldEndInObject(const char* str)
- {
- int i = 0;
- bool esc = 0;
- bool strO = 0;
- int objOc = 0;
- int arrayOc = 0;
- for (; str[i]; i++)
- {
- switch (str[i])
- {
- case '\\':
- if (strO)
- esc = !esc;
- else
- esc = 0;
- break;
- case '"':
- if (!esc) strO = !strO;
- esc = 0;
- break;
- case '[':
- if (!strO) arrayOc++;
- esc = 0;
- break;
- case ']':
- if (!strO) arrayOc--;
- esc = 0;
- break;
- case '{':
- if (!strO) objOc++;
- esc = 0;
- break;
- case '}':
- if (!strO) objOc--;
- esc = 0;
- break;
- case ':':
- if (!strO && objOc == 0 && arrayOc == 0) return i;
- esc = 0;
- break;
- default:
- esc = 0;
- break;
- }
- }
- return i;
- }
- int Parser::findValueEndInObject(const char* str)
- {
- int i = 0;
- bool esc = 0;
- bool strO = 0;
- int objOc = 0;
- int arrayOc = 0;
- for (; str[i]; i++)
- {
- switch (str[i])
- {
- case '\\':
- if (strO)
- esc = !esc;
- else
- esc = 0;
- break;
- case '"':
- if (!esc) strO = !strO;
- esc = 0;
- break;
- case '[':
- if (!strO) arrayOc++;
- esc = 0;
- break;
- case ']':
- if (!strO) arrayOc--;
- esc = 0;
- break;
- case '{':
- if (!strO) objOc++;
- esc = 0;
- break;
- case '}':
- if (!strO) objOc--;
- esc = 0;
- break;
- case ',':
- if (!strO && objOc == 0 && arrayOc == 0) return i;
- esc = 0;
- break;
- default:
- esc = 0;
- break;
- }
- }
- return i;
- }
- #pragma endregion Content
- using namespace Validator;
- #pragma region JSONValidationResult
- JSONValidationResult::JSONValidationResult()
- : ReferenceCounter()
- {}
- JSONValidationResult::~JSONValidationResult() {}
- #pragma region JSONTypeMissmatch
- JSONTypeMissmatch::JSONTypeMissmatch(Text path,
- JSONValue* foundValue,
- XML::Element* expected,
- JSONValidationResult* reason)
- : JSONValidationResult()
- {
- this->path = path;
- this->foundValue = foundValue;
- this->expected = expected;
- this->reason = reason;
- }
- JSONTypeMissmatch::~JSONTypeMissmatch()
- {
- foundValue->release();
- expected->release();
- if (reason) reason->release();
- }
- bool JSONTypeMissmatch::isValid() const
- {
- return 0;
- }
- void JSONTypeMissmatch::printInvalidInfo(int indent) const
- {
- Text ind = "";
- ind.fillText(' ', indent);
- std::cout << ind.getText() << "Type missmatch at path '" << path.getText()
- << "'. JSON Value\n"
- << ind.getText() << foundValue->toString().getText() << "\n"
- << ind.getText() << "does not match expected type\n";
- if (reason)
- {
- std::cout << ind.getText() << "Reason for type mismatch:\n";
- reason->printInvalidInfo(indent + 4);
- }
- else
- {
- std::cout << ind.getText() << expected->toString().getText() << "\n";
- }
- }
- JSONValue* JSONTypeMissmatch::getValidPart(
- RCArray<JSONValidationResult>* removedPartsValidationResults)
- {
- if (reason)
- {
- RCArray<JSONValidationResult> temporaryInvalidParts;
- JSONValue* valid = reason->getValidPart(&temporaryInvalidParts);
- Text* p = reason->getPath().getTeilText(path.getLength());
- if (foundValue->getType() == JSONType::ARRAY)
- {
- if (!valid
- && (!expected->hasAttribute("removeInvalidEntries")
- || !expected->getAttributeValue("removeInvalidEntries")
- .istGleich("true")))
- {
- if (removedPartsValidationResults)
- {
- if (temporaryInvalidParts.getEintragAnzahl() == 1)
- {
- if (reason) reason->release();
- reason = temporaryInvalidParts.get(0);
- }
- else
- {
- for (JSONValidationResult* res : temporaryInvalidParts)
- {
- if (res->isDifferent(this))
- {
- removedPartsValidationResults->add(
- dynamic_cast<JSONValidationResult*>(
- res->getThis()));
- }
- }
- }
- removedPartsValidationResults->add(
- dynamic_cast<JSONValidationResult*>(getThis()));
- }
- p->release();
- return 0;
- }
- if (p->hatAt(0, "[") && p->hatAt(p->getLength() - 1, "]"))
- {
- Text* it = p->getTeilText(1, p->getLength() - 1);
- int i = (int)*it;
- it->release();
- if (i >= 0 && foundValue->asArray()->getLength() > i)
- {
- if (removedPartsValidationResults)
- {
- for (JSONValidationResult* res : temporaryInvalidParts)
- {
- removedPartsValidationResults->add(
- dynamic_cast<JSONValidationResult*>(
- res->getThis()));
- }
- }
- JSONValue* tmp = foundValue->clone();
- if (valid)
- tmp->asArray()->setValue(i, valid);
- else
- tmp->asArray()->removeValue(i);
- JSONValidationResult* res = JSONValidator(
- dynamic_cast<XML::Element*>(expected->getThis()))
- .validate(tmp);
- res->addBasePath(path);
- if (res->isValid())
- {
- res->release();
- p->release();
- return tmp;
- }
- else if (res->isDifferent(this) || !valid)
- {
- p->release();
- tmp->release();
- JSONValue* result
- = res->getValidPart(removedPartsValidationResults);
- res->release();
- return result;
- }
- tmp->release();
- res->release();
- }
- }
- }
- else if (foundValue->getType() == JSONType::OBJECT)
- {
- if (!valid
- && (!expected->hasAttribute("removeInvalidEntries")
- || !expected->getAttributeValue("removeInvalidEntries")
- .istGleich("true")))
- {
- if (removedPartsValidationResults)
- {
- if (temporaryInvalidParts.getEintragAnzahl() == 1)
- {
- if (reason) reason->release();
- reason = temporaryInvalidParts.get(0);
- }
- else
- {
- for (JSONValidationResult* res : temporaryInvalidParts)
- {
- if (res->isDifferent(this))
- {
- removedPartsValidationResults->add(
- dynamic_cast<JSONValidationResult*>(
- res->getThis()));
- }
- }
- }
- removedPartsValidationResults->add(
- dynamic_cast<JSONValidationResult*>(getThis()));
- }
- p->release();
- return 0;
- }
- if (p->hatAt(0, "."))
- {
- if (removedPartsValidationResults)
- {
- for (JSONValidationResult* res : temporaryInvalidParts)
- {
- removedPartsValidationResults->add(
- dynamic_cast<JSONValidationResult*>(
- res->getThis()));
- }
- }
- Text* at = p->getTeilText(1);
- Text attr = *at;
- at->release();
- JSONValue* tmp = foundValue->clone();
- tmp->asObject()->removeValue(attr);
- if (valid) tmp->asObject()->addValue(attr, valid);
- JSONValidationResult* res = JSONValidator(
- dynamic_cast<XML::Element*>(expected->getThis()))
- .validate(tmp);
- res->addBasePath(path);
- if (res->isValid())
- {
- res->release();
- p->release();
- return tmp;
- }
- else if (res->isDifferent(this) || !valid)
- {
- p->release();
- tmp->release();
- JSONValue* result
- = res->getValidPart(removedPartsValidationResults);
- res->release();
- return result;
- }
- tmp->release();
- res->release();
- }
- }
- p->release();
- if (valid) valid->release();
- }
- if (removedPartsValidationResults)
- {
- removedPartsValidationResults->add(
- dynamic_cast<JSONValidationResult*>(getThis()));
- }
- return 0;
- }
- Text JSONTypeMissmatch::getPath() const
- {
- return path;
- }
- bool JSONTypeMissmatch::isDifferent(const JSONValidationResult* zResult) const
- {
- const JSONTypeMissmatch* casted
- = dynamic_cast<const JSONTypeMissmatch*>(zResult);
- if (casted == 0) return 1;
- if (!casted->getPath().istGleich(path)) return 1;
- return reason->isDifferent(casted->reason);
- }
- void Framework::JSON::Validator::JSONTypeMissmatch::addBasePath(Text basePath)
- {
- path = basePath + path;
- if (reason) reason->addBasePath(basePath);
- }
- #pragma endregion Content
- #pragma region JSONUnknownValue
- JSONUnknownValue::JSONUnknownValue(Text path, JSONValue* foundValue)
- : JSONValidationResult()
- {
- this->path = path;
- this->foundValue = foundValue;
- }
- JSONUnknownValue::~JSONUnknownValue()
- {
- foundValue->release();
- }
- bool JSONUnknownValue::isValid() const
- {
- return 0;
- }
- void JSONUnknownValue::printInvalidInfo(int indent) const
- {
- Text ind = "";
- ind.fillText(' ', indent);
- std::cout << ind.getText() << "Unknown Value at '" << path.getText()
- << "'. Value found:\n"
- << ind.getText() << foundValue->toString().getText() << "\n";
- }
- JSONValue* JSONUnknownValue::getValidPart(
- RCArray<JSONValidationResult>* removedPartsValidationResults)
- {
- if (removedPartsValidationResults)
- {
- removedPartsValidationResults->add(
- dynamic_cast<JSONValidationResult*>(getThis()));
- }
- return 0;
- }
- Text JSONUnknownValue::getPath() const
- {
- return path;
- }
- bool JSONUnknownValue::isDifferent(const JSONValidationResult* zResult) const
- {
- const JSONUnknownValue* casted
- = dynamic_cast<const JSONUnknownValue*>(zResult);
- if (casted == 0) return 1;
- if (!casted->getPath().istGleich(path)) return 1;
- return 0;
- }
- void Framework::JSON::Validator::JSONUnknownValue::addBasePath(Text basePath)
- {
- path = basePath + path;
- }
- #pragma endregion Content
- #pragma region JSONMissingValue
- JSONMissingValue::JSONMissingValue(Text path, XML::Element* expected)
- : JSONValidationResult()
- {
- this->path = path;
- this->expected = expected;
- }
- JSONMissingValue::~JSONMissingValue()
- {
- expected->release();
- }
- bool JSONMissingValue::isValid() const
- {
- return 0;
- }
- void JSONMissingValue::printInvalidInfo(int indent) const
- {
- Text ind = "";
- ind.fillText(' ', indent);
- std::cout << ind.getText() << "Missing Value at '" << path.getText()
- << "'. Expected type:\n"
- << ind.getText() << expected->toString().getText() << "\n";
- }
- JSONValue* JSONMissingValue::getValidPart(
- RCArray<JSONValidationResult>* removedPartsValidationResults)
- {
- if (expected->hasAttribute("default"))
- {
- JSONValue* def
- = Parser::getValue(expected->getAttributeValue("default"));
- JSONValidationResult* res
- = JSONValidator(dynamic_cast<XML::Element*>(expected->getThis()))
- .validate(def);
- res->addBasePath(path);
- if (res->isValid())
- {
- res->release();
- return def;
- }
- else if (res->isDifferent(this))
- {
- def->release();
- JSONValue* result
- = res->getValidPart(removedPartsValidationResults);
- res->release();
- return result;
- }
- def->release();
- }
- if (removedPartsValidationResults)
- {
- removedPartsValidationResults->add(
- dynamic_cast<JSONValidationResult*>(getThis()));
- }
- return 0;
- }
- Text JSONMissingValue::getPath() const
- {
- return path;
- }
- bool JSONMissingValue::isDifferent(const JSONValidationResult* zResult) const
- {
- const JSONMissingValue* casted
- = dynamic_cast<const JSONMissingValue*>(zResult);
- if (casted == 0) return 1;
- if (!casted->getPath().istGleich(path)) return 1;
- return 0;
- }
- void Framework::JSON::Validator::JSONMissingValue::addBasePath(Text basePath)
- {
- path = basePath + path;
- }
- #pragma endregion Content
- #pragma region JSONMissingOneOf
- JSONMissingOneOf::JSONMissingOneOf(Text path, XML::Editor expected)
- : JSONValidationResult()
- {
- this->path = path;
- for (XML::Element* e : expected)
- this->expected.add(dynamic_cast<XML::Element*>(e->getThis()));
- }
- JSONMissingOneOf::~JSONMissingOneOf() {}
- bool JSONMissingOneOf::isValid() const
- {
- return 0;
- }
- void JSONMissingOneOf::printInvalidInfo(int indent) const
- {
- Text ind = "";
- ind.fillText(' ', indent);
- std::cout << ind.getText() << "Missing Value at '" << path.getText()
- << "'. The value should have one of the specified types:\n";
- ind += " ";
- for (XML::Element* e : expected)
- {
- std::cout << ind.getText() << e->toString().getText() << "\n";
- }
- }
- JSONValue* JSONMissingOneOf::getValidPart(
- RCArray<JSONValidationResult>* removedPartsValidationResults)
- {
- for (XML::Element* e : expected)
- {
- if (e->hasAttribute("default"))
- {
- JSONValue *default = Parser::getValue(e->getAttributeValue("default"));
- if (default)
- {
- JSONValue *valid = JSONValidator(
- dynamic_cast<XML::Element*>(e->getThis()))
- .getValidParts(default, removedPartsValidationResults);
- default->release();
- if (valid)
- {
- return valid;
- }
- }
- }
- }
- if (removedPartsValidationResults)
- {
- removedPartsValidationResults->add(
- dynamic_cast<JSONValidationResult*>(getThis()));
- }
- // multiple possibilities are undecidable
- return 0;
- }
- Text JSONMissingOneOf::getPath() const
- {
- return path;
- }
- bool JSONMissingOneOf::isDifferent(const JSONValidationResult* zResult) const
- {
- const JSONMissingOneOf* casted
- = dynamic_cast<const JSONMissingOneOf*>(zResult);
- if (casted == 0) return 1;
- if (!casted->getPath().istGleich(path)) return 1;
- return 0;
- }
- void Framework::JSON::Validator::JSONMissingOneOf::addBasePath(Text basePath)
- {
- path = basePath + path;
- }
- #pragma endregion Content
- #pragma region JSONNoTypeMatching
- JSONNoTypeMatching::JSONNoTypeMatching(Text path,
- JSONValue* foundValue,
- RCArray<XML::Element>& expected,
- RCArray<JSONValidationResult>& reasons)
- : JSONValidationResult()
- {
- this->path = path;
- this->foundValue = foundValue;
- this->expected = expected;
- this->reasons = reasons;
- }
- JSONNoTypeMatching::~JSONNoTypeMatching()
- {
- foundValue->release();
- }
- bool JSONNoTypeMatching::isValid() const
- {
- return 0;
- }
- void JSONNoTypeMatching::printInvalidInfo(int indent) const
- {
- Text ind = "";
- ind.fillText(' ', indent);
- std::cout << ind.getText() << "Found Value at '" << path.getText()
- << "' did not match any of the specified types\n";
- Text ind2 = ind + " ";
- std::cout << ind.getText() << "Reasons:\n";
- for (JSONValidationResult* reason : reasons)
- {
- reason->printInvalidInfo(indent + 4);
- }
- }
- JSONValue* JSONNoTypeMatching::getValidPart(
- RCArray<JSONValidationResult>* removedPartsValidationResults)
- {
- RCArray<JSONValidationResult> tempErrors;
- for (JSONValidationResult* reason : reasons)
- {
- JSONValue* result = reason->getValidPart(&tempErrors);
- if (result)
- {
- return result;
- }
- }
- if (removedPartsValidationResults)
- {
- removedPartsValidationResults->add(
- dynamic_cast<JSONValidationResult*>(getThis()));
- reasons.leeren();
- for (JSONValidationResult* error : tempErrors)
- {
- reasons.add(dynamic_cast<JSONValidationResult*>(error->getThis()));
- }
- }
- // multiple possibilities are undecidable
- return 0;
- }
- Text JSONNoTypeMatching::getPath() const
- {
- return path;
- }
- bool JSONNoTypeMatching::isDifferent(const JSONValidationResult* zResult) const
- {
- const JSONNoTypeMatching* casted
- = dynamic_cast<const JSONNoTypeMatching*>(zResult);
- if (casted == 0) return 1;
- if (!casted->getPath().istGleich(path)) return 1;
- for (int i = 0; i < reasons.getEintragAnzahl(); i++)
- {
- if (reasons.z(i)->isDifferent(casted->reasons.z(i))) return 1;
- }
- return 0;
- }
- void Framework::JSON::Validator::JSONNoTypeMatching::addBasePath(Text basePath)
- {
- path = basePath + path;
- for (JSONValidationResult* reason : reasons)
- {
- reason->addBasePath(basePath);
- }
- }
- #pragma endregion Content
- #pragma region JSONValidValue
- JSONValidValue::JSONValidValue(Text path, JSONValue* value)
- : JSONValidationResult()
- {
- this->path = path;
- this->value = value;
- }
- JSONValidValue::~JSONValidValue()
- {
- value->release();
- }
- bool JSONValidValue::isValid() const
- {
- return 1;
- }
- void JSONValidValue::printInvalidInfo(int indent) const {}
- JSONValue* JSONValidValue::getValidPart(
- RCArray<JSONValidationResult>* removedPartsValidationResults)
- {
- return value->clone();
- }
- Text JSONValidValue::getPath() const
- {
- return path;
- }
- bool JSONValidValue::isDifferent(const JSONValidationResult* zResult) const
- {
- const JSONValidValue* casted = dynamic_cast<const JSONValidValue*>(zResult);
- if (casted == 0) return 1;
- if (!casted->getPath().istGleich(path)) return 1;
- return 0;
- }
- void Framework::JSON::Validator::JSONValidValue::addBasePath(Text basePath)
- {
- path = basePath + path;
- }
- #pragma endregion Content
- #pragma endregion Content
- #pragma region JSONValidator
- JSONValidator::JSONValidator(XML::Element* constraints)
- : ReferenceCounter(),
- constraints(constraints)
- {
- for (XML::Element* e : constraints->select()
- .selectAllElements()
- .whereNameEquals("object")
- .whereAttributeExists("id"))
- {
- Framework::Text id = e->getAttributeValue("id");
- typeConstraints.set(id, id.getLength(), e);
- }
- }
- JSONValidator::~JSONValidator()
- {
- constraints->release();
- }
- JSONValidationResult* JSONValidator::validate(JSONValue* zValue) const
- {
- return validate(zValue, constraints, "");
- }
- bool JSONValidator::isValid(JSONValue* zValue) const
- {
- JSONValidationResult* res = validate(zValue);
- if (res->isValid())
- {
- res->release();
- return 1;
- }
- res->release();
- return 0;
- }
- JSONValue* JSONValidator::getValidParts(JSONValue* zValue,
- RCArray<JSONValidationResult>* removedPartsValidationResults) const
- {
- JSONValidationResult* res = validate(zValue);
- if (res->isValid())
- {
- res->release();
- return zValue->clone();
- }
- JSONValue* valid = res->getValidPart(removedPartsValidationResults);
- res->release();
- return valid;
- }
- XML::Element* JSONValidator::zConstraints()
- {
- return constraints;
- }
- JSONValidationResult* JSONValidator::validate(
- JSONValue* zValue, XML::Element* zConstraints, Text path) const
- {
- if (zConstraints->getName().istGleich("oneOf"))
- {
- return validateMultipleTypes(zValue, zConstraints, path);
- }
- switch (zValue->getType())
- {
- case JSONType::NULL_:
- if (!zConstraints->hasAttribute("nullable")
- || !zConstraints->getAttributeValue("nullable").istGleich("true"))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- break;
- case JSONType::BOOLEAN:
- if (!zConstraints->getName().istGleich("bool"))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- else if (zConstraints->hasAttribute("equals"))
- {
- if (!zConstraints->getAttributeValue("equals").istGleich("true")
- == !zValue->asBool()->getBool())
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- }
- break;
- case JSONType::NUMBER:
- if (!zConstraints->getName().istGleich("number"))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- else
- {
- if (zConstraints->hasAttribute("equals")
- && (double)zConstraints->getAttributeValue("equals")
- != zValue->asNumber()->getNumber())
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- if (zConstraints->hasAttribute("lessOrEqual")
- && zValue->asNumber()->getNumber()
- > (double)zConstraints->getAttributeValue("lessOrEqual"))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- if (zConstraints->hasAttribute("greaterOrEqual")
- && zValue->asNumber()->getNumber()
- < (double)zConstraints->getAttributeValue(
- "greaterOrEqual"))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- if (zConstraints->hasAttribute("less")
- && zValue->asNumber()->getNumber()
- >= (double)zConstraints->getAttributeValue("less"))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- if (zConstraints->hasAttribute("greater")
- && zValue->asNumber()->getNumber()
- <= (double)zConstraints->getAttributeValue("greater"))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- }
- break;
- case JSONType::STRING:
- if (!zConstraints->getName().istGleich("string"))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- else
- {
- if (zConstraints->hasAttribute("equals")
- && !zConstraints->getAttributeValue("equals").istGleich(
- zValue->asString()->getString()))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- if (zConstraints->hasAttribute("contains")
- && zValue->asString()->getString().hat(
- zConstraints->getAttributeValue("contains").getText()))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- if (zConstraints->hasAttribute("startsWith")
- && zValue->asString()->getString().positionVon(
- zConstraints->getAttributeValue("startsWith").getText())
- == 0)
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- if (zConstraints->hasAttribute("endsWith")
- && zValue->asString()->getString().positionVon(
- zConstraints->getAttributeValue("endsWith").getText())
- == zValue->asString()->getString().getLength()
- - zConstraints->getAttributeValue("endsWith")
- .getLength())
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- if (zConstraints->hasAttribute("oneOf"))
- {
- JSONArray* array
- = Parser::getValue(zConstraints->getAttributeValue("oneOf"))
- ->asArray();
- bool ok = 0;
- for (JSONValue* v : *array)
- {
- if (v->asString()->getString().istGleich(
- zValue->asString()->getString()))
- {
- ok = 1;
- break;
- }
- }
- array->release();
- if (!ok)
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- }
- }
- break;
- case JSONType::ARRAY:
- if (!zConstraints->getName().istGleich("array"))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- else
- {
- int index = 0;
- for (JSON::JSONValue* value : *zValue->asArray())
- {
- Text p = path;
- p += "[";
- p += index;
- p += "]";
- JSONValidationResult* res
- = validateMultipleTypes(value, zConstraints, p);
- if (!res->isValid())
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- res);
- }
- res->release();
- index++;
- }
- }
- break;
- case JSONType::OBJECT:
- if (zConstraints->getName().istGleich("objectRef"))
- {
- Text id = zConstraints->getAttributeValue("ref");
- XML::Element* e = typeConstraints.get(id, id.getLength());
- if (e)
- {
- zConstraints = e;
- }
- }
- if (!zConstraints->getName().istGleich("object"))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(zConstraints->getThis()),
- 0);
- }
- else
- {
- JSON::JSONObject* obj = zValue->asObject();
- for (auto i = obj->getFields(); i; i++)
- {
- Text p = path;
- p += ".";
- p += i.val();
- if (!zConstraints->selectChildsByAttribute("name", i.val())
- .exists())
- {
- if (!zConstraints
- ->getAttributeValue("allowAdditionalAttributes")
- .istGleich("true"))
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(
- zConstraints->getThis()),
- new JSONUnknownValue(
- p, zValue->asObject()->getValue(i.val())));
- }
- }
- else
- {
- XML::Editor tmp = zConstraints->selectChildsByAttribute(
- "name", i.val());
- JSONValidationResult* res = validateMultipleTypes(
- zValue->asObject()->zValue(i.val()),
- tmp.begin().val(),
- p);
- if (!res->isValid())
- {
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(
- zConstraints->getThis()),
- res);
- }
- res->release();
- }
- }
- for (XML::Element* constraint : zConstraints->selectChildren())
- {
- if (!zValue->asObject()->hasValue(
- constraint->getAttributeValue("name")))
- {
- XML::Editor tmp = constraint->selectChildren();
- bool optional = true;
- std::function<void(XML::Element*)> checkOptional;
- checkOptional = [&optional, &checkOptional](
- XML::Element* zElement) {
- if (zElement->getName().istGleich("oneOf"))
- {
- XML::Editor tmp = zElement->selectChildren();
- tmp.forEach(checkOptional);
- }
- else
- {
- optional &= zElement->hasAttribute("optional")
- && zElement->getAttributeValue("optional")
- .istGleich("true");
- }
- };
- tmp.forEach(checkOptional);
- if (!optional)
- {
- Text p = path;
- p += ".";
- p += constraint->getAttributeValue("name");
- if (constraint->getChildCount() != 1)
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(
- zConstraints->getThis()),
- new JSONMissingOneOf(p, tmp));
- return new JSONTypeMissmatch(path,
- dynamic_cast<JSONValue*>(zValue->getThis()),
- dynamic_cast<XML::Element*>(
- zConstraints->getThis()),
- new JSONMissingValue(p,
- dynamic_cast<XML::Element*>(
- tmp.begin()->getThis())));
- }
- }
- }
- }
- break;
- }
- return new JSONValidValue(
- path, dynamic_cast<JSONValue*>(zValue->getThis()));
- }
- JSONValidationResult* JSONValidator::validateMultipleTypes(
- JSONValue* zChildValue,
- XML::Element* zPossibleChildConstraints,
- Text childPath) const
- {
- if (zPossibleChildConstraints->getChildCount() == 1
- && !zPossibleChildConstraints->hasAttribute("typeSpecifiedBy"))
- {
- XML::Editor children = zPossibleChildConstraints->selectChildren();
- return validate(zChildValue,
- children.begin().val(),
- childPath); // only one type is possible
- }
- bool hasTypeAttr = 0;
- RCArray<XML::Element> possibleConstraints;
- if (zPossibleChildConstraints->hasAttribute("typeSpecifiedBy"))
- { // try to find the correct constraints based on the type attribute
- hasTypeAttr = 1;
- Text typeAttr
- = zPossibleChildConstraints->getAttributeValue("typeSpecifiedBy");
- if (zChildValue->getType() == JSONType::OBJECT)
- {
- if (zChildValue->asObject()->hasValue(typeAttr))
- {
- JSONValue* typeV = zChildValue->asObject()->zValue(typeAttr);
- for (XML::Element* constraint :
- zPossibleChildConstraints->selectChildsByName("object")
- .whereChildWithAttributeExists("name", typeAttr))
- {
- XML::Editor nameChildren
- = constraint->selectChildsByAttribute("name", typeAttr);
- XML::Element* typeAttrContraints
- = nameChildren.begin().val();
- JSONValidationResult* res = validateMultipleTypes(
- typeV, typeAttrContraints, childPath + "." + typeAttr);
- if (res->isValid())
- possibleConstraints.add(
- dynamic_cast<XML::Element*>(constraint->getThis()));
- res->release();
- }
- }
- }
- }
- if (hasTypeAttr && possibleConstraints.getEintragAnzahl() == 1)
- return validate(zChildValue,
- possibleConstraints.begin().val(),
- childPath); // if the type is clear
- else if (hasTypeAttr && possibleConstraints.getEintragAnzahl() > 0)
- { // more then one type is possible
- RCArray<JSONValidationResult> invalidResults;
- for (XML::Element* constraint : possibleConstraints)
- {
- JSONValidationResult* res
- = validate(zChildValue, constraint, childPath);
- invalidResults.add(res);
- if (res->isValid())
- return new JSONValidValue(childPath,
- dynamic_cast<JSONValue*>(zChildValue->getThis()));
- }
- return new JSONNoTypeMatching(childPath,
- dynamic_cast<JSONValue*>(zChildValue->getThis()),
- possibleConstraints,
- invalidResults);
- }
- // try all types
- possibleConstraints.leeren();
- RCArray<JSONValidationResult> invalidResults;
- for (XML::Element* constraint : zPossibleChildConstraints->selectChildren())
- {
- JSONValidationResult* res
- = validate(zChildValue, constraint, childPath);
- invalidResults.add(res);
- if (res->isValid())
- return new JSONValidValue(
- childPath, dynamic_cast<JSONValue*>(zChildValue->getThis()));
- possibleConstraints.add(
- dynamic_cast<XML::Element*>(constraint->getThis()));
- }
- return new JSONNoTypeMatching(childPath,
- dynamic_cast<JSONValue*>(zChildValue->getThis()),
- possibleConstraints,
- invalidResults);
- }
- StringValidationBuilder<JSONValidator>* JSONValidator::buildForString()
- {
- return new StringValidationBuilder<JSONValidator>(
- [](XML::Element& e) { return new JSONValidator(e.dublicate()); });
- }
- NumberValidationBuilder<JSONValidator>* JSONValidator::buildForNumber()
- {
- return new NumberValidationBuilder<JSONValidator>(
- [](XML::Element& e) { return new JSONValidator(e.dublicate()); });
- }
- BoolValidationBuilder<JSONValidator>* JSONValidator::buildForBool()
- {
- return new BoolValidationBuilder<JSONValidator>(
- [](XML::Element& e) { return new JSONValidator(e.dublicate()); });
- }
- ObjectValidationBuilder<JSONValidator>* JSONValidator::buildForObject()
- {
- return new ObjectValidationBuilder<JSONValidator>(
- [](XML::Element& e) { return new JSONValidator(e.dublicate()); });
- }
- ArrayValidationBuilder<JSONValidator>* JSONValidator::buildForArray()
- {
- return new ArrayValidationBuilder<JSONValidator>(
- [](XML::Element& e) { return new JSONValidator(e.dublicate()); });
- }
- JSONValidator* JSONValidator::buildForObjectReference(Text objectId)
- {
- return new JSONValidator(
- new XML::Element(Text("<objectRef ref=\"") + objectId + Text("\"/>")));
- }
- OneOfValidationBuilder<JSONValidator>* JSONValidator::buildForOneOf()
- {
- return new OneOfValidationBuilder<JSONValidator>(
- [](XML::Element& e) { return new JSONValidator(e.dublicate()); });
- }
- #pragma endregion Content
|