import XMI per Input Stream [message #759245] |
Mon, 28 November 2011 02:43 |
Alex Miranski Messages: 2 Registered: November 2011 |
Junior Member |
|
|
Hey Guys,
I'm trying to build a EMF-Ecore-Model from a XMI-File. Not a big Thing, but the File is only available as ByteArray. Im using Maven for building with Emf v2.6.0 . Some googleing gave me the following lines of Code.
public Package importModel(final byte[] modelData) {
Package model = null;
EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
try {
final ByteArrayInputStream bais = new ByteArrayInputStream(modelData);
Resource resource = new XMIResourceImpl();
// Create XMLMap, used for proper XML mapping. This is an empty Map,
// it is using generated annotations for proper streaming
XMIResource.XMLMap xmlMap = new XMLMapImpl();
// Create options map for loading
Map options = new HashMap();
// Populate options
options.put(XMIResource.OPTION_XML_MAP, xmlMap);
try {
resource.load(bais, options);
} catch (Exception e) {
e.printStackTrace();
}
But the resource.load(); throws "org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package with uri 'http: //www.eclipse.org/uml2/2.1.0/UML' not found." (added space so its not a link). There are a lot of Threads around the Internet, but mostly the two lines before the try block solves the Problem for them. But i dont want to write the data to harddisk, just to get an URI and load it again. So there is no "Extension" that the factory map can use.
Any suggestions? I'm thankful for every Advise.
Greetz
|
|
|
Re: import XMI per Input Stream [message #759261 is a reply to message #759245] |
Mon, 28 November 2011 07:00 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
You're running standalone so you have to manually provide all the
relevant registrations that Eclipse plugins provide automatically.
"Package with uri 'xxx' not found." means that neither your
ResourceSet.getPackageRegistry() no the global package registry has a
registration for "xxx".
The UML2 project appears not to provide a standalone init routine to
make this easy.
You may find it sufficient to just do UMLPackage.eINSTANCE.getClass().
Otherwise you may find org.eclipse.ocl.uml.OCL.initialize(ResourceSet)
helpful.
Regards
Ed Willink
On 28/11/2011 02:43, bloodyworld.emf wrote:
> Hey Guys,
>
> I'm trying to build a EMF-Ecore-Model from a XMI-File. Not a big
> Thing, but the File is only available as ByteArray. Im using Maven for
> building with Emf v2.6.0 . Some googleing gave me the following lines
> of Code.
>
> public Package importModel(final byte[] modelData) {
> Package model = null;
>
> EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
>
> try {
> final ByteArrayInputStream bais = new
> ByteArrayInputStream(modelData);
> Resource resource = new XMIResourceImpl();
>
> // Create XMLMap, used for proper XML mapping. This is an
> empty Map,
> // it is using generated annotations for proper streaming
> XMIResource.XMLMap xmlMap = new XMLMapImpl();
>
> // Create options map for loading
> Map options = new HashMap();
>
> // Populate options
> options.put(XMIResource.OPTION_XML_MAP, xmlMap);
>
> try {
> resource.load(bais, options);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
>
>
> But the resource.load(); throws
> "org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package
> with uri 'http: //www.eclipse.org/uml2/2.1.0/UML' not found." (added
> space so its not a link). There are a lot of Threads around the
> Internet, but mostly the two lines before the try block solves the
> Problem for them. But i dont want to write the data to harddisk, just
> to get an URI and load it again. So there is no "Extension" that the
> factory map can use.
>
> Any suggestions? I'm thankful for every Advise.
>
>
> Greetz
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03901 seconds