Skip to content

Instantly share code, notes, and snippets.

@nbhusare
Last active August 16, 2017 09:58
Show Gist options
  • Save nbhusare/f27e1e6043863b3bb0d1dbb498f6c89e to your computer and use it in GitHub Desktop.
Save nbhusare/f27e1e6043863b3bb0d1dbb498f6c89e to your computer and use it in GitHub Desktop.
Safe way of adding resource to the resource set
// Get the URI to the resource
final URI uri = resource.getURI();
// Get the resource resolved by the URI. Do not load the resource, only get one if exists
final Resource r = resourceSet.getResource(uri, false);
if (r != null) {
// Add the resource to the resourceset
resourceSet.getResources().add(resource);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment