Search in sources :

Example 1 with AttributeType

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());
}
Also used : AttributeType(com.ait.lienzo.client.core.AttributeType)

Example 2 with AttributeType

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();
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONObject(com.google.gwt.json.client.JSONObject) Attribute(com.ait.lienzo.client.core.Attribute) AttributeType(com.ait.lienzo.client.core.AttributeType) JSONString(com.google.gwt.json.client.JSONString)

Aggregations

AttributeType (com.ait.lienzo.client.core.AttributeType)2 Attribute (com.ait.lienzo.client.core.Attribute)1 JSONObject (com.google.gwt.json.client.JSONObject)1 JSONString (com.google.gwt.json.client.JSONString)1 JSONValue (com.google.gwt.json.client.JSONValue)1