use of org.eclipse.vorto.repository.core.impl.ModelEMFResource in project vorto by eclipse.
the class TypeImportValidation method validate.
@Override
public void validate(ModelInfo modelResource, InvocationContext context) throws ValidationException {
Collection<String> unImportedReferences = Lists.newArrayList();
ModelEMFResource emfModel = (ModelEMFResource) modelResource;
Model model = emfModel.getModel();
if (model == null)
return;
if (model instanceof Entity) {
unImportedReferences.addAll(getUnimportedProperties(((Entity) model).getProperties(), model.getReferences()));
} else if (model instanceof FunctionblockModel) {
unImportedReferences.addAll(validateFunctionBlock((FunctionblockModel) model));
} else if (model instanceof InformationModel) {
unImportedReferences.addAll(getUnimportedFunctionblocks(((InformationModel) model).getProperties(), model.getReferences()));
}
unImportedReferences.forEach(ref -> System.out.println("Missing : " + ref));
if (!unImportedReferences.isEmpty()) {
throw new ValidationException(errorMessage(unImportedReferences), modelResource);
}
}
use of org.eclipse.vorto.repository.core.impl.ModelEMFResource in project vorto by eclipse.
the class AbstractModelParser method parse.
@Override
public ModelInfo parse(InputStream is) {
XtextResourceSet resourceSet = getInjector().getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resourceSet.createResource(URI.createURI("dummy:/" + fileName));
try {
resource.load(is, resourceSet.getLoadOptions());
} catch (IOException e) {
throw new ValidationException(e.getMessage(), null);
}
List<org.eclipse.emf.ecore.resource.Resource.Diagnostic> grammarErrors = getGrammarErrors(resource.getErrors());
if (!grammarErrors.isEmpty()) {
ModelInfo invalidModelResource = new ModelInfo(parseModelIdFromFileName(), ModelType.fromFileName(fileName));
throw new ValidationException(grammarErrors.get(0).getMessage(), invalidModelResource);
}
return new ModelEMFResource((Model) resource.getContents().get(0));
}
Aggregations