Skip to main content



      Home
Home » Modeling » MoDisco » MoDisco changing Model Load behavior(Problem loading as Meta-Model Type)
MoDisco changing Model Load behavior [message #664871] Tue, 12 April 2011 07:01 Go to next message
Eclipse UserFriend
Hi,

What I'm trying to do is load a file according to my Meta-Model from code like so:
ResourceSet resourceSet = new ResourceSetImpl();
Resource myRes = resourceSet.createResource(myFileUri, MyMetaModelPackage.eNS_URI);
myRes.load(null);
EObject myObj = xmlRes.getContents().get(0);

myFileUri points to a file on the local filesystem. MyMetaModelPackage.eNS_URI contins the namespace of the Meta-Model.

In the case where the file extension is the expected (the one specified in the genmodel), things work as expected. myRes gets loaded as an XMIResource and myObj is of the expected Meta-Model type.

However if myFileUri points to a file with identical content, but with a different file extension, things behave differently. Then myRes gets the type 'org.eclipse.gmt.modisco.xml.resource.GenericXMLResourceImpl ' and myObj is a 'org.eclipse.gmt.modisco.xml.emf.impl.RootImpl' with the name of the first element in the model file.

Thing is if I uninstall MoDisco (version 0.8.2.v201102100957) and repeat the process where I load the file with the wrong file extension, things work just normal. I get an XMIResource, and the EObject I get out is of my Meta-Model type.

Is this a known bug in MoDisco, or is it expected behavior? Is there a way I should do my loading so MoDisco doesn't interfere?

Thanks in advance for any clarifications,

Anders
Re: MoDisco changing Model Load behavior [message #664982 is a reply to message #664871] Tue, 12 April 2011 12:22 Go to previous messageGo to next message
Eclipse UserFriend
This is a multi-part message in MIME format.
--------------060500000507030903090101
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Anders,

Even if you make use of content types like the one registered for XMI

<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
base-type="org.eclipse.core.runtime.xml"
* file-extensions="xmi"*
id="org.eclipse.emf.ecore.xmi"
name="%_UI_XMI_content_type"
priority="normal">
<describer
class=" org.eclipse.emf.ecore.xmi.impl.XMLContentHandlerImpl$XMI$Des criber "/>
</content-type>
</extension>

you still need to specify which file extensions to inspect for that type
of content. So it's up to you to ensure you have sufficient
registrations against extensions if that's sufficiently unique or a
combination of content types and extension (if you want to use xml as
your extension for example) to get the behavior you desire.


Anders Olsson wrote:
> Hi,
>
> What I'm trying to do is load a file according to my Meta-Model from
> code like so:
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource myRes = resourceSet.createResource(myFileUri,
> MyMetaModelPackage.eNS_URI);
> myRes.load(null);
> EObject myObj = xmlRes.getContents().get(0);
>
> myFileUri points to a file on the local filesystem.
> MyMetaModelPackage.eNS_URI contins the namespace of the Meta-Model.
>
> In the case where the file extension is the expected (the one
> specified in the genmodel), things work as expected. myRes gets loaded
> as an XMIResource and myObj is of the expected Meta-Model type.
>
> However if myFileUri points to a file with identical content, but with
> a different file extension, things behave differently. Then myRes gets
> the type 'org.eclipse.gmt.modisco.xml.resource.GenericXMLResourceImpl
> ' and myObj is a 'org.eclipse.gmt.modisco.xml.emf.impl.RootImpl' with
> the name of the first element in the model file.
>
> Thing is if I uninstall MoDisco (version 0.8.2.v201102100957) and
> repeat the process where I load the file with the wrong file
> extension, things work just normal. I get an XMIResource, and the
> EObject I get out is of my Meta-Model type.
>
> Is this a known bug in MoDisco, or is it expected behavior? Is there a
> way I should do my loading so MoDisco doesn't interfere?
>
> Thanks in advance for any clarifications,
>
> Anders

--------------060500000507030903090101
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Anders,<br>
<br>
Even if you make use of content types like the one registered for XMI<br>
<br>
<small>  &lt;extension<br>
        point="org.eclipse.core.contenttype.contentTypes"&gt;<br >
     &lt;content-type<br>
           base-type="org.eclipse.core.runtime.xml"<br>
          <b> file-extensions="xmi"</b><br>
           id="org.eclipse.emf.ecore.xmi"<br>
           name="%_UI_XMI_content_type"<br>
           priority="normal"&gt;<br>
        &lt;describer
class=" org.eclipse.emf.ecore.xmi.impl.XMLContentHandlerImpl$XMI$Des criber "/&gt;<br>
     &lt;/content-type&gt;<br>
  &lt;/extension&gt;</small><br>
<br>
you still need to specify which file extensions to inspect for that
type of content.  So it's up to you to ensure you have sufficient
registrations against extensions if that's sufficiently unique or a
combination of content types and extension (if you want to use xml as
your extension for example) to get the behavior you desire.<br>
<br>
<br>
Anders Olsson wrote:
<blockquote cite="mid:io1avg$n8l$1@news.eclipse.org" type="cite">Hi,
<br>
<br>
What I'm trying to do is load a file according to my Meta-Model from
code like so:
<br>
ResourceSet resourceSet = new ResourceSetImpl();
<br>
Resource myRes = resourceSet.createResource(myFileUri,
MyMetaModelPackage.eNS_URI);
<br>
myRes.load(null);
<br>
EObject myObj = xmlRes.getContents().get(0);
<br>
<br>
myFileUri points to a file on the local filesystem.
MyMetaModelPackage.eNS_URI contins the namespace of the Meta-Model.
<br>
<br>
In the case where the file extension is the expected (the one specified
in the genmodel), things work as expected. myRes gets loaded as an
XMIResource and myObj is of the expected Meta-Model type.
<br>
<br>
However if myFileUri points to a file with identical content, but with
a different file extension, things behave differently. Then myRes gets
the type  'org.eclipse.gmt.modisco.xml.resource.GenericXMLResourceImpl
' and myObj is a  'org.eclipse.gmt.modisco.xml.emf.impl.RootImpl' with
the name of the first element in the model file.
<br>
<br>
Thing is if I uninstall MoDisco (version 0.8.2.v201102100957) and
repeat the process where I load the file with the wrong file extension,
things work just normal. I get an XMIResource, and the EObject I get
out is of my Meta-Model type.
<br>
<br>
Is this a known bug in MoDisco, or is it expected behavior? Is there a
way I should do my loading so MoDisco doesn't interfere?
<br>
<br>
Thanks in advance for any clarifications,
<br>
<br>
Anders
<br>
</blockquote>
</body>
</html>

--------------060500000507030903090101--
Re: MoDisco changing Model Load behavior [message #665087 is a reply to message #664871] Wed, 13 April 2011 04:38 Go to previous messageGo to next message
Eclipse UserFriend
Hi Anders,

XMIResource factory is the default EMF registered factory for
deserializing a file, but the fact is that MoDisco registers one
specific factory for files with extensions "xml". I suppose the file you
try to load has an extension "xml" ... ?

Alongside Ed explanation and solution with additional global
registration based on contenttype/extension, i suggest to try this : you
may locally register in your ResourceSet one whished factory for your
file extension, which will override the global factories registrations.
So you may add the following 2th line in your program :


ResourceSet resourceSet = new ResourceSetImpl();

resourceSet.getExtensionToFactoryMap().put("MYFILEEXTENSION ", new
org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl());

Resource myRes = resourceSet.createResource(myFileUri,
MyMetaModelPackage.eNS_URI);
myRes.load(null);
EObject myObj = xmlRes.getContents().get(0);


Fabien.
Re: MoDisco changing Model Load behavior [message #667201 is a reply to message #664871] Wed, 27 April 2011 07:50 Go to previous message
Eclipse UserFriend
Hi,

thank you very much Fabien and Ed. Your replies were spot on: the file extension was XML when I tried to load the file. Clearly isn't a MoDisco problem, but rather me not registering the correct Factory. Thanks for the concrete example on how to do this as well.

Best Regards,

Anders
Previous Topic:MoDisco 0.8 Java Code Generation
Next Topic:Welcome to eclipse.modisco
Goto Forum:
  


Current Time: Thu May 15 14:44:16 EDT 2025

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

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

Back to the top