use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException in project scheduling by ow2-proactive.
the class ModelFromURLParserValidator method createValidator.
@Override
protected Validator<String> createValidator(String model, Converter<String> converter) throws ModelSyntaxException {
String modelFromUrlRegexp = "^" + MODEL_FROM_URL_TYPE_REGEXP + LEFT_DELIMITER_REGEXP + "(.+)" + RIGHT_DELIMITER_REGEXP + "$";
String urlString = parseAndGetOneGroup(model, modelFromUrlRegexp);
URL url = null;
try {
url = new URL(urlString);
List<String> lines = IOUtils.readLines(url.openStream(), Charset.defaultCharset());
String modelReceivedFromURL = null;
modelReceivedFromURL = findFirstNonEmptyLineTrimmed(lines);
if (Strings.isNullOrEmpty(modelReceivedFromURL)) {
throw new ModelSyntaxException("In " + getType() + " expression, model received from defined url '" + urlString + "' is empty.");
}
if (modelReceivedFromURL.startsWith(MODEL_FROM_URL_TYPE)) {
throw new ModelSyntaxException("In " + getType() + " expression, model received from defined url '" + urlString + "' is recursive.");
}
return new ModelValidator(modelReceivedFromURL);
} catch (MalformedURLException e) {
throw new ModelSyntaxException("In " + getType() + " expression, defined url '" + urlString + "' is invalid: " + e.getMessage(), e);
} catch (IOException e) {
throw new ModelSyntaxException("In " + getType() + " expression, defined url '" + urlString + "' could not be reached: " + e.getMessage(), e);
}
}
use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException in project scheduling by ow2-proactive.
the class BaseParserValidator method parseAndGetRegexGroups.
protected static List<String> parseAndGetRegexGroups(String valueToParse, String regexp) throws ModelSyntaxException {
try {
Pattern pattern = Pattern.compile(regexp);
Matcher matcher = pattern.matcher(valueToParse);
if (matcher.find()) {
return getMatchedGroups(matcher, matcher.groupCount());
} else {
throw new ModelSyntaxException("Expression '" + valueToParse + "' does not match " + regexp);
}
} catch (PatternSyntaxException e) {
throw new ModelSyntaxException("Internal error, regular expression '" + regexp + "' is invalid: " + e.getMessage(), e);
}
}
use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException in project scheduling by ow2-proactive.
the class RangeParserValidator method createValidator.
@Override
protected Validator<T> createValidator(String model, Converter<T> converter) throws ModelSyntaxException {
if (model.matches(getTypeRegexp())) {
return new RangeValidator();
}
String mainRangeRegexp = "^" + getTypeRegexp() + RANGE_MAIN_REGEXP + "$";
String rangeString = parseAndGetOneGroup(model, mainRangeRegexp);
try {
return new RangeValidator<>(extractRange(rangeString, converter));
} catch (IllegalArgumentException e) {
throw new ModelSyntaxException(e.getMessage(), e);
}
}
use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException in project scheduling by ow2-proactive.
the class RegexpParserValidator method createValidator.
@Override
protected Validator<String> createValidator(String model, Converter<String> converter) throws ModelSyntaxException {
String regexpRegexp = "^" + REGEXP_TYPE_REGEXP + LEFT_DELIMITER_REGEXP + "(.+)" + RIGHT_DELIMITER_REGEXP + "$";
String regexpString = parseAndGetOneGroup(model, regexpRegexp);
try {
return new RegexpValidator(regexpString);
} catch (PatternSyntaxException e) {
throw new ModelSyntaxException(e.getMessage(), e);
}
}
use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException in project scheduling by ow2-proactive.
the class SPELParserValidator method createValidator.
@Override
protected Validator<String> createValidator(String model, Converter<String> converter) throws ModelSyntaxException {
String spelRegexp = "^" + SPEL_TYPE_REGEXP + LEFT_DELIMITER_REGEXP + "(.+)" + RIGHT_DELIMITER_REGEXP + "$";
String spelString = parseAndGetOneGroup(model, spelRegexp);
try {
return new SpelValidator(spelString);
} catch (ParseException e) {
throw new ModelSyntaxException(e.getMessage(), e);
}
}
Aggregations