Home » Modeling » EMF » inspecting an ecore
| |
Re: inspecting an ecore [message #636966 is a reply to message #635713] |
Wed, 03 November 2010 15:08 |
|
On 10/27/2010 09:08 PM, Ed Merks wrote:
> Lorenzo,
>
> Loading resources works the same for all models and that's described in
> the introductory overview. The paper about dynamic Ecore will probably
> be very helpful for what you want to do.
>
> Discover the Eclipse Modeling Framework (EMF) and Its Dynamic
> Capabilities <http://www.devx.com/Java/Article/29093/0/page/1>
>
>
> Lorenzo Bettini wrote:
>> Hi
>>
>> In my application I'd like to able to load an ecore file and be able
>> to inspect all the elements defined there...
>>
>> is there any tutorial/example showing that?
>>
I'm doing something like this, does it look right?
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet
.getResourceFactoryRegistry()
.getContentTypeToFactoryMap()
.put(EcorePackage.eCONTENT_TYPE, new
EcoreResourceFactoryImpl());
resourceSet
.getURIConverter()
.getContentHandlers()
.add(new RootXMLContentHandlerImpl(EcorePackage.eCONTENT_TYPE,
null, null,
EcorePackage.eNS_URI, null));
resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI,
EcorePackage.eINSTANCE);
URI uri = URI.createFileURI("model/FJ.ecore");
Resource resource = resourceSet.getResource(uri, true);
System.out.println("Loaded " + uri); //$NON-NLS-1$
System.out.println("Resource: " + resource.toString());
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Re: inspecting an ecore [message #637013 is a reply to message #636966] |
Wed, 03 November 2010 18:28 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Lorenzo,
Comments below.
Lorenzo Bettini wrote:
> On 10/27/2010 09:08 PM, Ed Merks wrote:
>> Lorenzo,
>>
>> Loading resources works the same for all models and that's described in
>> the introductory overview. The paper about dynamic Ecore will probably
>> be very helpful for what you want to do.
>>
>> Discover the Eclipse Modeling Framework (EMF) and Its Dynamic
>> Capabilities <http://www.devx.com/Java/Article/29093/0/page/1>
>>
>>
>> Lorenzo Bettini wrote:
>>> Hi
>>>
>>> In my application I'd like to able to load an ecore file and be able
>>> to inspect all the elements defined there...
>>>
>>> is there any tutorial/example showing that?
>>>
>
> I'm doing something like this, does it look right?
Does it work?
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> resourceSet
> .getResourceFactoryRegistry()
> .getContentTypeToFactoryMap()
> .put(EcorePackage.eCONTENT_TYPE, new
> EcoreResourceFactoryImpl());
>
> resourceSet
> .getURIConverter()
> .getContentHandlers()
> .add(new RootXMLContentHandlerImpl(EcorePackage.eCONTENT_TYPE,
> null, null,
> EcorePackage.eNS_URI, null));
I've not tried content handlers for Ecore.
>
> resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI,
> EcorePackage.eINSTANCE);
>
> URI uri = URI.createFileURI("model/FJ.ecore");
It's best to use an absolute path.
>
> Resource resource = resourceSet.getResource(uri, true);
> System.out.println("Loaded " + uri); //$NON-NLS-1$
>
> System.out.println("Resource: " + resource.toString());
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: inspecting an ecore [message #637680 is a reply to message #637013] |
Mon, 08 November 2010 10:35 |
|
On 11/03/2010 07:28 PM, Ed Merks wrote:
> Lorenzo Bettini wrote:
>> On 10/27/2010 09:08 PM, Ed Merks wrote:
>>> Lorenzo,
>>>
>>> Loading resources works the same for all models and that's described in
>>> the introductory overview. The paper about dynamic Ecore will probably
>>> be very helpful for what you want to do.
>>>
>>> Discover the Eclipse Modeling Framework (EMF) and Its Dynamic
>>> Capabilities <http://www.devx.com/Java/Article/29093/0/page/1>
>>>
>>>
>>> Lorenzo Bettini wrote:
>>>> Hi
>>>>
>>>> In my application I'd like to able to load an ecore file and be able
>>>> to inspect all the elements defined there...
>>>>
>>>> is there any tutorial/example showing that?
>>>>
>>
>> I'm doing something like this, does it look right?
> Does it work?
yes, but I wanted to be sure I was doing it right :)
>>
>> ResourceSet resourceSet = new ResourceSetImpl();
>>
>> resourceSet
>> .getResourceFactoryRegistry()
>> .getContentTypeToFactoryMap()
>> .put(EcorePackage.eCONTENT_TYPE, new
>> EcoreResourceFactoryImpl());
>>
>> resourceSet
>> .getURIConverter()
>> .getContentHandlers()
>> .add(new RootXMLContentHandlerImpl(EcorePackage.eCONTENT_TYPE,
>> null, null,
>> EcorePackage.eNS_URI, null));
> I've not tried content handlers for Ecore.
actually I started from the code generated when "generate test code"
>>
>> resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI,
>> EcorePackage.eINSTANCE);
>>
>> URI uri = URI.createFileURI("model/FJ.ecore");
> It's best to use an absolute path.
yes, that was just a test... by the way, is there a kind of reference
sheet for the several available URI syntaxes?
thanks
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Re: inspecting an ecore [message #637731 is a reply to message #637680] |
Mon, 08 November 2010 13:28 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Lorenzo,
Comments below.
Lorenzo Bettini wrote:
> On 11/03/2010 07:28 PM, Ed Merks wrote:
>> Lorenzo Bettini wrote:
>>> On 10/27/2010 09:08 PM, Ed Merks wrote:
>>>> Lorenzo,
>>>>
>>>> Loading resources works the same for all models and that's
>>>> described in
>>>> the introductory overview. The paper about dynamic Ecore will probably
>>>> be very helpful for what you want to do.
>>>>
>>>> Discover the Eclipse Modeling Framework (EMF) and Its Dynamic
>>>> Capabilities <http://www.devx.com/Java/Article/29093/0/page/1>
>>>>
>>>>
>>>> Lorenzo Bettini wrote:
>>>>> Hi
>>>>>
>>>>> In my application I'd like to able to load an ecore file and be able
>>>>> to inspect all the elements defined there...
>>>>>
>>>>> is there any tutorial/example showing that?
>>>>>
>>>
>>> I'm doing something like this, does it look right?
>> Does it work?
>
> yes, but I wanted to be sure I was doing it right :)
>
>>>
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>
>>> resourceSet
>>> .getResourceFactoryRegistry()
>>> .getContentTypeToFactoryMap()
>>> .put(EcorePackage.eCONTENT_TYPE, new
>>> EcoreResourceFactoryImpl());
>>>
>>> resourceSet
>>> .getURIConverter()
>>> .getContentHandlers()
>>> .add(new RootXMLContentHandlerImpl(EcorePackage.eCONTENT_TYPE,
>>> null, null,
>>> EcorePackage.eNS_URI, null));
>> I've not tried content handlers for Ecore.
>
> actually I started from the code generated when "generate test code"
Then it must be right. :-P
>
>>>
>>> resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI,
>>> EcorePackage.eINSTANCE);
>>>
>>> URI uri = URI.createFileURI("model/FJ.ecore");
>> It's best to use an absolute path.
>
> yes, that was just a test... by the way, is there a kind of reference
> sheet for the several available URI syntaxes?
Well, anything that's a well formed URL is allowed. Others define how
http:, file:, zip: are structured. The Eclipse platform defines how
platform: is structured...
>
> thanks
> Lorenzo
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Thu Sep 26 15:43:02 GMT 2024
Powered by FUDForum. Page generated in 0.03141 seconds
|