Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Model file suffix mandatory
Model file suffix mandatory [message #899138] Mon, 30 July 2012 16:17 Go to next message
Ralph P is currently offline Ralph PFriend
Messages: 30
Registered: September 2010
Location: Frankfurt, Germany
Member
Hi,

I defined an ECORE model called "MyModel".
The generated wizard creates XML files with the suffix .mymodel which can be edited with the corresponding generated editor.

My problem is, that the editor throws an exception when the suffix is not .mymodel (see below). Why does that happen? How can this error make sense?

org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 'MyModel' is not found or is abstract. (platform:/resource/MyProject/Model.xml, 2, 73)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.validateCreateObjectFromFactory(XMLHandler.java:2244)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.validateCreateObjectFromFactory(XMLHandler.java:2235)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1332)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1468)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1019)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:83)


Is there a way to enable other suffixes as well or make it irrelevant which suffix the XML file must have?

Thanks in advance!

Regards,
Ralph
Re: Model file suffix mandatory [message #899172 is a reply to message #899138] Mon, 30 July 2012 20:38 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Ralph,

Comments below.
On 30/07/2012 6:17 PM, Ralph P wrote:
> Hi,
>
> I defined an ECORE model called "MyModel".
> The generated wizard creates XML files with the suffix .mymodel which
> can be edited with the corresponding generated editor.
>
> My problem is, that the editor throws an exception when the suffix is
> not .mymodel (see below). Why does that happen?
Because the right factory is registered in the plugin.xml based on the
suffix; have a look.
> How can this error make sense?
>
> org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 'MyModel' is
> not found or is abstract. (platform:/resource/MyProject/Model.xml, 2, 73)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.validateCreateObjectFromFactory(XMLHandler.java:2244)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.validateCreateObjectFromFactory(XMLHandler.java:2235)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1332)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1468)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1019)
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:83)
>
> Is there a way to enable other suffixes as well or make it irrelevant
> which suffix the XML file must have?
Yes, but if you want to use a commonly used suffix like *.xml, you'll
need to use content types. You can do that by defining a content type
identifier for the GenPackage and changing the suffix to what you want
to use. Be sure the delete the plugin.xml and regenerate it and have a
look at what's generated to understand it better.
>
>
> Thanks in advance!
>
> Regards,
> Ralph


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Model file suffix mandatory [message #899235 is a reply to message #899172] Tue, 31 July 2012 08:05 Go to previous messageGo to next message
Ralph P is currently offline Ralph PFriend
Messages: 30
Registered: September 2010
Location: Frankfurt, Germany
Member
Hello Ed,

thanks for the reply!
I don't fully understand you, but you still brought me a solution.
I just defined two more org.eclipse.emf.ecore.extension_parsers extensions with different types/suffixes (one of them is 'xml') which point at the same ResourceFactory. It seems to work fine. Is there an argument not to do it that way?

Quote:
You can do that by defining a content type
identifier for the GenPackage and changing the suffix to what you want
to use.

This is what I don't understand. Do you mean defining a new Content Type via an Eclipse extension in the plugin.xml? How do I refer to the "GenPackage"?

Quote:
Be sure the delete the plugin.xml and regenerate it and have a
look at what's generated to understand it better.

You mean the generation process of the model code is affected by the content types? Does this mean I need to have the content type defined in my development environment?

Regards,
Ralf
Re: Model file suffix mandatory [message #899242 is a reply to message #899235] Tue, 31 July 2012 08:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Ralph,

There can be only one resource factory registered against *.xml, so if
everyone does this, there will be one winner and lots of losers...

On 31/07/2012 10:05 AM, Ralph P wrote:
> Hello Ed,
>
> thanks for the reply!
> I don't fully understand you, but you still brought me a solution.
> I just defined two more org.eclipse.emf.ecore.extension_parsers
> extensions with different types/suffixes (one of them is 'xml') which
> point at the same ResourceFactory. It seems to work fine. Is there an
> argument not to do it that way?
>
> Quote:
>> You can do that by defining a content type
>> identifier for the GenPackage and changing the suffix to what you want
>> to use.
>
> This is what I don't understand. Do you mean defining a new Content
> Type via an Eclipse extension in the plugin.xml? How do I refer to the
> "GenPackage"?
When you open the *.genmodel, the GenPackage is the second level of
nesting. If you selected it, you'll see all the properties you can
specify for a GenPackage, one of which is the Content Type Identifier.
>
> Quote:
>> Be sure the delete the plugin.xml and regenerate it and have a
>> look at what's generated to understand it better.
>
> You mean the generation process of the model code is affected by the
> content types?
Of the plugin.xml yes. The content type identifier also produces a
constant in the generated XyzPackage.
> Does this mean I need to have the content type defined in my
> development environment?
Yes, EMF will generate the right things for you.
>
> Regards,
> Ralf
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Model file suffix mandatory [message #899268 is a reply to message #899242] Tue, 31 July 2012 09:31 Go to previous messageGo to next message
Ralph P is currently offline Ralph PFriend
Messages: 30
Registered: September 2010
Location: Frankfurt, Germany
Member
Hi Ed,

thanks again, now I understood! Unfortunately it's still not working, even if everything looks fine now.

I added a Content Type Identifier and added three File Extensions. The generator creates a correct content_parser and the corresponding content type in the (new) plugin.xml. At runtime I can find the content type (with the extensions). But mysteriously the editor still only accepts "*.mymodel" files (even if I remove the mymodel extension from the content type). Since no extension_parser was created in the plugin.xml, I'm asking myself where the mymodel extension is registered and why the other extensions are not.

Do you have an idea?

Regards,
Ralf
Re: Model file suffix mandatory [message #899426 is a reply to message #899268] Tue, 31 July 2012 18:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Ralph,

Comments below.

On 31/07/2012 11:31 AM, Ralph P wrote:
> Hi Ed,
>
> thanks again, now I understood! Unfortunately it's still not working,
> even if everything looks fine now.
>
> I added a Content Type Identifier and added three File Extensions. The
> generator creates a correct content_parser and the corresponding
> content type in the (new) plugin.xml. At runtime I can find the
> content type (with the extensions). But mysteriously the editor still
> only accepts "*.mymodel" files (even if I remove the mymodel extension
> from the content type). Since no extension_parser was created in the
> plugin.xml, I'm asking myself where the mymodel extension is
> registered and why the other extensions are not.
Did you delete the editor project's plugin.xml? The editor registration
is different when you use content types...
>
> Do you have an idea?
>
> Regards,
> Ralf
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Model file suffix mandatory [message #899519 is a reply to message #899426] Wed, 01 August 2012 09:29 Go to previous messageGo to next message
Ralph P is currently offline Ralph PFriend
Messages: 30
Registered: September 2010
Location: Frankfurt, Germany
Member
Hi Ed,

regenerating the plugin.xml in the editor plug-in created a content type binding properly, but it had nothing to do with registering the factory properly.
But I found out that the reference to my content type in the was "<model plug-in ID>.model", while in the content_parser extension it was only "model".
So I changed the "contentTypeIdentifier" attribute value manually to "<model plug-in ID>.model" - and it worked!

I also had to change the eCONTENT_TYPE constant of the ModelPackage interface, because the finish action of the generated wizard could also not resolve the "model" content type ID.

Anyways, it's now working 100% how I want it to be! Thank you very much!

Regards,
Ralf
Re: Model file suffix mandatory [message #899530 is a reply to message #899519] Wed, 01 August 2012 10:14 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Ralf,

Comments below.
On 01/08/2012 11:29 AM, Ralph P wrote:
> Hi Ed,
>
> regenerating the plugin.xml in the editor plug-in created a content
> type binding properly, but it had nothing to do with registering the
> factory properly.
> But I found out that the reference to my content type in the was
> "<model plug-in ID>.model", while in the content_parser extension it
> was only "model".
Ah yes, if the ID isn't qualified at all, PDE implicitly qualifies it.
You really should use a qualified name in the first place; something
globally unique, like Java package names.
> So I changed the "contentTypeIdentifier" attribute value manually to
> "<model plug-in ID>.model" - and it worked!
>
> I also had to change the eCONTENT_TYPE constant of the ModelPackage
> interface, because the finish action of the generated wizard could
> also not resolve the "model" content type ID.
As long as the plugin.xmls were regenerated after your changes to the
*.genmodel, everything should align...
>
> Anyways, it's now working 100% how I want it to be! Thank you very much!
You're welcome.
>
> Regards,
> Ralf


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF: Obfuscate generated code
Next Topic:[CDO/Hibernate] Examples: Why Query with CDOTransaction and not CDOView?
Goto Forum:
  


Current Time: Thu Apr 25 14:17:59 GMT 2024

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

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

Back to the top