Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Re: metamodel conflict while reading xmi file
Re: metamodel conflict while reading xmi file [message #625226] Wed, 17 October 2007 11:21
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Daniel,

It seems to me that the UML2 project provides a specialized resource
factory that you should be using instead. So it's best to read the UML
documentation and ask questions about problems on the UML2 newsgroup,
which I've added to the "to" list of the reply.

In general accessing XyzPackage.eINSTANCE.eClass() will register that
package in the EPackage.Registry.INSTANCE, but a resource set has a
local getPackageRegistry() and you can register things locally to hide
or augment the global registrations...


Daniel Lucredio wrote:
> Hi everybody, I've been looking for a solution for this, and I still
> found no answers, maybe you guys can help.
>
> I am developing a stand-alone application for dynamically loading
> several XMI files using EMF. Each file can refer to a different
> package - or metamodel - (ex: uml2, gmf, or my own ecore metamodel),
> through a different namespace in the xmi file. I've followed the EMF
> tutorial for doing this, and it works fine:
>
> // Initialize the resource set.
> ResourceSet resourceSet = new ResourceSetImpl();
> // Register the default resource factory -- only needed for
> stand-alone!
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(
> Resource.Factory.Registry.DEFAULT_EXTENSION, new
> XMIResourceFactoryImpl());
>
> // Register the package
> UMLPackage.eINSTANCE.eClass();
>
> URI fileURI = URI.createFileURI(file.getAbsolutePath());
>
> // Demand load the resource for this file.
> Resource resource = resourceSet.getResource(fileURI, true);
>
> However, some of my files are use two different versions of the UML
> metamodel (1.0.0 and 2.2.0). If I read them separately (two executions
> of the main method), it works. However, if I try to load them in the
> same execution (meaning that both metamodels - jar files - are loaded
> into the JVM at the same time), there seems to be some conflict, and
> an exception is thrown:
>
> org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
> 'base_Activity' not found.
> (file:/C:/eclipseWorkspace/StandaloneEMFTest/models/Sample1. uml, 667,
> 103)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.reportUnknownFeatu re(XMLHandler.java:1856)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleUnknownFeatu re(XMLHandler.java:1820)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.handleUnknownFeatu re(XMIHandler.java:149)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XML Handler.java:2570)
>
> at
> org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler.handleObjectAtt ribs(SAXXMIHandler.java:76)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFa ctory(XMLHandler.java:2058)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1270)
>
> 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.parsers.AbstractXMLDocume ntParser.emptyElement(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$FragmentContentDriver.next(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl.next(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
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSA XParser.parse(Unknown
> Source)
> at javax.xml.parsers.SAXParser.parse(Unknown Source)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:179)
> 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
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:256)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:271)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:398)
>
>
> Maybe it's because some elements have the same name in the different
> versions of UML, and EMF is getting lost. I am not sure about this.
> Also, depending on the order I load the files, it works: If I load a
> UML 1.0.0 file first, it works, but if I load the UML 2.2.0 first, the
> error occurs.
>
> What I want to do is to consider one metamodel at a time. For example:
> while reading a file for UML 2.2.0, only the UML 2.2.0 package is
> loaded. Then, I want to unload it, load another version of UML, and
> then read the file, so that there won't be any conflicts.
>
> However, the only way of registering these packages is by accessing
> the eINSTANCE field, which triggers some init() method that already
> loads the classes into some kind of global registry, and I am unable
> to unload them after that. Is there another way of registering the
> metamodel packages other than by using the eINSTANCE field(), so that
> I can try to use some custom class loader, for example, and have more
> control over which classes are loaded?
>
> Thanks
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Stereotype Application very slow
Next Topic:using PacakageMerge to transform a model.
Goto Forum:
  


Current Time: Tue Apr 16 11:35:02 GMT 2024

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

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

Back to the top