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));
}
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;
}
Aggregations