diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EMFResourceUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EMFResourceUtils.java index 851a593c9b7692c10c655addb3895805fb8aad46..9a48cd81ebb1d5aebd58af6998c8399159994894 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EMFResourceUtils.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EMFResourceUtils.java @@ -25,8 +25,10 @@ import org.eclipse.core.resources.IFile; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.xmi.XMLResource; +import org.fortiss.tooling.kernel.ToolingKernelActivator; /** * Utility methods used for Eclipse resource storage. @@ -58,4 +60,19 @@ public final class EMFResourceUtils { options.put(Resource.OPTION_ZIP, false); return options; } + + /** Loads the root EObject from the given URI. */ + public static EObject loadModelFromFile(URI resourceURI) { + try { + ResourceSet rset = new ResourceSetImpl(); + Resource r; + r = rset.createResource(resourceURI); + r.load(EMFResourceUtils.buildOptionsMap()); + return r.getContents().get(0); + } catch (IOException ex) { + LoggingUtils.error(ToolingKernelActivator.getDefault(), + "Failed to load model from " + resourceURI.toString()); + } + return null; + } }