Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Load EMF model instance from XMI file
Load EMF model instance from XMI file [message #1474463] Sat, 15 November 2014 12:43 Go to next message
furkan tanriverdi is currently offline furkan tanriverdiFriend
Messages: 15
Registered: November 2014
Junior Member
I know there are several QnA about this subject. I have tried lots of solution, I am always getting same error. What I want to do is in my project to read elements and try to find EAttributes and their values, which EClass they belong. EReferences also.

Can you plesea show me a way and a method to traverse xmi file ?

My code structure is like:

Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
    Map<String, Object> m = reg.getExtensionToFactoryMap();
    m.put("xmi", new XMIResourceFactoryImpl());

    ResourceSet resSet = new ResourceSetImpl();
    Resource resource = resSet.getResource(URI.createURI("model/List.xmi"), true);
    resource.load(Collections.EMPTY_MAP);
    EObject root = resource.getContents().get(0);

Error:

Quote:
Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'List' not found. (file:///C:/Users/2/My%20Repository/UNIT%20Research%20and%20Development/com.unitbilisim.research.transformation/model/List.xmi, 6, 40) at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319) at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278) at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406) at com.unitbilisim.research.transformation.ConvertEcore2Graph.main(ConvertEcore2Graph.java:61) Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'List' not found. (file:///C:/Users/2/My%20Repository/UNIT%20Research%20and%20Development/com.unitbilisim.research.transformation/model/List.xmi, 6, 40) at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:2625) at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:2458) at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1335) at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504) at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1026) at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:77) at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008) at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719) at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:163) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source) at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175) at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:261) at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518) at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297) at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259) at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274) ... 2 more


What does 'package with uri "" not found' mean ? Can I read xmi file directly or do I need to parse it as xml file ?

I have also tried this:

    XMIResource resource = new XMIResourceImpl(URI.createURI("model/List.xmi"));
    resource.load(null);
    System.out.println( resource.getContents().get(0) );
PackageNotFoundEx. and Reource$IOWrappedEx. again :(


Please help

kind regards
Re: Load EMF model instance from XMI file [message #1474570 is a reply to message #1474463] Sat, 15 November 2014 14:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Furkan,

Comments below.

On 15/11/2014 2:21 PM, furkan tanrıverdi wrote:
> I know there are several QnA about this subject. I have tried lots of
> solution, I am always getting same error. What I want to do is in my
> project to read elements and try to find EAttributes and their values,
> which EClass they belong. EReferences also.
> Can you plesea show me a way and a method to traverse xmi file ?
>
> My code structure is like:
>
> Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
> Map<String, Object> m = reg.getExtensionToFactoryMap();
> m.put("xmi", new XMIResourceFactoryImpl());
>
> ResourceSet resSet = new ResourceSetImpl();
> Resource resource =
> resSet.getResource(URI.createURI("model/List.xmi"), true);
> resource.load(Collections.EMPTY_MAP);
> EObject root = resource.getContents().get(0);
You're trying to do this stand alone? Invoke the Generate Test Code and
look for XyzExample.java in the *.tests project.
> Error:
>
> Quote:
>> Exception in thread "main"
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
>> org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri
>> 'List' not found.
>> (file:///C:/Users/2/My%20Repository/UNIT%20Research%20and%20Development/com.unitbilisim.research.transformation/model/List.xmi,
>> 6, 40) at
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
>> at
>> com.unitbilisim.research.transformation.ConvertEcore2Graph.main(ConvertEcore2Graph.java:61)
>> Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException:
>> Package with uri 'List' not found.
>> (file:///C:/Users/2/My%20Repository/UNIT%20Research%20and%20Development/com.unitbilisim.research.transformation/model/List.xmi,
>> 6, 40) at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:2625)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:2458)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1335)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1026)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:77)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:163)
>> at
>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
>> Source) at
>> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown
>> Source) at
>> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:261)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
>> ... 2 more
>
>
> What does 'package with uri "" not found' mean ?
That means your xmi file is expecting there to be a registered model,
i.e., an EPackage with that value as the nsURI.
> Can I read xmi file directly or do I need to parse it as xml file ?
XMI is XML. To make any sense of it, you'd need the registered model as
you parse it.
>
> I have also tried this:
>
> XMIResource resource = new
> XMIResourceImpl(URI.createURI("model/List.xmi"));
Where did this XMI come from? Note that I've always telling people not
to use a relative URI to load a resource.
> resource.load(null);
> System.out.println( resource.getContents().get(0) );
> PackageNotFoundEx. and Reource$IOWrappedEx. again :(
>
> Please help
>
> kind regards


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Load EMF model instance from XMI file [message #1474696 is a reply to message #1474570] Sat, 15 November 2014 17:06 Go to previous messageGo to next message
furkan tanriverdi is currently offline furkan tanriverdiFriend
Messages: 15
Registered: November 2014
Junior Member
I generated it as dynamic instance from ecore model. It's in my model folder with *.ecore file.

So, what do you suggest load ?

Sorry for my lack of knowledge but I have been working with EMF just for 2 or 3 weeks Sad

Re: Load EMF model instance from XMI file [message #1474710 is a reply to message #1474696] Sat, 15 November 2014 17:20 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
What kind of environment are you wanting to run in? Just stand alone,
or are you building an Eclipse application? What's you goal? In any
case, try generating a model and looking at the example. That will
answer many of your questions...


On 15/11/2014 6:06 PM, furkan tanrıverdi wrote:
> I generated it as dynamic instance from ecore model. It's in my model
> folder with *.ecore file.
> So, what do you suggest load ?
> Sorry for my lack of knowledge but I have been working with EMF just
> for 2 or 3 weeks :(
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:MissingResourceException for own messages in the validator
Next Topic:Load EMF instance model from xmi file and traverse it
Goto Forum:
  


Current Time: Tue Apr 23 14:34:53 GMT 2024

Powered by FUDForum. Page generated in 0.03300 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top