Skip to content
Snippets Groups Projects
Commit 5c0b9d25 authored by Johannes Eder's avatar Johannes Eder
Browse files

new utility method

parent 91788241
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,7 @@ import org.fortiss.tooling.kernel.ToolingKernelActivator;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 05A7E1EF00860F1627C27B2E7E6675A9
* @ConQAT.Rating YELLOW Hash: 56BD3983999FF36819DDEDE7854E36EF
*/
public final class EMFResourceUtils {
/**
......@@ -112,6 +112,41 @@ public final class EMFResourceUtils {
return null;
}
/**
* Loads the root model element from the given {@link URI}. Logs errors to the console and
* returns <code>null</code>.
*
* @param uri
* the resource {@link URI}.
* @param topLevelClass
* the type of the top level class to be returned
* @return the root {@link EObject} of class type topLevelClass (first root which is found of
* this type is returned)
*/
public static Pair<EObject, Map<EObject, AnyType>> loadModelFromFileWithUnknownFeatures(
URI uri, Class<?> topLevelClass) {
try {
ResourceSet rset = new ResourceSetImpl();
Resource r;
r = rset.createResource(uri);
r.load(EMFResourceUtils.buildOptionsMap());
Map<EObject, AnyType> unknownFeatures =
r instanceof XMIResource ? ((XMIResource)r).getEObjectToExtensionMap()
: new HashMap<EObject, AnyType>();
if(!r.getContents().isEmpty()) {
for(EObject content : r.getContents()) {
if(topLevelClass.isAssignableFrom(content.getClass()))
return new Pair<EObject, Map<EObject, AnyType>>(content, unknownFeatures);
}
}
} catch(IOException ex) {
error(ToolingKernelActivator.getDefault(),
"Failed to load model from " + uri.toString(), ex);
}
return null;
}
/**
* Loads the root model element from the given {@link URI}. Logs errors to the console and
* returns <code>null</code>.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment