use of org.eclipse.winery.model.converter.support.exception.InvalidToscaSyntax in project winery by eclipse.
the class YamlReader method readServiceTemplate.
/**
* Reads a file and converts it to a ServiceTemplate
*
* @return ServiceTemplate
* @throws MultiException the ServiceTemplate or the file is invalid.
*/
private YTServiceTemplate readServiceTemplate(InputStream inputStream, String namespace) throws MultiException {
Object object = null;
// pre parse checking
try {
object = readObjectFromInputStream(inputStream);
ObjectValidator objectValidator = new ObjectValidator();
objectValidator.validateObject(object);
} catch (ConstructorException e) {
ExceptionInterpreter interpreter = new ExceptionInterpreter();
throw new MultiException().add(interpreter.interpret(e));
} catch (ScannerException e) {
ExceptionInterpreter interpreter = new ExceptionInterpreter();
throw new MultiException().add(interpreter.interpret(e));
} catch (InvalidToscaSyntax invalidToscaSyntax) {
invalidToscaSyntax.printStackTrace();
}
// parse checking
return buildServiceTemplate(object, namespace);
}
use of org.eclipse.winery.model.converter.support.exception.InvalidToscaSyntax in project winery by eclipse.
the class ObjectValidator method validateObject.
public void validateObject(Object object) throws InvalidToscaSyntax {
if (object instanceof LinkedHashMap) {
LinkedHashMap map = (LinkedHashMap) object;
Set<Map.Entry> entries = map.entrySet();
if (entries.size() == 0 || !entries.iterator().next().getKey().equals("tosca_definitions_version")) {
for (Map.Entry entry : entries) {
if (entry.getKey().equals("tosca_definitions_version")) {
throw new InvalidToscaSyntax("The field tosca_definitions_version MUST be defined before all other YAML elements");
}
}
}
}
}
Aggregations