XMI Import [message #474563] |
Tue, 08 July 2008 09:20 |
Michael Messages: 43 Registered: July 2009 |
Member |
|
|
Hi,
IŽve a Problem with my XMI import. The following code snipped shows, how
my Import should work:
public static Resource loadXMI(String extension, String path){
//Initialize the UMLMetaModel package
UMLPackageImpl.init();
//create resource set and resource
ResourceSet resourceSet = new ResourceSetImpl();
//Register XML resource factory
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(extension,
new XMIResourceFactoryImpl());
//Create a resource
Resource resource = resourceSet.createResource(URI.createFileURI(path));
//Load the resource
try{
resource.load(null);
}catch (IOException e) {
e.printStackTrace();
}
return resource;
}
This import routine works with the following XMI-file:
<?xml version="1.0" encoding="ASCII"?>
<uml:Package xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML" name="familyTreePackage">
<packagedElement xsi:type="uml:Class" name="Individual"
isAbstract="true">
<ownedAttribute name="vorname" visibility="private"/>
<ownedAttribute name="nachname"/>
<ownedOperation name="getName"/>
</packagedElement>
<packagedElement xsi:type="uml:Class" name="Male"/>
</uml:Package>
BUT when I try to import another XMI-File (which comes out of my
UML-tool), a exception is thrown:
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package with
uri 'null' not found.
(file:/D:/Strobel_Michael/Java/workspace_diploma/export.xmi, 3, 17)
at
org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLL oadImpl.java:81)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:189)
at
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1354)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1155)
at xmi.Import.loadAmeosXMI(Import.java:32)
at xmi.StartXmiImport.main(StartXmiImport.java:17)
Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package
with uri 'null' not found.
(file:/D:/Strobel_Michael/Java/workspace_diploma/export.xmi, 3, 17)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1247)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1336)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:970)
at
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:87)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:953)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:684)
at
org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:167)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDispatcher.dispatch(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:179)
... 5 more
The XMI-File looks like this:
<?xml version="1.0" encoding= "ISO-8859-1"?>
<XMI xmi.version="1.1" xmlns:UML='org.omg.xmi.namespace.UML'>
<XMI.header>
<XMI.metamodel xmi.name="UML" xmi.version="1.4"/>
</XMI.header>
<XMI.content>
<UML:Model>
<UML:Namespace.ownedElement>
<UML:Class
xmi.id='UID_5098CBE8-3903-4530-A0BA-20B99298C6CD'
xmi.uuid='UID_5098CBE8-3903-4530-A0BA-20B99298C6CD'
name='Klasse2'
visibility='public'
isAbstract='false'
isRoot='true'
isLeaf='true'
isActive='false'
>
<UML:Classifier.feature>
<UML:Attribute
xmi.id='UID_3D5DA53B-9677-4fc6-929B-77AF1A481E6C'
xmi.uuid='UID_3D5DA53B-9677-4fc6-929B-77AF1A481E6C'
name='Attr2'
visibility='private'
comment=''
ownerScope='instance'
>
<UML:StructuralFeature.multiplicity>
<UML:Multiplicity>
<UML:Multiplicity.range>
<UML:MultiplicityRange lower='1'
upper='1'/>
</UML:Multiplicity.range>
</UML:Multiplicity>
</UML:StructuralFeature.multiplicity>
</UML:Attribute>
</UML:Classifier.feature>
</UML:Class>
<UML:Class
xmi.id='UID_A85A853F-7BA6-4f75-BC97-B2E197E7162B'
xmi.uuid='UID_A85A853F-7BA6-4f75-BC97-B2E197E7162B'
name='Klasse1'
visibility='public'
isAbstract='false'
isRoot='true'
isLeaf='true'
isActive='false'
>
<UML:Classifier.feature>
<UML:Attribute
xmi.id='UID_E475B9C9-E9A5-4af4-A3B3-E4966B60FE8E'
xmi.uuid='UID_E475B9C9-E9A5-4af4-A3B3-E4966B60FE8E'
name='Attr1'
visibility='private'
comment=''
ownerScope='instance'
>
<UML:StructuralFeature.multiplicity>
<UML:Multiplicity>
<UML:Multiplicity.range>
<UML:MultiplicityRange lower='1'
upper='1'/>
</UML:Multiplicity.range>
</UML:Multiplicity>
</UML:StructuralFeature.multiplicity>
</UML:Attribute>
</UML:Classifier.feature>
</UML:Class>
<UML:Class
xmi.id='ID_DUMMY_CLASS'
name='Container_class_for_objects_and_actors'
visibility='public'
isRoot='true'
isLeaf='true'
isActive='true'
/>
</UML:Namespace.ownedElement>
</UML:Model>
</XMI.content>
</XMI>
Sorry for the huge amount of code....! :)
Can anybody please help me??
Regards
Michael
|
|
|
Re: XMI Import [message #474564 is a reply to message #474563] |
Tue, 08 July 2008 12:20 |
Ed Merks Messages: 33146 Registered: July 2009 |
Senior Member |
|
|
Michael,
Comments below.
Michael wrote:
> Hi,
>
> IŽve a Problem with my XMI import. The following code snipped shows,
> how my Import should work:
>
> public static Resource loadXMI(String extension, String path){
> //Initialize the UMLMetaModel package
> UMLPackageImpl.init();
>
> //create resource set and resource
> ResourceSet resourceSet = new ResourceSetImpl();
>
> //Register XML resource factory
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(extension,
>
> new XMIResourceFactoryImpl());
> //Create a resource
> Resource resource =
> resourceSet.createResource(URI.createFileURI(path));
> //Load the resource
> try{
> resource.load(null);
> }catch (IOException e) {
> e.printStackTrace();
> } return resource;
> }
>
> This import routine works with the following XMI-file:
>
> <?xml version="1.0" encoding="ASCII"?>
> <uml:Package xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML"
> name="familyTreePackage">
> <packagedElement xsi:type="uml:Class" name="Individual"
> isAbstract="true">
> <ownedAttribute name="vorname" visibility="private"/>
> <ownedAttribute name="nachname"/>
> <ownedOperation name="getName"/>
> </packagedElement>
> <packagedElement xsi:type="uml:Class" name="Male"/>
> </uml:Package>
>
> BUT when I try to import another XMI-File (which comes out of my
> UML-tool), a exception is thrown:
>
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package
> with uri 'null' not found.
> (file:/D:/Strobel_Michael/Java/workspace_diploma/export.xmi, 3, 17)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLL oadImpl.java:81)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:189)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1354)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1155)
>
> at xmi.Import.loadAmeosXMI(Import.java:32)
> at xmi.StartXmiImport.main(StartXmiImport.java:17)
> Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package
> with uri 'null' not found.
> (file:/D:/Strobel_Michael/Java/workspace_diploma/export.xmi, 3, 17)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1247)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1336)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:970)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:87)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:953)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:684)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:167)
>
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDispatcher.dispatch(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
> Source)
> at javax.xml.parsers.SAXParser.parse(Unknown Source)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:179)
> ... 5 more
>
> The XMI-File looks like this:
>
> <?xml version="1.0" encoding= "ISO-8859-1"?>
> <XMI xmi.version="1.1" xmlns:UML='org.omg.xmi.namespace.UML'>
> <XMI.header>
> <XMI.metamodel xmi.name="UML" xmi.version="1.4"/>
> </XMI.header>
You're not going to be able to read UML 1.4 instances nor can EMF
consume XMI 1.x in general.
> <XMI.content>
> <UML:Model>
> <UML:Namespace.ownedElement>
> <UML:Class
> xmi.id='UID_5098CBE8-3903-4530-A0BA-20B99298C6CD'
> xmi.uuid='UID_5098CBE8-3903-4530-A0BA-20B99298C6CD'
> name='Klasse2'
> visibility='public'
> isAbstract='false'
> isRoot='true'
> isLeaf='true'
> isActive='false'
> >
> <UML:Classifier.feature>
> <UML:Attribute
>
> xmi.id='UID_3D5DA53B-9677-4fc6-929B-77AF1A481E6C'
>
> xmi.uuid='UID_3D5DA53B-9677-4fc6-929B-77AF1A481E6C'
> name='Attr2'
> visibility='private'
> comment=''
> ownerScope='instance'
> >
> <UML:StructuralFeature.multiplicity>
> <UML:Multiplicity>
> <UML:Multiplicity.range>
> <UML:MultiplicityRange
> lower='1' upper='1'/>
> </UML:Multiplicity.range>
> </UML:Multiplicity>
> </UML:StructuralFeature.multiplicity>
> </UML:Attribute>
> </UML:Classifier.feature>
> </UML:Class>
> <UML:Class
> xmi.id='UID_A85A853F-7BA6-4f75-BC97-B2E197E7162B'
> xmi.uuid='UID_A85A853F-7BA6-4f75-BC97-B2E197E7162B'
> name='Klasse1'
> visibility='public'
> isAbstract='false'
> isRoot='true'
> isLeaf='true'
> isActive='false'
> >
> <UML:Classifier.feature>
> <UML:Attribute
>
> xmi.id='UID_E475B9C9-E9A5-4af4-A3B3-E4966B60FE8E'
>
> xmi.uuid='UID_E475B9C9-E9A5-4af4-A3B3-E4966B60FE8E'
> name='Attr1'
> visibility='private'
> comment=''
> ownerScope='instance'
> >
> <UML:StructuralFeature.multiplicity>
> <UML:Multiplicity>
> <UML:Multiplicity.range>
> <UML:MultiplicityRange
> lower='1' upper='1'/>
> </UML:Multiplicity.range>
> </UML:Multiplicity>
> </UML:StructuralFeature.multiplicity>
> </UML:Attribute>
> </UML:Classifier.feature>
> </UML:Class>
> <UML:Class xmi.id='ID_DUMMY_CLASS'
> name='Container_class_for_objects_and_actors'
> visibility='public'
> isRoot='true' isLeaf='true'
> isActive='true'
> />
> </UML:Namespace.ownedElement>
> </UML:Model>
> </XMI.content>
> </XMI>
>
> Sorry for the huge amount of code....! :)
> Can anybody please help me??
You'll only generally be able to read XMI 2.0 serializations and even
then, the serialization must conform some existing Ecore model, i.e, for
UML it better be some version of UML 2.x...
>
> Regards Michael
>
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: XMI Import [message #620476 is a reply to message #474563] |
Tue, 08 July 2008 12:20 |
Ed Merks Messages: 33146 Registered: July 2009 |
Senior Member |
|
|
Michael,
Comments below.
Michael wrote:
> Hi,
>
> IŽve a Problem with my XMI import. The following code snipped shows,
> how my Import should work:
>
> public static Resource loadXMI(String extension, String path){
> //Initialize the UMLMetaModel package
> UMLPackageImpl.init();
>
> //create resource set and resource
> ResourceSet resourceSet = new ResourceSetImpl();
>
> //Register XML resource factory
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(extension,
>
> new XMIResourceFactoryImpl());
> //Create a resource
> Resource resource =
> resourceSet.createResource(URI.createFileURI(path));
> //Load the resource
> try{
> resource.load(null);
> }catch (IOException e) {
> e.printStackTrace();
> } return resource;
> }
>
> This import routine works with the following XMI-file:
>
> <?xml version="1.0" encoding="ASCII"?>
> <uml:Package xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML"
> name="familyTreePackage">
> <packagedElement xsi:type="uml:Class" name="Individual"
> isAbstract="true">
> <ownedAttribute name="vorname" visibility="private"/>
> <ownedAttribute name="nachname"/>
> <ownedOperation name="getName"/>
> </packagedElement>
> <packagedElement xsi:type="uml:Class" name="Male"/>
> </uml:Package>
>
> BUT when I try to import another XMI-File (which comes out of my
> UML-tool), a exception is thrown:
>
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package
> with uri 'null' not found.
> (file:/D:/Strobel_Michael/Java/workspace_diploma/export.xmi, 3, 17)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLL oadImpl.java:81)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:189)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1354)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1155)
>
> at xmi.Import.loadAmeosXMI(Import.java:32)
> at xmi.StartXmiImport.main(StartXmiImport.java:17)
> Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package
> with uri 'null' not found.
> (file:/D:/Strobel_Michael/Java/workspace_diploma/export.xmi, 3, 17)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1247)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1336)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:970)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:87)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:953)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:684)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:167)
>
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDispatcher.dispatch(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
> Source)
> at javax.xml.parsers.SAXParser.parse(Unknown Source)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:179)
> ... 5 more
>
> The XMI-File looks like this:
>
> <?xml version="1.0" encoding= "ISO-8859-1"?>
> <XMI xmi.version="1.1" xmlns:UML='org.omg.xmi.namespace.UML'>
> <XMI.header>
> <XMI.metamodel xmi.name="UML" xmi.version="1.4"/>
> </XMI.header>
You're not going to be able to read UML 1.4 instances nor can EMF
consume XMI 1.x in general.
> <XMI.content>
> <UML:Model>
> <UML:Namespace.ownedElement>
> <UML:Class
> xmi.id='UID_5098CBE8-3903-4530-A0BA-20B99298C6CD'
> xmi.uuid='UID_5098CBE8-3903-4530-A0BA-20B99298C6CD'
> name='Klasse2'
> visibility='public'
> isAbstract='false'
> isRoot='true'
> isLeaf='true'
> isActive='false'
> >
> <UML:Classifier.feature>
> <UML:Attribute
>
> xmi.id='UID_3D5DA53B-9677-4fc6-929B-77AF1A481E6C'
>
> xmi.uuid='UID_3D5DA53B-9677-4fc6-929B-77AF1A481E6C'
> name='Attr2'
> visibility='private'
> comment=''
> ownerScope='instance'
> >
> <UML:StructuralFeature.multiplicity>
> <UML:Multiplicity>
> <UML:Multiplicity.range>
> <UML:MultiplicityRange
> lower='1' upper='1'/>
> </UML:Multiplicity.range>
> </UML:Multiplicity>
> </UML:StructuralFeature.multiplicity>
> </UML:Attribute>
> </UML:Classifier.feature>
> </UML:Class>
> <UML:Class
> xmi.id='UID_A85A853F-7BA6-4f75-BC97-B2E197E7162B'
> xmi.uuid='UID_A85A853F-7BA6-4f75-BC97-B2E197E7162B'
> name='Klasse1'
> visibility='public'
> isAbstract='false'
> isRoot='true'
> isLeaf='true'
> isActive='false'
> >
> <UML:Classifier.feature>
> <UML:Attribute
>
> xmi.id='UID_E475B9C9-E9A5-4af4-A3B3-E4966B60FE8E'
>
> xmi.uuid='UID_E475B9C9-E9A5-4af4-A3B3-E4966B60FE8E'
> name='Attr1'
> visibility='private'
> comment=''
> ownerScope='instance'
> >
> <UML:StructuralFeature.multiplicity>
> <UML:Multiplicity>
> <UML:Multiplicity.range>
> <UML:MultiplicityRange
> lower='1' upper='1'/>
> </UML:Multiplicity.range>
> </UML:Multiplicity>
> </UML:StructuralFeature.multiplicity>
> </UML:Attribute>
> </UML:Classifier.feature>
> </UML:Class>
> <UML:Class xmi.id='ID_DUMMY_CLASS'
> name='Container_class_for_objects_and_actors'
> visibility='public'
> isRoot='true' isLeaf='true'
> isActive='true'
> />
> </UML:Namespace.ownedElement>
> </UML:Model>
> </XMI.content>
> </XMI>
>
> Sorry for the huge amount of code....! :)
> Can anybody please help me??
You'll only generally be able to read XMI 2.0 serializations and even
then, the serialization must conform some existing Ecore model, i.e, for
UML it better be some version of UML 2.x...
>
> Regards Michael
>
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04006 seconds