Contributing extended models in Eclipse and as stand-alone EMF. [message #869233] |
Thu, 03 May 2012 05:21 |
Frank Goldwin Messages: 10 Registered: May 2012 |
Junior Member |
|
|
Hi,
I have a number of message dictionaries specified in XML. Each has a different XML format.
I have the XSD for each one so I can build an EMF model for each one (DictionaryType1, DictionaryType2, etc).
I will create a plugin for each one so I can contribute different dictionary types to an application.
All models will implement a StandardDictionary interface that I define, so they can be handled in the same way by clients.
Then I want to build a DictionaryLibrary (DL) model to contain any number of these dictionaries.
The users should be able to copy a dictionary XML file into the workspace, then add a StandardDictionary node to the DL with the DL editor, specifying an alias for the dictionary and its XML target file in the workspace.
The DL then will be the application entry point to request dictionaries objects (by alias), both in Eclipse and stand-alone EMF.
Note: I will model the containment as cross-resource containment, so dictionaries remain in their XML file,
and the DL in its own file. This way I also get lazy loading through EMF proxy resolution.
The problem I'm having is 2 folds:
1 - I'm not sure how to model the StandardDictionary element in the DL model.
Should I model it as an interface?
Should I then have the the root node of each DictionaryTypeX model implement the StandardDictionary?
Like every EMF model the DictionaryTypeX plugins contribute to the org.eclipse.emf.ecore.generated_package extension point.
Thus in the DL editor I can work out the list of DictionaryTypeX registered.
Then, on a right click, I can display the list of available dictionary types for the user to choose, and then create the correct element as a child node of the Dictionary library.
Will this setup allow me to add a number of heterogeneous dictionary elements to the DL root in the DL editor?
Can EMF automate discovery of the list of registered dictionary types and display it in the popup menu?
2 - During stand-alone execution the DictionaryTypeX packages don't register themselves.
The DL model will be loaded from its file and for each child node should then use the correct DictionaryTypeX model to load it.
Does EMF provide the capability to have this happen automatically, maybe through adapter factories?
Or should I somehow provide some helper code to make this happen?
Note that XML dictionary files come from non-EMF sources and thus will not contain a namespace.
Ideally I would prefer not to modify them but I can if strictly necessary.
I feel I can use EMF capabilities to make this happen smoothly without adding any or much of my code but I'm not entirely sure how.
Any help would be much appreciated.
Than you.
Frank
|
|
|
Re: Contributing extended models in Eclipse and as stand-alone EMF. [message #869244 is a reply to message #869233] |
Thu, 03 May 2012 05:41 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Frank,
Comments below.
On 03/05/2012 7:21 AM, Frank Goldwin wrote:
> Hi,
>
> I have a number of message dictionaries specified in XML. Each has a
> different XML format.
> I have the XSD for each one so I can build an EMF model for each one
> (DictionaryType1, DictionaryType2, etc).
> I will create a plugin for each one so I can contribute different
> dictionary types to an application.
> All models will implement a StandardDictionary interface that I
> define, so they can be handled in the same way by clients.
>
> Then I want to build a DictionaryLibrary (DL) model to contain any
> number of these dictionaries.
As an XSD?
> The users should be able to copy a dictionary XML file into the
> workspace, then add a StandardDictionary node to the DL with the DL
> editor, specifying an alias for the dictionary and its XML target file
> in the workspace.
An alias?
> The DL then will be the application entry point to request
> dictionaries objects (by alias), both in Eclipse and stand-alone EMF.
>
> Note: I will model the containment as cross-resource containment, so
> dictionaries remain in their XML file,
> and the DL in its own file. This way I also get lazy loading through
> EMF proxy resolution.
Does it need to be containment at all?
>
> The problem I'm having is 2 folds:
>
> 1 - I'm not sure how to model the StandardDictionary element in the DL
> model.
> Should I model it as an interface?
You'll need an EClass. An interface just means there's no generated
Impl for that EClass but only for derived classes. If you make it
abstract there will be an Impl but you won't be able to create
instances, only derived instances. It's typically preferred to have an
Impl because otherwise each derived class needs its own "copy" of the
Impl details.
> Should I then have the the root node of each DictionaryTypeX model
> implement the StandardDictionary?
You can if you want.
> Like every EMF model the DictionaryTypeX plugins contribute to the
> org.eclipse.emf.ecore.generated_package extension point.
> Thus in the DL editor I can work out the list of DictionaryTypeX
> registered.
> Then, on a right click, I can display the list of available dictionary
> types for the user to choose, and then create the correct element as a
> child node of the Dictionary library.
> Will this setup allow me to add a number of heterogeneous dictionary
> elements to the DL root in the DL editor?
> Can EMF automate discovery of the list of registered dictionary types
> and display it in the popup menu?
Sounds like this case:
http://ed-merks.blogspot.de/2008/01/creating-children-you-didnt-know.html
>
> 2 - During stand-alone execution the DictionaryTypeX packages don't
> register themselves.
> The DL model will be loaded from its file and for each child node
> should then use the correct DictionaryTypeX model to load it.
> Does EMF provide the capability to have this happen automatically,
> maybe through adapter factories?
> Or should I somehow provide some helper code to make this happen?
You need to ensure that each package is initialized, i.e.,
XyzPackage.eINSTANCE.eClass() is an idiom for ensuring that the package
instance is initialized and registered in the global package registry.
>
> Note that XML dictionary files come from non-EMF sources and thus will
> not contain a namespace.
> Ideally I would prefer not to modify them but I can if strictly
> necessary.
I'm not sure how it will be possible for EMF (or any other tool) to know
which XSD and hence which EPackage specifies the syntax for what it's
supposed to read...
>
> I feel I can use EMF capabilities to make this happen smoothly without
> adding any or much of my code but I'm not entirely sure how.
The last part about no namespace yet multiple schemas sounds like the
worst problem. Somehow you'll have to know based on the file name or
the initial file contents which generated resource factory and hence
which package should be used to process the contents.
> Any help would be much appreciated.
>
> Than you.
> Frank
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05868 seconds