Why alwasy get root model null when load xmi file [message #871124] |
Fri, 11 May 2012 02:19 |
jy zhang 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 |
Ed Merks 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 |
jy zhang 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:14Comments 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 |
Ed Merks 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 |
jy zhang 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 ^-^
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03553 seconds