Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Why alwasy get root model null when load xmi file
Why alwasy get root model null when load xmi file [message #871124] Fri, 11 May 2012 02:19 Go to next message
jy zhang is currently offline jy zhangFriend
Messages: 20
Registered: May 2012
Junior Member
Hi, everyone.
I used code below to try to load case1.xmi(attached, XMI2.1 exported by Enterprise Architect),
but I alwasy got root as null, what's the problem?

Thanks for any comment.

public class Test {
	public static void main(String[] args) throws ClassNotFoundException, IOException {		
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
				"xmi", new XMIResourceFactoryImpl());
		ResourceSet resourceSet = new ResourceSetImpl();		
		resourceSet.getLoadOptions().put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
		URI uri = URI.createURI("case1.xmi");		
		Package root = UML2Util.load(resourceSet, uri, UMLPackage.Literals.PACKAGE);
		System.out.println(root);
	}
}
  • Attachment: case1.xmi
    (Size: 7.32KB, Downloaded 181 times)

[Updated on: Fri, 11 May 2012 02:21]

Report message to a moderator

Re: Why alwasy get root model null when load xmi file [message #871132 is a reply to message #871124] Fri, 11 May 2012 05:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Comments below.

On 11/05/2012 4:19 AM, jy zhang wrote:
> Hi, everyone.
> I used code below to try to load case1.xmi(attached),
Do you have a model/EPackage whose nsURI is corresponds to the URI
declared by xmlns:uml? This looks to be more of a UML2 question in any
case because you're going to need the UML2 model to process the contents
in some meaningful way.
> but I alwasy got root as null, what's the problem?
>
> Thanks for any comment.
>
>
> public class Test {
> public static void main(String[] args) throws ClassNotFoundException, IOException {
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
> "xmi", new XMIResourceFactoryImpl());
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getLoadOptions().put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
> URI uri = URI.createURI("case1.xmi");
> Package root = UML2Util.load(resourceSet, uri, UMLPackage.Literals.PACKAGE);
> System.out.println(root);
> }
> }
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Why alwasy get root model null when load xmi file [message #871133 is a reply to message #871132] Fri, 11 May 2012 05:35 Go to previous messageGo to next message
jy zhang is currently offline jy zhangFriend
Messages: 20
Registered: May 2012
Junior Member
Hi, Ed.

Thanks for your comment.
Sorry for put this question in unsuitable forum.
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:uml="http:||www.omg.org/spec/UML/20090901" xmlns:xmi="http:||schema.omg.org/spec/XMI/2.1">
	<xmi:Documentation exporter="Enterprise Architect" exporterVersion="6.5"/>
	<uml:Model xmi:type="uml:Model" name="EA_Model" visibility="public">
		<packagedElement xmi:type="uml:Package" xmi:id="EAPK_63EE466B_B4AF_4754_AFCB_E519053BFDD4" name="package1" visibility="public">

Above is the begining of case1.xmi, I just want to get the instance of org.eclipse.uml2.uml.Package for "EA_Model".

Any idea?
Thanks again!

Ed Merks wrote on Fri, 11 May 2012 01:14
Comments below.

On 11/05/2012 4:19 AM, jy zhang wrote:
> Hi, everyone.
> I used code below to try to load case1.xmi(attached),
Do you have a model/EPackage whose nsURI is corresponds to the URI
declared by xmlns:uml? This looks to be more of a UML2 question in any
case because you're going to need the UML2 model to process the contents
in some meaningful way.
> but I alwasy got root as null, what's the problem?

>

[Updated on: Fri, 11 May 2012 05:35]

Report message to a moderator

Re: Why alwasy get root model null when load xmi file [message #871134 is a reply to message #871133] Fri, 11 May 2012 05:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Comments below.

On 11/05/2012 7:35 AM, jy zhang wrote:
> Hi, Ed.
>
> Thanks for your comment.
> Sorry for put this question in unsuitable forum.
No problem.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xmi:XMI xmi:version="2.1"
> xmlns:uml="http:||www.omg.org|spec|UML|20090901"
> xmlns:xmi="http:||schema.omg.org/spec|XMI|2.1">
> <xmi:Documentation exporter="Enterprise Architect"
> exporterVersion="6.5"/>
> <uml:Model xmi:type="uml:Model" name="EA_Model" visibility="public">
> <packagedElement xmi:type="uml:Package"
> xmi:id="EAPK_63EE466B_B4AF_4754_AFCB_E519053BFDD4" name="package1"
> visibility="public">
>
> Above is the begining of case1.xmi, I just want to get the instance of
> org.eclipse.uml2.uml.Package for "EA_Model".
>
> Any idea?
Yes, it's a UML question. You'll need to ask folks who know about all
the subtleties of loading UML instances in all the various flavors and
model versions floating around out there because I know nothing about that.
> Thanks again!
>
> Ed Merks wrote on Fri, 11 May 2012 01:14
>> Comments below.
>>
>> On 11/05/2012 4:19 AM, jy zhang wrote:
>> > Hi, everyone.
>> > I used code below to try to load case1.xmi(attached),
>> Do you have a model/EPackage whose nsURI is corresponds to the URI
>> declared by xmlns:uml? This looks to be more of a UML2 question in
>> any case because you're going to need the UML2 model to process the
>> contents in some meaningful way.
>> > but I alwasy got root as null, what's the problem?
>>
>> >
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Why alwasy get root model null when load xmi file [message #871232 is a reply to message #871134] Fri, 11 May 2012 14:18 Go to previous messageGo to next message
jy zhang is currently offline jy zhangFriend
Messages: 20
Registered: May 2012
Junior Member
After debug, I think I found the key point:
packageRegistry and regeistry extension for factory.

No matter .uml or .xml or .xmi, it's just postfix,
if the file itself is an XMI file, it can be load by EMF correctly.
We can use code below to get root and root2.
public class Test {
	public static void main(String[] args) throws ClassNotFoundException, IOException {
		ResourceSet resourceSet = new ResourceSetImpl();
		Registry packageRegistry = resourceSet.getPackageRegistry();
		packageRegistry.put("http:||schema.omg.org/spec/XMI/2.1", UMLPackage.eINSTANCE);
		packageRegistry.put("http:||schema.omg.org/spec/UML/2.1", UMLPackage.eINSTANCE);
		Map<String, Object> extensionToFactoryMap = resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
		extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION, new XMIResourceFactoryImpl());
		extensionToFactoryMap.put("xml", new XMIResourceFactoryImpl());
		resourceSet.getLoadOptions().put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
		
		
		URI uri = URI.createURI("erModel.xml");
		Package root = UML2Util.load(resourceSet, uri, UMLPackage.Literals.PACKAGE);
		System.out.println(root);
		
		URI uri2 = URI.createURI("erModel.xmi");
		Package root2 = UML2Util.load(resourceSet, uri2, UMLPackage.Literals.PACKAGE);
		System.out.println(root2);
	}
}

Anyway, sorry for put this question in the wrong forum,
and Thanks Ed for your help ^-^
Re: Why alwasy get root model null when load xmi file [message #879482 is a reply to message #871232] Thu, 31 May 2012 09:50 Go to previous messageGo to next message
max power is currently offline max powerFriend
Messages: 9
Registered: May 2012
Junior Member
Hi!

I am facing a similar problem as jy zhang. I'd like to import an xmi file that is exported by Enterprise Architect. I used his code since it seemed to work.

But the code doesn't work for me. I get follwing exception:

java.lang.NoSuchMethodError: org.eclipse.uml2.uml.internal.impl.ElementImpl.eBasicAdapterArray()[Lorg/eclipse/emf/common/notify/Adapter;
	at org.eclipse.uml2.uml.internal.impl.ElementImpl.eNotify(ElementImpl.java:964)
	at org.eclipse.uml2.uml.internal.impl.NamedElementImpl.setName(NamedElementImpl.java:268)
	at org.eclipse.uml2.uml.internal.impl.ClassImpl.eSet(ClassImpl.java:1563)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1071)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHelperImpl.java:1154)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2643)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2702)
	at org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler.handleObjectAttribs(SAXXMIHandler.java:85)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2178)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromTypeName(XMLHandler.java:2081)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHandler.java:2016)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.createObject(XMIHandler.java:131)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1799)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1023)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:87)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1001)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:712)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:167)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:181)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:180)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1445)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1241)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:255)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:270)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
	at org.eclipse.uml2.common.util.UML2Util.load(UML2Util.java:1220)
	at de.infoasset.emf2hybridWiki.handler.SubmitHandler.importXMImodel(SubmitHandler.java:340)
	at de.infoasset.emf2hybridWiki.handler.SubmitHandler.doBusinessLogic(SubmitHandler.java:100)
	at de.infoasset.platform.handler.Handler.doDoDoBusinessLogic(Handler.java:195)
	at de.infoasset.platform.handler.Handler.doDoBusinessLogic(Handler.java:214)
	at de.infoasset.platform.handler.Handler.handleRequestGetStation(Handler.java:173)
	at de.infoasset.platform.handler.Handler.handleRequest(Handler.java:115)
	at de.infoasset.platform.handler.Handler.getResponse(Handler.java:101)
	at de.infoasset.platform.client.RequestDispatcher.handleRequest(RequestDispatcher.java:73)
	at de.infoasset.platform.server.WebServer$1.handle(WebServer.java:209)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:973)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:194)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:907)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
	at de.infoasset.platform.server.WebServer$3.handle(WebServer.java:294)
	at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:47)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
	at org.eclipse.jetty.server.Server.handle(Server.java:346)
	at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:442)
	at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:941)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:801)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:224)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:51)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:586)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:44)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
	at java.lang.Thread.run(Unknown Source)


