Hello,
I have a question regarding loading an EMF model from a stream.
I have two functions:
public static EObject load(File file) throws IOException {
ResourceSet resSet = new ResourceSetImpl();
Map<String, Object> loadMap = configure(resSet);
URI fileUri = URI.createFileURI(file.getAbsolutePath());
Resource res = resSet.getResource(fileUri, true);
res.load(loadMap);
return res.getContents().get(0);
}
private static Map<String, Object> configure(ResourceSet resSet) throws IOException {
Map<String, Object> parserFeatures = new HashMap<String, Object>();
Map<String, Object> parserProperties = new LinkedHashMap<String, Object>();
Map<String, Object> loadMap = new HashMap<String, Object>();
loadMap.put(XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl());
loadMap.put(XMLResource.OPTION_EXTENDED_META_DATA, ExtendedMetaData.INSTANCE);
parserFeatures.put("htp://xml.org/sax/features/validation", Boolean.TRUE);
URL find = FileLocator.find(Activator.getContext().getBundle(), new Path("model/pack.xsd"), null);
parserProperties.put("htp://java.sun.com/xml/jaxp/properties/schemaLanguage", "htp://www.w3.org/2001/XMLSchema");
InputStream schemaStream = find.openStream();
parserProperties.put("htp://java.sun.com/xml/jaxp/properties/schemaSource", schemaStream);
resSet.getLoadOptions().put(XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl());
resSet.getLoadOptions().put(XMLResource.OPTION_PARSER_FEATURES, parserFeatures);
resSet.getLoadOptions().put(XMLResource.OPTION_PARSER_PROPERTIES, parserProperties);
resSet.getPackageRegistry().put(PackPackage.eINSTANCE.getNsURI(), PackPackage.eINSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("pack", new PackResourceFactoryImpl());
return loadMap;
}
which are working fine.
When it comes to load the model from a stream, I get into trouble ...
public static EObject load(InputStream inStream) throws IOException {
ResourceSet resSet = new ResourceSetImpl();
Map<String, Object> loadMap = configure(resSet);
Resource res = resSet.createResource(URI.createURI("htp:///My.pack"), "pack");
res.load(inStream, loadMap);
return res.getContents().get(0);
}
I get this error: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'null' not found. (htp:///My.pack, 2, 7)
If I remove this line:
loadMap.put(XMLResource.OPTION_EXTENDED_META_DATA, ExtendedMetaData.INSTANCE);
it works with streams also. However, the documentation says to use this setting for models created from a schema. So what is going wrong? Any idea?
Thanks in advance
Frank
(I had to use htp instead of http since I am not allowed to post links yet ...)