Home » Modeling » EMF » How to determine model's metamodel?
|
Re: How to determine model's metamodel? [message #429216 is a reply to message #429214] |
Tue, 14 April 2009 20:59 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Esteban,
Comments below.
Esteban Dugueperoux wrote:
> Hi,
>
> I would like to write a program receveing as input a file and
> determining his metamodel (nsURI).
> Is it possible with EMF, with a generic ResourceFactory?
>
> The only way that I have found :
>
> public String getMetamodel(File file){
> String nsURI;
> ResourceSet resourceSet = new ResourceSetImpl();
> Factory factory;
> factory = new XMIResourceFactoryImpl();
> resourceSet.getResourceFactoryRegistry()
> .getExtensionToFactoryMap().put(
> Resource.Factory.Registry.DEFAULT_EXTENSION, factory);
>
> URI uri = URI.createFileURI(file.getAbsolutePath());
> Resource resource = null;
>
> try {
> resource = resourceSet.getResource(uri, true);
> } catch (Exception e) {
> Throwable throwable = e.getCause();
> if(throwable instanceof PackageNotFoundException){
> PackageNotFoundException exception =
> (PackageNotFoundException) throwable;
> nsURI = exception.uri();
> }
> }
> return nsURI;
> }
>
> Do you have a proper method?
This is pretty much what content types help you do. I wonder what you
will do with this information? A RootXMLContentHandlerImpl could be
used to do it more directly...
public RootXMLContentHandlerImpl
(String contentTypeID,
String [] extensions,
String kind,
Pattern namespacePattern,
String [] elementNames)
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to determine model's metamodel? [message #429254 is a reply to message #429216] |
Wed, 15 April 2009 13:53 |
Esteban Dugueperoux Messages: 472 Registered: July 2009 |
Senior Member |
|
|
Hi Ed,
I don't see how to use RootXMLContentHandlerImpl. Is it through a
URIConverter to pass to a ResourceSet?
What are these needed parameters constructor?
I don't see why RootXMLContentHandlerImpl is related to contentType
extension point.
I have found this thread
http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg3 2631.html
which explain that content types are appropriate but I don't see why.
Thanks.
Ed Merks a écrit :
> Esteban,
>
> Comments below.
>
>
> Esteban Dugueperoux wrote:
>> Hi,
>>
>> I would like to write a program receveing as input a file and
>> determining his metamodel (nsURI).
>> Is it possible with EMF, with a generic ResourceFactory?
>>
>> The only way that I have found :
>>
>> public String getMetamodel(File file){
>> String nsURI;
>> ResourceSet resourceSet = new ResourceSetImpl();
>> Factory factory;
>> factory = new XMIResourceFactoryImpl();
>> resourceSet.getResourceFactoryRegistry()
>> .getExtensionToFactoryMap().put(
>> Resource.Factory.Registry.DEFAULT_EXTENSION, factory);
>>
>> URI uri = URI.createFileURI(file.getAbsolutePath());
>> Resource resource = null;
>> try {
>> resource = resourceSet.getResource(uri, true);
>> } catch (Exception e) {
>> Throwable throwable = e.getCause();
>> if(throwable instanceof PackageNotFoundException){
>> PackageNotFoundException exception =
>> (PackageNotFoundException) throwable;
>> nsURI = exception.uri();
>> }
>> }
>> return nsURI;
>> }
>>
>> Do you have a proper method?
> This is pretty much what content types help you do. I wonder what you
> will do with this information? A RootXMLContentHandlerImpl could be
> used to do it more directly...
>
> public RootXMLContentHandlerImpl
> (String contentTypeID,
> String [] extensions,
> String kind,
> Pattern namespacePattern,
> String [] elementNames)
|
|
|
Re: How to determine model's metamodel? [message #429256 is a reply to message #429254] |
Wed, 15 April 2009 15:14 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Esteban,
Comments below.
Esteban DUGUEPEROUX wrote:
> Hi Ed,
>
> I don't see how to use RootXMLContentHandlerImpl.
Well, it's not entirely self evident I know. It can be used just all
by itself. You've tried to experiment.
> Is it through a URIConverter to pass to a ResourceSet?
You can see uses of it in the plugin.xml of the
org.eclipse.emf.ecore.xmi plugin.
> What are these needed parameters constructor?
> I don't see why RootXMLContentHandlerImpl is related to contentType
> extension point.
See the plugin.xml I referred to above.
> I have found this thread
> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg3 2631.html
> which explain that content types are appropriate but I don't see why.
Nor did you answer the question I asked. What are you trying to accomplish?
>
>
> Thanks.
>
>
> Ed Merks a écrit :
>> Esteban,
>>
>> Comments below.
>>
>>
>> Esteban Dugueperoux wrote:
>>> Hi,
>>>
>>> I would like to write a program receveing as input a file and
>>> determining his metamodel (nsURI).
>>> Is it possible with EMF, with a generic ResourceFactory?
>>>
>>> The only way that I have found :
>>>
>>> public String getMetamodel(File file){
>>> String nsURI;
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>> Factory factory;
>>> factory = new XMIResourceFactoryImpl();
>>> resourceSet.getResourceFactoryRegistry()
>>> .getExtensionToFactoryMap().put(
>>> Resource.Factory.Registry.DEFAULT_EXTENSION, factory);
>>>
>>> URI uri = URI.createFileURI(file.getAbsolutePath());
>>> Resource resource = null;
>>> try {
>>> resource = resourceSet.getResource(uri, true);
>>> } catch (Exception e) {
>>> Throwable throwable = e.getCause();
>>> if(throwable instanceof PackageNotFoundException){
>>> PackageNotFoundException exception =
>>> (PackageNotFoundException) throwable;
>>> nsURI = exception.uri();
>>> }
>>> }
>>> return nsURI;
>>> }
>>>
>>> Do you have a proper method?
>> This is pretty much what content types help you do. I wonder what
>> you will do with this information? A RootXMLContentHandlerImpl could
>> be used to do it more directly...
>>
>> public RootXMLContentHandlerImpl
>> (String contentTypeID,
>> String [] extensions,
>> String kind,
>> Pattern namespacePattern,
>> String [] elementNames)
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to determine model's metamodel? [message #429260 is a reply to message #429256] |
Wed, 15 April 2009 16:02 |
Esteban Dugueperoux Messages: 472 Registered: July 2009 |
Senior Member |
|
|
Sorry,
My project is to create a GMF editor to describe MDA workflow where we
can drag'n drop file corresponding to model to transform/generate.
I must determine if the file dropped is a XMI file and his metamodel. I
need his metamodel to control if I can set this model as input of a
transformation/generation model (ATL, MOFScript, ...) according to
metamodel transformation/generation model.
Thanks for you help Ed.
Ed Merks a écrit :
> Esteban,
>
> Comments below.
>
>
> Esteban DUGUEPEROUX wrote:
>> Hi Ed,
>>
>> I don't see how to use RootXMLContentHandlerImpl.
> Well, it's not entirely self evident I know. It can be used just all
> by itself. You've tried to experiment.
>> Is it through a URIConverter to pass to a ResourceSet?
> You can see uses of it in the plugin.xml of the
> org.eclipse.emf.ecore.xmi plugin.
>> What are these needed parameters constructor?
>> I don't see why RootXMLContentHandlerImpl is related to contentType
>> extension point.
> See the plugin.xml I referred to above.
>> I have found this thread
>> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg3 2631.html
>> which explain that content types are appropriate but I don't see why.
> Nor did you answer the question I asked. What are you trying to
> accomplish?
>>
>>
>> Thanks.
>>
>>
>> Ed Merks a écrit :
>>> Esteban,
>>>
>>> Comments below.
>>>
>>>
>>> Esteban Dugueperoux wrote:
>>>> Hi,
>>>>
>>>> I would like to write a program receveing as input a file and
>>>> determining his metamodel (nsURI).
>>>> Is it possible with EMF, with a generic ResourceFactory?
>>>>
>>>> The only way that I have found :
>>>>
>>>> public String getMetamodel(File file){
>>>> String nsURI;
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>> Factory factory;
>>>> factory = new XMIResourceFactoryImpl();
>>>> resourceSet.getResourceFactoryRegistry()
>>>> .getExtensionToFactoryMap().put(
>>>> Resource.Factory.Registry.DEFAULT_EXTENSION, factory);
>>>>
>>>> URI uri = URI.createFileURI(file.getAbsolutePath());
>>>> Resource resource = null;
>>>> try {
>>>> resource = resourceSet.getResource(uri, true);
>>>> } catch (Exception e) {
>>>> Throwable throwable = e.getCause();
>>>> if(throwable instanceof PackageNotFoundException){
>>>> PackageNotFoundException exception =
>>>> (PackageNotFoundException) throwable;
>>>> nsURI = exception.uri();
>>>> }
>>>> }
>>>> return nsURI;
>>>> }
>>>>
>>>> Do you have a proper method?
>>> This is pretty much what content types help you do. I wonder what
>>> you will do with this information? A RootXMLContentHandlerImpl could
>>> be used to do it more directly...
>>>
>>> public RootXMLContentHandlerImpl
>>> (String contentTypeID,
>>> String [] extensions,
>>> String kind,
>>> Pattern namespacePattern,
>>> String [] elementNames)
|
|
|
Re: How to determine model's metamodel? [message #429261 is a reply to message #429260] |
Wed, 15 April 2009 18:57 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Esteban,
This is exactly the purpose of content types. For example, this defines
that "EMOF" content type can appear with files with emof or xmi
extension in which the namespace of the root element (ignoring the
special XMI element if it appears) matches the namespace pattern below.
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
base-type="org.eclipse.emf.ecore.xmi"
file-extensions="emof,xmi"
id="org.eclipse.emf.emof"
name="%_UI_EMOF_content_type"
priority="normal">
<describer
class=" org.eclipse.emf.ecore.xmi.impl.RootXMLContentHandlerImpl$Des criber ">
<parameter
name="namespacePattern"
value="http://schema\.omg\.org/spec/(mof/2\.0/emof\.xmi|MOF/2\.0/emof\.xml)">
</parameter>
<parameter
name="kind"
value="xmi">
</parameter>
</describer>
</content-type>
</extension>
URIConverter.contentDescription can be used to determine the content
type of something, so think that's what you want to be using, along with
a registration of a content type for the namespace you're interested in...
Esteban DUGUEPEROUX wrote:
> Sorry,
>
> My project is to create a GMF editor to describe MDA workflow where we
> can drag'n drop file corresponding to model to transform/generate.
> I must determine if the file dropped is a XMI file and his metamodel.
> I need his metamodel to control if I can set this model as input of a
> transformation/generation model (ATL, MOFScript, ...) according to
> metamodel transformation/generation model.
>
> Thanks for you help Ed.
>
> Ed Merks a écrit :
>> Esteban,
>>
>> Comments below.
>>
>>
>> Esteban DUGUEPEROUX wrote:
>>> Hi Ed,
>>>
>>> I don't see how to use RootXMLContentHandlerImpl.
>> Well, it's not entirely self evident I know. It can be used just
>> all by itself. You've tried to experiment.
>>> Is it through a URIConverter to pass to a ResourceSet?
>> You can see uses of it in the plugin.xml of the
>> org.eclipse.emf.ecore.xmi plugin.
>>> What are these needed parameters constructor?
>>> I don't see why RootXMLContentHandlerImpl is related to contentType
>>> extension point.
>> See the plugin.xml I referred to above.
>>> I have found this thread
>>> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg3 2631.html
>>> which explain that content types are appropriate but I don't see why.
>> Nor did you answer the question I asked. What are you trying to
>> accomplish?
>>>
>>>
>>> Thanks.
>>>
>>>
>>> Ed Merks a écrit :
>>>> Esteban,
>>>>
>>>> Comments below.
>>>>
>>>>
>>>> Esteban Dugueperoux wrote:
>>>>> Hi,
>>>>>
>>>>> I would like to write a program receveing as input a file and
>>>>> determining his metamodel (nsURI).
>>>>> Is it possible with EMF, with a generic ResourceFactory?
>>>>>
>>>>> The only way that I have found :
>>>>>
>>>>> public String getMetamodel(File file){
>>>>> String nsURI;
>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>> Factory factory;
>>>>> factory = new XMIResourceFactoryImpl();
>>>>> resourceSet.getResourceFactoryRegistry()
>>>>> .getExtensionToFactoryMap().put(
>>>>> Resource.Factory.Registry.DEFAULT_EXTENSION, factory);
>>>>>
>>>>> URI uri = URI.createFileURI(file.getAbsolutePath());
>>>>> Resource resource = null;
>>>>> try {
>>>>> resource = resourceSet.getResource(uri, true);
>>>>> } catch (Exception e) {
>>>>> Throwable throwable = e.getCause();
>>>>> if(throwable instanceof PackageNotFoundException){
>>>>> PackageNotFoundException exception
>>>>> = (PackageNotFoundException) throwable;
>>>>> nsURI = exception.uri();
>>>>> }
>>>>> }
>>>>> return nsURI;
>>>>> }
>>>>>
>>>>> Do you have a proper method?
>>>> This is pretty much what content types help you do. I wonder what
>>>> you will do with this information? A RootXMLContentHandlerImpl
>>>> could be used to do it more directly...
>>>>
>>>> public RootXMLContentHandlerImpl
>>>> (String contentTypeID,
>>>> String [] extensions,
>>>> String kind,
>>>> Pattern namespacePattern,
>>>> String [] elementNames)
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Sat Apr 27 04:55:52 GMT 2024
Powered by FUDForum. Page generated in 0.03144 seconds
|