Do you have any ideas?

Many thx in advance!
Re: Why alwasy get root model null when load xmi file [message #879491 is a reply to message #879482] Thu, 31 May 2012 09:59 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I've not seen that error before, so I don't think it's one of the normal
UML difficulties.

NoSuchMethodError suggests that you have a mismatch in your Java
classes. I would start with a couple of rebuild alls and restarts.
Problem may just go away. If not check that your installs are from the
same Eclipse release; e.g. all Indigo.

Regards

Ed Willink


On 31/05/2012 10:50, max power wrote:
> Hi!
> I am facing a similar problem as jy zhang. I'd like to import an xmi
> file that is exported by Enterprise Architect. I used his code since
> it seemed to work.
>
> But the code doesn't work for me. I get follwing exception:
>
> java.lang.NoSuchMethodError:
> org.eclipse.uml2.uml.internal.impl.ElementImpl.eBasicAdapterArray()[Lorg/eclipse/emf/common/notify/Adapter;
> at
> org.eclipse.uml2.uml.internal.impl.ElementImpl.eNotify(ElementImpl.java:964)
> at
> org.eclipse.uml2.uml.internal.impl.NamedElementImpl.setName(NamedElementImpl.java:268)
> at
> org.eclipse.uml2.uml.internal.impl.ClassImpl.eSet(ClassImpl.java:1563)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1071)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHelperImpl.java:1154)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2643)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2702)
> at
> org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler.handleObjectAttribs(SAXXMIHandler.java:85)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2178)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromTypeName(XMLHandler.java:2081)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHandler.java:2016)
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.createObject(XMIHandler.java:131)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1799)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1023)
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:87)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1001)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:712)
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:167)
> at
> org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
> Source)
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
> at
> org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
> at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:181)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:180)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1445)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1241)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:255)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:270)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
> at org.eclipse.uml2.common.util.UML2Util.load(UML2Util.java:1220)
> at
> de.infoasset.emf2hybridWiki.handler.SubmitHandler.importXMImodel(SubmitHandler.java:340)
> at
> de.infoasset.emf2hybridWiki.handler.SubmitHandler.doBusinessLogic(SubmitHandler.java:100)
> at
> de.infoasset.platform.handler.Handler.doDoDoBusinessLogic(Handler.java:195)
> at
> de.infoasset.platform.handler.Handler.doDoBusinessLogic(Handler.java:214)
> at
> de.infoasset.platform.handler.Handler.handleRequestGetStation(Handler.java:173)
> at
> de.infoasset.platform.handler.Handler.handleRequest(Handler.java:115)
> at
> de.infoasset.platform.handler.Handler.getResponse(Handler.java:101)
> at
> de.infoasset.platform.client.RequestDispatcher.handleRequest(RequestDispatcher.java:73)
> at
> de.infoasset.platform.server.WebServer$1.handle(WebServer.java:209)
> at
> org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
> at
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:973)
> at
> org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:194)
> at
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:907)
> at
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
> at
> de.infoasset.platform.server.WebServer$3.handle(WebServer.java:294)
> at
> org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:47)
> at
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
> at org.eclipse.jetty.server.Server.handle(Server.java:346)
> at
> org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:442)
> at
> org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:941)
> at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:801)
> at
> org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:224)
> at
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:51)
> at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:586)
> at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:44)
> at
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
> at
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
> at java.lang.Thread.run(Unknown Source)
>
> Do you have any ideas?
>
> Many thx in advance!
Previous Topic:[EMF Compare] Import project to Eclipse (solved)
Next Topic:Interface for generated EMF Interface
Goto Forum:
  


Current Time: Thu Apr 25 00:39:20 GMT 2024

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

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

Back to the top