Skip to content

Commit

Permalink
fix another NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
melaasar committed Aug 13, 2024
1 parent 3c3df0f commit ff326c2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ public EList<Element> getValues() {
if (_not_1) {
_xifexpression_1 = ECollections.<Element>unmodifiableEList(this.getReferencedValues());
}
else {
return ECollections.<Element>emptyEList();
}
_xifexpression = _xifexpression_1;
}
return _xifexpression;
Expand Down
2 changes: 2 additions & 0 deletions io.opencaesar.oml/src/io/opencaesar/oml/Oml.xcore
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class Annotation extends Element {
literalValues.unmodifiableEList
else if (!referencedValues.empty)
referencedValues.unmodifiableEList
else
return ECollections.emptyEList
}
/*
* Gets the first value of the annotation
Expand Down
54 changes: 28 additions & 26 deletions io.opencaesar.oml/src/io/opencaesar/oml/util/OmlUriResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ private boolean exists(URI uri) {
return uriConverter.exists(uri, null);
}

/**
* Resolves the given logical IRI in context of the given resource
*
* @param contextResource The resource that is the context of resolution
* @param iri The logical IRI to resolve
* @return The resolved physical URI
*/
public synchronized URI resolveUri(Resource contextResource, String iri) {
URI resolvedUri = resolveUri(contextResource.getURI(), iri);

if (resolvedUri == null) {
resolvedUri = resolveFromResourceSet(contextResource.getResourceSet(), iri);
}

return resolvedUri;
}

/**
* Resolves the given logical IRI in context of the given physical URI
*
Expand Down Expand Up @@ -162,31 +179,6 @@ public synchronized URI resolveUri(URI contextFileURI, String iri) {
return resolvedUri;
}

/**
* Resolves the given logical IRI in context of the given resource
*
* @param contextResource The resource that is the context of resolution
* @param iri The logical IRI to resolve
* @return The resolved physical URI
*/
public synchronized URI resolveUri(Resource contextResource, String iri) {
URI resolvedUri = resolveUri(contextResource.getURI(), iri);

if (resolvedUri == null) {
ResourceSet rs = contextResource.getResourceSet();
if (rs.getLoadOptions().get(OmlConstants.RESOLVE_IRI_USING_RESOURCE_SET) == Boolean.TRUE) {
resolvedUri = resolveFromResourceSet(rs, iri);
}
}

return resolvedUri;
}

private URI resolveFromResourceSet(ResourceSet rs, String iri) {
Ontology ontology = OmlRead.getOntologyByIri(rs, iri);
return (ontology != null) ? ontology.eResource().getURI() : null;
}

private URI resolveFromCatalog(URI folderUri, String iri) {
OmlCatalog catalog = findCatalog(folderUri);
if (catalog == null) {
Expand Down Expand Up @@ -214,7 +206,17 @@ private URI resolveFromCatalog(URI folderUri, String iri) {
return exists(resolved) ? resolved : null;
}

public synchronized Set<URI> getResolvedUris(Resource contextResource) {
private URI resolveFromResourceSet(ResourceSet rs, String iri) {
if (rs.getLoadOptions().get(OmlConstants.RESOLVE_IRI_USING_RESOURCE_SET) == Boolean.TRUE) {
Ontology ontology = OmlRead.getOntologyByIri(rs, iri);
if (ontology != null) {
return ontology.eResource().getURI();
}
}
return null;
}

public synchronized Set<URI> getResolvedUris(Resource contextResource) {
if (contextResource == null) {
return Collections.emptySet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ boolean validatePropertyValueRestrictionSubject(PropertyValueAssertion object, D

if (!domains.stream().allMatch(d -> allTypes.contains(d))) {
return report(Diagnostic.WARNING, diagnostics, object,
"The subject of the assertion is not already in the domain of "+property.getAbbreviatedIri(),
"The subject of the assertion is not assereted to be in the domain(s) of "+property.getAbbreviatedIri(),
OmlPackage.Literals.PROPERTY_VALUE_ASSERTION__PROPERTY);
}
return true;
Expand Down Expand Up @@ -960,22 +960,22 @@ boolean validatePropertyValueRestrictionObject(PropertyValueAssertion object, Di
final Set<Entity> allTypes = cache.getAllTypes(instance);
if (!ranges.stream().allMatch(d -> allTypes.contains(d))) {
return report(Diagnostic.WARNING, diagnostics, object,
instance.getAbbreviatedIri()+" is not asserted to be in the range of "+property.getAbbreviatedIri(),
instance.getAbbreviatedIri()+" is not asserted to be in the range(s) of "+property.getAbbreviatedIri(),
OmlPackage.Literals.PROPERTY_VALUE_ASSERTION__REFERENCED_VALUES);
}
} else if (theObject instanceof AnonymousInstance) {
final Set<Entity> allTypes = cache.getAllTypes((Instance)theObject);
if (!ranges.stream().allMatch(d -> allTypes.contains(d))) {
return report(Diagnostic.WARNING, diagnostics, object,
"The object of the assertion is not asserted to be in the range of "+property.getAbbreviatedIri(),
"The object of the assertion is not asserted to be in the range(s) of "+property.getAbbreviatedIri(),
OmlPackage.Literals.PROPERTY_VALUE_ASSERTION__CONTAINED_VALUES);
}
} else {
Literal literal = (Literal) theObject;
final Set<Scalar> allTypes = cache.getAllTypes(literal);
if (!ranges.stream().allMatch(d -> allTypes.contains(d))) {
return report(Diagnostic.WARNING, diagnostics, object,
literal.getLexicalValue()+" is not asserted to be in the range of "+property.getAbbreviatedIri(),
literal.getLexicalValue()+" is not asserted to be in the range(s) of "+property.getAbbreviatedIri(),
OmlPackage.Literals.PROPERTY_VALUE_ASSERTION__LITERAL_VALUES);
}
}
Expand Down

0 comments on commit ff326c2

Please sign in to comment.