Search in sources :

Example 1 with ConstructorException

use of org.yaml.snakeyaml.constructor.ConstructorException in project winery by eclipse.

the class Reader method readServiceTemplate.

/**
 * Reads a file and converts it to a ServiceTemplate
 *
 * @return ServiceTemplate
 * @throws MultiException the ServiceTemplate or the file is invalid.
 */
private TServiceTemplate readServiceTemplate(Path path, Path file, String namespace) throws MultiException {
    Path filePath;
    if (Objects.isNull(path)) {
        filePath = file;
    } else {
        filePath = path.resolve(file);
    }
    // 
    if (!fileChanged(filePath)) {
        if (exceptionBuffer.containsKey(filePath)) {
            throw exceptionBuffer.get(filePath);
        }
        if (serviceTemplateBuffer.containsKey(filePath)) {
            return serviceTemplateBuffer.get(filePath);
        }
    }
    logger.debug("Read Service Template: {}", filePath);
    try {
        // pre parse checking
        try {
            ObjectValidator objectValidator = new ObjectValidator();
            objectValidator.validateObject(readObject(filePath));
        } 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 (YAMLParserException e) {
            throw new MultiException().add(e);
        }
        // parse checking
        TServiceTemplate result = buildServiceTemplate(readObject(filePath), namespace);
        // post parse checking
        Validator validator = new Validator(path);
        validator.validate(result, namespace);
        serviceTemplateBuffer.put(filePath, result);
        return result;
    } catch (MultiException e) {
        exceptionBuffer.put(filePath, e);
        throw e.add(file.toString());
    }
}
Also used : Path(java.nio.file.Path) ScannerException(org.yaml.snakeyaml.scanner.ScannerException) ExceptionInterpreter(org.eclipse.winery.yaml.common.validator.support.ExceptionInterpreter) YAMLParserException(org.eclipse.winery.yaml.common.exception.YAMLParserException) ObjectValidator(org.eclipse.winery.yaml.common.validator.ObjectValidator) ConstructorException(org.yaml.snakeyaml.constructor.ConstructorException) MultiException(org.eclipse.winery.yaml.common.exception.MultiException) ObjectValidator(org.eclipse.winery.yaml.common.validator.ObjectValidator) Validator(org.eclipse.winery.yaml.common.validator.Validator) TServiceTemplate(org.eclipse.winery.model.tosca.yaml.TServiceTemplate)

Aggregations

Path (java.nio.file.Path)1 TServiceTemplate (org.eclipse.winery.model.tosca.yaml.TServiceTemplate)1 MultiException (org.eclipse.winery.yaml.common.exception.MultiException)1 YAMLParserException (org.eclipse.winery.yaml.common.exception.YAMLParserException)1 ObjectValidator (org.eclipse.winery.yaml.common.validator.ObjectValidator)1 Validator (org.eclipse.winery.yaml.common.validator.Validator)1 ExceptionInterpreter (org.eclipse.winery.yaml.common.validator.support.ExceptionInterpreter)1 ConstructorException (org.yaml.snakeyaml.constructor.ConstructorException)1 ScannerException (org.yaml.snakeyaml.scanner.ScannerException)1