Search in sources :

Example 1 with CompiledPattern

use of org.whole.lang.grammars.model.CompiledPattern in project whole by wholeplatform.

the class GenericGrammarBasedValidatorVisitor method validateDataTerminal.

protected void validateDataTerminal(IEntity entity) {
    EntityDescriptor<?> ed = entity.wGetEntityDescriptor();
    if (ed.getDataKind().isEnumValue())
        return;
    String value = DataTypeUtils.getAsPersistenceString(entity);
    DataTerminal dataTerminal = getDataTerminal(ed);
    if (dataTerminal != null) {
        Pattern pattern = ((CompiledPattern) dataTerminal.getPattern()).getValue();
        if (!pattern.matcher(value).matches())
            getDecorationManager().addError(entity, "the data entity doesn't match the pattern: " + pattern.toString(), EntityUtils.getLocation(entity));
    } else
        getDecorationManager().addError(entity, "the data entity is unknonwn", EntityUtils.getLocation(entity));
}
Also used : Pattern(java.util.regex.Pattern) CompiledPattern(org.whole.lang.grammars.model.CompiledPattern) CompiledPattern(org.whole.lang.grammars.model.CompiledPattern) DataTerminal(org.whole.lang.grammars.model.DataTerminal)

Example 2 with CompiledPattern

use of org.whole.lang.grammars.model.CompiledPattern in project whole by wholeplatform.

the class GrammarsDefaultDataTypeParser method matches.

protected String matches(EntityDescriptor<?> ed, String value) {
    Pattern pattern = grammarBasedDataTypeParser.getDataTerminal(ed).getPattern();
    java.util.regex.Pattern compiledPattern = Matcher.matchImpl(GrammarsEntityDescriptorEnum.CompiledPattern, pattern) ? ((CompiledPattern) pattern).getValue() : java.util.regex.Pattern.compile(((RegExp) pattern).getValue());
    if (!compiledPattern.matcher(value).matches())
        throw new WholeIllegalArgumentException(WholeMessages.no_data_type);
    return value;
}
Also used : CompiledPattern(org.whole.lang.grammars.model.CompiledPattern) Pattern(org.whole.lang.grammars.model.Pattern) RegExp(org.whole.lang.grammars.model.RegExp) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException)

Aggregations

CompiledPattern (org.whole.lang.grammars.model.CompiledPattern)2 Pattern (java.util.regex.Pattern)1 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)1 DataTerminal (org.whole.lang.grammars.model.DataTerminal)1 Pattern (org.whole.lang.grammars.model.Pattern)1 RegExp (org.whole.lang.grammars.model.RegExp)1