Loading UML file from MagicDraw 11 [message #66034] |
Mon, 03 July 2006 11:30  |
Eclipse User |
|
|
|
Originally posted by: benjamin.mesing.informatik.uni-rostock.de
Hello,
I've tried to get loading of MagicDraw xmi files working for some time
now, however I haven't succeeded yet.
I am not really sure what I do wrong, but I do not really understand the
UML2 and EMF libraries yet. I understand that the following line
registers the UMLFactory for the .uml extension.
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
Do I have to register this factory for .xmi too? Or should I register
the XMIResourceFactoryImpl?
I have the following test file which I would like to load:
<?xml version='1.0' encoding='UTF-8'?>
<xmi:XMI xmi:version='2.1' timestamp='Mon Jun 26 11:17:36 CEST 2006'
xmlns:uml='http://schema.omg.org/spec/UML/2.0'
xmlns:xmi='http://schema.omg.org/spec/XMI/2.1'>
<uml:Model xmi:id='eee_1045467100313_135436_1' name='Data' visibility='public'>
<ownedMember xmi:type='uml:Class' xmi:id='_11_0_1_2610136_1151307651168_829099_5' name='Class1MagicDraw ' visibility='public'>
<ownedOperation xmi:type='uml:Operation' xmi:id='_11_0_1_2610136_1151307711917_114728_52' concurrency='sequential' name='helloWorld' visibility='public'/>
</ownedMember>
<ownedMember xmi:type='uml:Class' xmi:id='_11_0_1_2610136_1151307668268_345223_23' name='Class2Magic Draw' visibility='public'>
<generalization xmi:type='uml:Generalization' xmi:id='_11_0_1_2610136_1151307689897_650305_41' general='_11_0_1_2610136_1151307651168_829099_5'/>
</ownedMember>
</uml:Model>
</xmi:XMI>
The loading routine I am using looks roughly like this:
public void load(URI uri) throws TypeException
{
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xmi",
new XMIResourceFactoryImpl());
UMLPackage pkg = UMLPackage.eINSTANCE;
org.eclipse.uml2.uml.Package package_ = null;
try
{
Resource resource = RESOURCE_SET.getResource(uri, true);
package_ = (org.eclipse.uml2.uml.Package) EcoreUtil.getObjectByType(resource.getContents(),
UMLPackage.eINSTANCE.getPackage());
}
catch (WrappedException we)
{
System.err.println(we.getMessage());
System.exit(1);
}
if (package_ == null)
{
System.out.println("Parsing XMI file failed");
System.exit(1);
}
}
When using things like shown above, loading fails with the following
message:
org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with
uri 'http://schema.omg.org/spec/UML/2.0' not found.
(file:/<path>/test-magicDraw-manual-edit-small.xmi, 3, 81)
If I trim it down, and make it look more like a UML2 file by removing
the <xmi> tag and using the uml2 namespace I get a different error.
<?xml version='1.0' encoding='UTF-8'?>
<uml:Model xmi:id='eee_1045467100313_135436_1' name='Data' visibility='public'
xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML" xmi:version='2.1'>
[...]
</uml:Model>
Registering the UML2 NS_URI:
RESOURCE_SET.getPackageRegistry().put("http://schema.omg.org/spec/UML/2.0", UMLPackage.eINSTANCE);
leads to the following error:
org.eclipse.emf.ecore.xmi.IllegalValueException: Value
'org.eclipse.uml2.uml.internal.impl.ClassImpl@2e7820 (name:
Class1MagicDraw
, visibility: <unset>) (isLeaf: false, visibility: public,
isAbstract: false) (isActive: false, isAbstract: false)' is not
legal. (file:/<paths>/test-magicDraw-manual-edit-small.xmi, 6,
133)
This seems to be due to the <ownedMember> elements since changing them to
<ownedType> finally makes the file load fine:
<?xml version='1.0' encoding='UTF-8'?>
<uml:Model xmi:id='eee_1045467100313_135436_1' name='Data' visibility='public' xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML" xmi:version='2.1'>
<ownedType xmi:type='uml:Class' xmi:id='_11_0_1_2610136_1151307651168_829099_5' name='Class1MagicDraw ' visibility='public'>
<ownedOperation xmi:type='uml:Operation' xmi:id='_11_0_1_2610136_1151307711917_114728_52' concurrency='sequential' name='helloWorld' visibility='public'/>
</ownedType>
<ownedType xmi:type='uml:Class' xmi:id='_11_0_1_2610136_1151307668268_345223_23' name='Class2Magic Draw' visibility='public'>
<generalization xmi:type='uml:Generalization' xmi:id='_11_0_1_2610136_1151307689897_650305_41' general='_11_0_1_2610136_1151307651168_829099_5'/>
</ownedType>
</uml:Model>
How are things supposed to work? I am totally at a loss, so any help
would be appreciated. I could perform an XSLT, but I would rather
first understand how things work.
I am using EMF 2.2 and UML2 2.0.0
Best regards
Ben
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07034 seconds