Search in sources :

Example 1 with CouldNotResolveReferenceException

use of org.eclipse.vorto.repository.core.impl.validation.CouldNotResolveReferenceException in project vorto by eclipse.

the class AbstractModelParser method parse.

@Override
public ModelInfo parse(InputStream is) {
    Injector injector = getInjector();
    XtextResourceSet resourceSet = workspace.getResourceSet();
    Resource resource = createResource(fileName, getContent(is), resourceSet).orElseThrow(() -> new ValidationException("Xtext is not able to create a resource for this model. Check if you are using the correct parser.", getModelInfoFromFilename()));
    if (resource.getContents().size() <= 0) {
        throw new ValidationException("Xtext is not able to create a model out of this file. Check if the file you are using is correct.", getModelInfoFromFilename());
    }
    Model model = (Model) resource.getContents().get(0);
    // always load direct references to make the model complete
    workspace.loadFromRepository(getReferences(model));
    if (this.isValidationEnabled) {
        /* Execute validators */
        IResourceValidator validator = injector.getInstance(IResourceValidator.class);
        List<Issue> issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
        if (issues.size() > 0) {
            List<ModelId> missingReferences = getMissingReferences(model, issues);
            if (missingReferences.size() > 0) {
                throw new CouldNotResolveReferenceException(getModelInfo(model).orElse(getModelInfoFromFilename()), missingReferences);
            } else {
                Set<ValidationIssue> validationIssues = convertIssues(issues);
                throw new ValidationException(collate(validationIssues), validationIssues, getModelInfo(model).orElse(getModelInfoFromFilename()));
            }
        }
        if (!resource.getErrors().isEmpty()) {
            throw new ValidationException(resource.getErrors().get(0).getMessage(), getModelInfo(model).orElse(getModelInfoFromFilename()));
        }
    }
    return new ModelResource((Model) resource.getContents().get(0));
}
Also used : ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) Issue(org.eclipse.xtext.validation.Issue) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) CouldNotResolveReferenceException(org.eclipse.vorto.repository.core.impl.validation.CouldNotResolveReferenceException) ModelResource(org.eclipse.vorto.repository.core.ModelResource) Resource(org.eclipse.emf.ecore.resource.Resource) ModelResource(org.eclipse.vorto.repository.core.ModelResource) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Model(org.eclipse.vorto.core.api.model.model.Model) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

Injector (com.google.inject.Injector)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Model (org.eclipse.vorto.core.api.model.model.Model)1 ModelId (org.eclipse.vorto.model.ModelId)1 ModelResource (org.eclipse.vorto.repository.core.ModelResource)1 CouldNotResolveReferenceException (org.eclipse.vorto.repository.core.impl.validation.CouldNotResolveReferenceException)1 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)1 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)1 IResourceValidator (org.eclipse.xtext.validation.IResourceValidator)1 Issue (org.eclipse.xtext.validation.Issue)1