1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786 |
- #include "JSON.h"
- #include "Datei.h"
- #include "Logging.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;
- }
- ArrayIterator<JSONValue*> JSONArray::begin() const
- {
- return array->begin();
- }
- ArrayIterator<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;
- }
- ArrayIterator<Text> JSONObject::getFields()
- {
- return fields->begin();
- }
- ArrayIterator<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 = "{";
- ArrayIterator<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() {}
- void Framework::JSON::Validator::JSONValidationResult::logInvalidInfo(
- std::source_location location) const
- {
- Logging::error(location) << getInvalidInfo(0).getText();
- }
- #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;
- }
- Text JSONTypeMissmatch::getInvalidInfo(int indent) const
- {
- Text ind = "";
- ind.fillText(' ', indent);
- Text error = "";
- error.append() << 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)
- {
- error.append() << ind.getText() << "Reason for type mismatch:\n"
- << reason->getInvalidInfo(indent + 4);
- }
- else
- {
- error.append() << ind.getText() << expected->toString().getText()
- << "\n";
- }
- return error;
- }
- 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;
- }
- Text JSONUnknownValue::getInvalidInfo(int indent) const
- {
- Text ind = "";
- ind.fillText(' ', indent);
- Text error = "";
- error.append() << ind.getText() << "Unknown Value at '" << path.getText()
- << "'. Value found:\n"
- << ind.getText() << foundValue->toString().getText() << "\n";
- return error;
- }
- 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;
- }
- Text JSONMissingValue::getInvalidInfo(int indent) const
- {
- Text ind = "";
- ind.fillText(' ', indent);
- Text error = "";
- error.append() << ind.getText() << "Missing Value at '" << path.getText()
- << "'. Expected type:\n"
- << ind.getText() << expected->toString().getText() << "\n";
- return error;
- }
- 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;
- }
- Text JSONMissingOneOf::getInvalidInfo(int indent) const
- {
- Text ind = "";
- ind.fillText(' ', indent);
- Text error = "";
- error.append() << ind.getText() << "Missing Value at '" << path.getText()
- << "'. The value should have one of the specified types:\n";
- ind += " ";
- for (XML::Element* e : expected)
- {
- error.append() << ind.getText() << e->toString().getText() << "\n";
- }
- return error;
- }
- JSONValue* JSONMissingOneOf::getValidPart(
- RCArray<JSONValidationResult>* removedPartsValidationResults)
- {
- for (XML::Element* e : expected)
- {
- if (e->hasAttribute("default"))
- {
- JSONValue* defaultValue
- = Parser::getValue(e->getAttributeValue("default"));
- if (defaultValue)
- {
- JSONValue* valid
- = JSONValidator(dynamic_cast<XML::Element*>(e->getThis()))
- .getValidParts(
- defaultValue, removedPartsValidationResults);
- defaultValue->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;
- }
- Text JSONNoTypeMatching::getInvalidInfo(int indent) const
- {
- Text ind = "";
- ind.fillText(' ', indent);
- Text error = "";
- error.append() << ind.getText() << "Found Value at '" << path.getText()
- << "' did not match any of the specified types\n";
- Text ind2 = ind + " ";
- error.append() << ind.getText() << "Reasons:\n";
- for (JSONValidationResult* reason : reasons)
- {
- error += reason->getInvalidInfo(indent + 4);
- }
- return error;
- }
- 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;
- }
- Text JSONValidValue::getInvalidInfo(int indent) const
- {
- return "";
- }
- 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
|