Home » Modeling » UML2 » How to get the root Model from XMI file exported by Enterprise Architect
How to get the root Model from XMI file exported by Enterprise Architect [message #870956] |
Thu, 10 May 2012 10:50 |
jy zhang Messages: 20 Registered: May 2012 |
Junior Member |
|
|
In my standalone programm,
I can use code below to get the root model of .uml(attached) created by UML2Tools.
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
URI uri = URI.createURI("33.uml");
Package uml2Model = UML2Util.load(RESOURCE_SET, uri, UMLPackage.Literals.PACKAGE);
But when I use code below to try to get the root model of .xml(attached) exported by Enterprise Architect, i failed.
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"xml", UMLResource.Factory.INSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
URI uri = URI.createURI("erModel.xml");
RESOURCE_SET.getLoadOptions().put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
Package uml2Model = UML2Util.load(RESOURCE_SET, uri, UMLPackage.Literals.MODEL);
XMIResourceFactoryImpl xmiResFactory = new XMIResourceFactoryImpl();
Resource res = xmiResFactory.createResource(uri);
res.load(RESOURCE_SET.getLoadOptions());
EList<EObject> contents = res.getContents();
I got uml2Model as null, and contents contains all AnyTypeImpl.
How can I get the root model correctly?
Thanks a lot!
-
Attachment: erModel.xml
(Size: 8.31KB, Downloaded 272 times) -
Attachment: 33.uml
(Size: 1.53KB, Downloaded 213 times)
[Updated on: Thu, 10 May 2012 10:52] Report message to a moderator
|
|
|
Re: How to get the root Model from XMI file exported by Enterprise Architect [message #870973 is a reply to message #870956] |
Thu, 10 May 2012 12:07 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
The *.uml extension is for Eclipse UML dialects
The *.xmi is for OMG dialects.
Try using *.xmi, since you appear to have a regular OMG file.
Regards
Ed Willink
On 10/05/2012 11:50, jy zhang wrote:
> In my standalone programm,
> I can use code below to get the root model of .uml(attached) created by UML2Tools.
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
> URI uri = URI.createURI("33.uml");
> Package uml2Model = UML2Util.load(RESOURCE_SET, uri, UMLPackage.Literals.PACKAGE);
>
>
> But when I use code below to try to get the root model of .xml(attached) exported by Enterprise Architect, i failed.
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "xml", UMLResource.Factory.INSTANCE);
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
> URI uri = URI.createURI("erModel.xml");
> RESOURCE_SET.getLoadOptions().put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
> Package uml2Model = UML2Util.load(RESOURCE_SET, uri, UMLPackage.Literals.MODEL);
>
> XMIResourceFactoryImpl xmiResFactory = new XMIResourceFactoryImpl();
> Resource res = xmiResFactory.createResource(uri);
> res.load(RESOURCE_SET.getLoadOptions());
> EList<EObject> contents = res.getContents();
>
> I got uml2Model as null, and contents contains all AnyTypeImpl.
> How can I get the root model correctly?
>
> Thanks a lot!
>
|
|
|
Re: How to get the root Model from XMI file exported by Enterprise Architect [message #870978 is a reply to message #870973] |
Thu, 10 May 2012 12:45 |
jy zhang Messages: 20 Registered: May 2012 |
Junior Member |
|
|
Thanks Edward,
But I'm OK to load *.uml by my code, now my problem is to load *.xml.
I can NOT get the root model of *.xml exported by EA.
Thanks again!
Edward Willink wrote on Thu, 10 May 2012 08:07Hi
The *.uml extension is for Eclipse UML dialects
The *.xmi is for OMG dialects.
Try using *.xmi, since you appear to have a regular OMG file.
Regards
Ed Willink
On 10/05/2012 11:50, jy zhang wrote:
> In my standalone programm,
> I can use code below to get the root model of .uml(attached) created by UML2Tools.
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
> URI uri = URI.createURI("33.uml");
> Package uml2Model = UML2Util.load(RESOURCE_SET, uri, UMLPackage.Literals.PACKAGE);
>
>
> But when I use code below to try to get the root model of .xml(attached) exported by Enterprise Architect, i failed.
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "xml", UMLResource.Factory.INSTANCE);
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
> URI uri = URI.createURI("erModel.xml");
> RESOURCE_SET.getLoadOptions().put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
> Package uml2Model = UML2Util.load(RESOURCE_SET, uri, UMLPackage.Literals.MODEL);
>
> XMIResourceFactoryImpl xmiResFactory = new XMIResourceFactoryImpl();
> Resource res = xmiResFactory.createResource(uri);
> res.load(RESOURCE_SET.getLoadOptions());
> EList<EObject> contents = res.getContents();
>
> I got uml2Model as null, and contents contains all AnyTypeImpl.
> How can I get the root model correctly?
>
> Thanks a lot!
>
|
|
|
Re: How to get the root Model from XMI file exported by Enterprise Architect [message #870986 is a reply to message #870978] |
Thu, 10 May 2012 13:14 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
As I wrote before;' try *.xmi
Regards
Ed Willink
On 10/05/2012 13:45, jy zhang wrote:
> Thanks Edward,
>
> But I'm OK to load *.uml by my code, now my problem is to load *.xml.
> I can NOT get the root model of *.xml exported by EA.
>
> Thanks again!
>
>
> Edward Willink wrote on Thu, 10 May 2012 08:07
>> Hi
>>
>> The *.uml extension is for Eclipse UML dialects
>>
>> The *.xmi is for OMG dialects.
>>
>> Try using *.xmi, since you appear to have a regular OMG file.
>>
>> Regards
>>
>> Ed Willink
>>
>> On 10/05/2012 11:50, jy zhang wrote:
>> > In my standalone programm,
>> > I can use code below to get the root model of .uml(attached)
>> created by UML2Tools.
>> >
>> >
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
>> UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
>> > URI uri = URI.createURI("33.uml");
>> > Package uml2Model = UML2Util.load(RESOURCE_SET, uri,
>> UMLPackage.Literals.PACKAGE);
>> >
>> >
>> > But when I use code below to try to get the root model of
>> .xml(attached) exported by Enterprise Architect, i failed.
>> >
>> >
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
>> "xml", UMLResource.Factory.INSTANCE);
>> >
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
>> UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
>> > URI uri = URI.createURI("erModel.xml");
>> >
>> RESOURCE_SET.getLoadOptions().put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE,
>> Boolean.TRUE);
>> > Package uml2Model = UML2Util.load(RESOURCE_SET, uri,
>> UMLPackage.Literals.MODEL);
>> >
>> > XMIResourceFactoryImpl xmiResFactory = new XMIResourceFactoryImpl();
>> > Resource res = xmiResFactory.createResource(uri);
>> > res.load(RESOURCE_SET.getLoadOptions());
>> > EList<EObject> contents = res.getContents();
>> >
>> > I got uml2Model as null, and contents contains all AnyTypeImpl.
>> > How can I get the root model correctly?
>> >
>> > Thanks a lot!
>> >
>
>
|
|
|
Re: How to get the root Model from XMI file exported by Enterprise Architect [message #870997 is a reply to message #870986] |
Thu, 10 May 2012 13:45 |
jy zhang Messages: 20 Registered: May 2012 |
Junior Member |
|
|
Hi Edward,
But I've tried to load *.xmi exported as XMI2.1 by EA too,
the same problem as *.xml
I got 3 AnyImpl instances in contents.
Thanks a lot!
EDIT: (i'll attach erModel2.xmi and append code, root is always null)
public class Test {
public static void main(String[] args) throws ClassNotFoundException, IOException {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"xmi", UMLResource.Factory.INSTANCE);
ResourceSet resourceSet = new ResourceSetImpl();
URI uri = URI.createURI("erModel2.xmi");
resourceSet.getLoadOptions().put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
Package root = UML2Util.load(resourceSet, uri, UMLPackage.Literals.PACKAGE);
System.out.println(root);
}
}
Edward Willink wrote on Thu, 10 May 2012 09:14Hi
As I wrote before;' try *.xmi
Regards
Ed Willink
On 10/05/2012 13:45, jy zhang wrote:
> Thanks Edward,
>
> But I'm OK to load *.uml by my code, now my problem is to load *.xml.
> I can NOT get the root model of *.xml exported by EA.
>
> Thanks again!
>
-
Attachment: erModel2.xmi
(Size: 8.31KB, Downloaded 184 times)
[Updated on: Thu, 10 May 2012 14:26] Report message to a moderator
|
|
|
Re: How to get the root Model from XMI file exported by Enterprise Architect [message #871231 is a reply to message #870997] |
Fri, 11 May 2012 14:16 |
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, Thanks Edward for your help ^-^
|
|
|
Re: How to get the root Model from XMI file exported by Enterprise Architect [message #871358 is a reply to message #871231] |
Sat, 12 May 2012 10:34 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
The significance of *.xmi, is that there are contentType registrations
so that the XML file is read, the namespace is identified and the
corresponding UML version is exploited. OMG contentTypes are only
available for *.xmi MDT/IML2 dialects for *.uml.
Explicit package registrations as you have are now, as from Juno M6, in
UMLUtil.init, with the content types in UMLResourcesUtil.init().
Finally the difficulties that you and many others experience when taking
responsibility for standalone initialisation will have an easy solution.
Regards
Ed Willink
On 11/05/2012 15:16, jy zhang wrote:
> 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, Thanks Edward for your help ^-^
|
|
| |
Goto Forum:
Current Time: Wed Apr 24 23:48:29 GMT 2024
Powered by FUDForum. Page generated in 0.03901 seconds
|