use of com.ait.lienzo.client.core.AttributeType in project lienzo-core by ahome-it.
the class MultiTypeValidator method validate.
@Override
public void validate(final JSONValue jval, final ValidationContext ctx) throws ValidationException {
for (final AttributeType type : m_types) {
boolean valid = true;
final ValidationContext test = new ValidationContext().setStopOnError(false);
try {
type.validate(jval, test);
} catch (final ValidationException e) {
valid = false;
}
if (test.getErrorCount() > 0) {
valid = false;
}
if (valid) {
// OK
return;
}
}
ctx.addBadTypeError(getTypeName());
}
use of com.ait.lienzo.client.core.AttributeType in project lienzo-core by ahome-it.
the class JSONDeserializer method validateAttributes.
protected final void validateAttributes(final JSONObject json, final IFactory<?> factory, final String type, final ValidationContext ctx) throws ValidationException {
final JSONValue aval = json.get("attributes");
if (null == aval) {
// OK - 'attributes' is optional
return;
}
ctx.push("attributes");
final JSONObject aobj = aval.isObject();
if (aobj == null) {
ctx.addBadTypeError("Object");
return;
} else {
// Make sure all required attributes are defined (and not null)
final Set<String> keys = aobj.keySet();
for (final Attribute attr : factory.getRequiredAttributes()) {
final String attrName = attr.getProperty();
ctx.push(attrName);
if (false == keys.contains(attrName)) {
// value is missing
ctx.addRequiredError();
} else {
final JSONValue jval = aobj.get(attrName);
if (((jval == null) || (jval.isNull() != null))) {
// value is null
ctx.addRequiredError();
}
}
// attrName
ctx.pop();
}
for (final String attrName : keys) {
ctx.push(attrName);
final AttributeType atyp = factory.getAttributeType(attrName);
if (atyp == null) {
ctx.addInvalidAttributeError(type);
} else {
atyp.validate(aobj.get(attrName), ctx);
}
// attrName
ctx.pop();
}
}
// attributes
ctx.pop();
}
Aggregations