Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Resolving proxy when processing xtext model
Resolving proxy when processing xtext model [message #556470] Wed, 01 September 2010 13:37 Go to next message
Eclipse UserFriend
Originally posted by: mdsamh.yahoo.com

Hi,



The purpose of my grammar is to manipulate a source .ecore model. In my
grammar, I import Ecore metamodel (http:www.eclipse.org/emf/2002/ecore) to
type elements of my rules. I also allow importing a source .ecore model,
using importURI = STRING, where I can supply a URI of a source model that I
intend to manipulate.

Below is part of my grammar:

grammar nha.xtext.demo.MyDemo with org.eclipse.xtext.common.Terminals

generate myDemo "http://www.xtext.nha/demo/MyDemo"

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Model:
imports+=Import*
manipulations+= Manipulations *;
Import:
"import" importURI=STRING;
Manipulations:
"manipulate" class=[ecore::EClass];

In the editor, I can type

import "platform:/resource/projectName/folderName/source.ecore"

manipulate ClassOne

// assuming ClassOne is an EClass in model source.ecore which I imported

This gives me an Xtext file with proxy:

org.eclipse.emf.ecore.impl.EClassImpl@12b4986 (eProxyURI:

Report message to a moderator

Re: Resolving proxy when processing xtext model [message #556479 is a reply to message #556470] Wed, 01 September 2010 14:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i guess you get this error when generating code right / reading the model ?

to be able to handle platform./resource uris you have to add following to the workflow

Workflow {
    bean = StandaloneSetup {
		platformUri = ".."
	}
...


or when in a Java Context

new StandaloneSetup ().setPlatformUri("..");
MyDemoStandaloneSetup.doSetup();
...


to get the files read you have to add following to YourDslStandaloneSetup

@Override
	public void register(Injector injector) {
		super.register(injector);
		org.eclipse.xtext.resource.IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceServiceProviderImpl());
	}


and therefore have to add org.eclipse.xtext.ecore to the plugin dependencies.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 02 September 2010 06:27]

Report message to a moderator

Re: Resolving proxy when processing xtext model [message #556542 is a reply to message #556470] Wed, 01 September 2010 16:54 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
You are using a platform:/resource URI, which is only valid form within
Eclipse as it refers to projects in the workspace. So it can be linked
in the editor, but not in standalone Java code.

As an alternative, you could use a relative URI or a classpath:/ URI, or
use the URI mapper of your resource set to map the platform:/resource
URI to a file URI.

Regards
Jan


Am 01.09.10 15:37, schrieb medo samh:
> Hi,
>
>
>
> The purpose of my grammar is to manipulate a source .ecore model. In my
> grammar, I import Ecore metamodel (http:www.eclipse.org/emf/2002/ecore) to
> type elements of my rules. I also allow importing a source .ecore model,
> using importURI = STRING, where I can supply a URI of a source model that I
> intend to manipulate.
>
> Below is part of my grammar:
>
> grammar nha.xtext.demo.MyDemo with org.eclipse.xtext.common.Terminals
>
> generate myDemo "http://www.xtext.nha/demo/MyDemo"
>
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
>
> Model:
> imports+=Import*
> manipulations+= Manipulations *;
> Import:
> "import" importURI=STRING;
> Manipulations:
> "manipulate" class=[ecore::EClass];
>
> In the editor, I can type
>
> import "platform:/resource/projectName/folderName/source.ecore"
>
> manipulate ClassOne
>
> // assuming ClassOne is an EClass in model source.ecore which I imported
>
> This gives me an Xtext file with proxy:
>
> org.eclipse.emf.ecore.impl.EClassImpl@12b4986 (eProxyURI:
> model/first.mydemo#xtextLink_:://@manipulations.0::http://ww w.xtext.nha/demo/MyDemo«Manipulations«0::/3)
>
> In my code, I can load the Xtext file successfully but could not resolve the
> proxy to get the name of ClassOne.
>
> I load the Xtext file using:
>
> MyDemoStandaloneSetup.doSetup();
>
> XtextResourceSet drs = new XtextResourceSet();
>
> URI uri = URI.createURI("folderName/modelName.mydemo");
>
> Resource xtextResource = drs.getResource(uri , true);
>
> Model md = (Model) xtextResource.getContents().get(0);
>
> xtextResource.load(null)
>
>
>
> I try to resolve the proxy using:
>
> Manipulations manipulations = (Manipulations) manipulations;
>
> EObject mc = (EObject) manipulations.getClass_();
>
> if (mc !=null&& mc.eIsProxy()){
>
> InternalEObject imc =(InternalEObject)mc;
>
> mc = EcoreUtil.resolve(mc, manipulations);
>
> }
>
> This code did not work and I am not sure if this is the right way.
>
> I am new to xtext and EMF and this problem is stopping me. I would really
> appreciate your advice to go over it.
>
>
>
> Thanks in advance
>
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Resolving proxy when processing xtext model [message #556626 is a reply to message #556479] Thu, 02 September 2010 07:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mdsamh.yahoo.com

Hi Christian,

Thanks for your help. I have followed your steps. The two entries in the
Workflow were there by default (did not need to add them). I have added the
register ( ) method to MyDslStandaloneSetup as you suggested.

But now whenever I try to run my program to load my Xtext model, I get the
error below:

Exception in thread "main" java.lang.NoClassDefFoundError:
org/eclipse/xtext/ecore/EcoreResourceServiceProviderImplat
nha.xtext.demo.MyDemoStandaloneSetup.register(MyDemoStandalo neSetup.java:24)at
nha.xtext.demo.MyDemoStandaloneSetupGenerated.createInjector AndDoEMFRegistration(MyDemoStandaloneSetupGenerated.java:21) at
nha.xtext.demo.MyDemoStandaloneSetup.doSetup(MyDemoStandalon eSetup.java:18)at
modelDemo.LoadingDemo.load(LoadingDemo.java:24) at
modelDemo.Test_LoadingDemo.main(Test_LoadingDemo.java:48)

Caused by: java.lang.ClassNotFoundException:
org.eclipse.xtext.ecore.EcoreResourceServiceProviderImpl

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

... 5 more

I am not sure what is the cause of this error. As I said, I new to Xtext
and I could be missing something very obvious.

Thanks in advance for your help



"Christian Dietrich" <christian.dietrich@itemis.de> wrote in message
news:i5lmvs$98s$1@build.eclipse.org...
> Hi,
>
> i guess you get this error when generating code right / reading the model
> ?
>
> to be able to handle platform./resource uris you have to add following to
> the workflow
>
>
> Workflow {
> bean = StandaloneSetup {
> platformUri = "${runtimeProject}/.."
> }
>
> component = DirectoryCleaner {
> directory = "${runtimeProject}/src-gen"
> }
> ..
>
>
> to get the files read you have to add following to YourDslStandaloneSetup
>
>
> @Override
> public void register(Injector injector) {
> super.register(injector);
> org.eclipse.xtext.resource.IResourceServiceProvider.Registry .INSTANCE.getExtensionToFactoryMap().put( "ecore",
> new EcoreResourceServiceProviderImpl());
> }
>
>
> and therefore have to add org.eclipse.xtext.ecore to the plugin
> dependencies.
>
> ~Christian
Re: Resolving proxy when processing xtext model [message #556628 is a reply to message #556626] Thu, 02 September 2010 07:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi did you do that:

Quote:

and therefore have to add org.eclipse.xtext.ecore to the plugin dependencies.



btw i am using the eclipse forum and i missed half of your message
in between i updated my post to

Workflow {
    bean = StandaloneSetup {
		platformUri = ".."
	}



(the runtimeProject stuff and dircleaner was just a copy and past error)

and added a solution when not using a workflow:

new StandaloneSetup ().setPlatformUri("..");
MyDemoStandaloneSetup.doSetup();



~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resolving proxy when processing xtext model [message #556632 is a reply to message #556542] Thu, 02 September 2010 07:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mdsamh.yahoo.com

Hi Jan,

Thanks for your clarification.

It would be really helpful if you could give some more hints on how to use a
URI mapper of resource set to map a platform URI to a file URI.

Few lines of a sample code would be really great.

Thanks in advance



"Jan K
Re: Resolving proxy when processing xtext model [message #556640 is a reply to message #556632] Thu, 02 September 2010 07:45 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
If you start your model reader from a workflow, use the StandaloneSetup
with a platformURI as Christian described above. It maps every file in a
given driectory to a platform URI.

If you're interested in how that works outside a workflow, have a look
at the implementation (the StandaloneSetup class).


Am 02.09.10 09:18, schrieb medo samh:
> Hi Jan,
>
> Thanks for your clarification.
>
> It would be really helpful if you could give some more hints on how to use a
> URI mapper of resource set to map a platform URI to a file URI.
>
> Few lines of a sample code would be really great.
>
> Thanks in advance
>
>
>
> "Jan K�oehnlein"<jan.koehnlein@itemis.de> wrote in message
> news:i5m0gn$ejh$1@build.eclipse.org...
>> You are using a platform:/resource URI, which is only valid form within
>> Eclipse as it refers to projects in the workspace. So it can be linked in
>> the editor, but not in standalone Java code.
>>
>> As an alternative, you could use a relative URI or a classpath:/ URI, or
>> use the URI mapper of your resource set to map the platform:/resource URI
>> to a file URI.
>>
>> Regards
>> Jan
>>
>>
>> Am 01.09.10 15:37, schrieb medo samh:
>>> Hi,
>>>
>>>
>>>
>>> The purpose of my grammar is to manipulate a source .ecore model. In my
>>> grammar, I import Ecore metamodel (http:www.eclipse.org/emf/2002/ecore)
>>> to
>>> type elements of my rules. I also allow importing a source .ecore model,
>>> using importURI = STRING, where I can supply a URI of a source model that
>>> I
>>> intend to manipulate.
>>>
>>> Below is part of my grammar:
>>>
>>> grammar nha.xtext.demo.MyDemo with org.eclipse.xtext.common.Terminals
>>>
>>> generate myDemo "http://www.xtext.nha/demo/MyDemo"
>>>
>>> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
>>>
>>> Model:
>>> imports+=Import*
>>> manipulations+= Manipulations *;
>>> Import:
>>> "import" importURI=STRING;
>>> Manipulations:
>>> "manipulate" class=[ecore::EClass];
>>>
>>> In the editor, I can type
>>>
>>> import "platform:/resource/projectName/folderName/source.ecore"
>>>
>>> manipulate ClassOne
>>>
>>> // assuming ClassOne is an EClass in model source.ecore which I imported
>>>
>>> This gives me an Xtext file with proxy:
>>>
>>> org.eclipse.emf.ecore.impl.EClassImpl@12b4986 (eProxyURI:
>>> model/first.mydemo#xtextLink_:://@manipulations.0::http://ww w.xtext.nha/demo/MyDemo«Manipulations«0::/3)
>>>
>>> In my code, I can load the Xtext file successfully but could not resolve
>>> the
>>> proxy to get the name of ClassOne.
>>>
>>> I load the Xtext file using:
>>>
>>> MyDemoStandaloneSetup.doSetup();
>>>
>>> XtextResourceSet drs = new XtextResourceSet();
>>>
>>> URI uri = URI.createURI("folderName/modelName.mydemo");
>>>
>>> Resource xtextResource = drs.getResource(uri , true);
>>>
>>> Model md = (Model) xtextResource.getContents().get(0);
>>>
>>> xtextResource.load(null)
>>>
>>>
>>>
>>> I try to resolve the proxy using:
>>>
>>> Manipulations manipulations = (Manipulations) manipulations;
>>>
>>> EObject mc = (EObject) manipulations.getClass_();
>>>
>>> if (mc !=null&& mc.eIsProxy()){
>>>
>>> InternalEObject imc =(InternalEObject)mc;
>>>
>>> mc = EcoreUtil.resolve(mc, manipulations);
>>>
>>> }
>>>
>>> This code did not work and I am not sure if this is the right way.
>>>
>>> I am new to xtext and EMF and this problem is stopping me. I would
>>> really
>>> appreciate your advice to go over it.
>>>
>>>
>>>
>>> Thanks in advance
>>>
>>>
>>
>>
>> --
>> Need professional support for Eclipse Modeling?
>> Go visit: http://xtext.itemis.com
>
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:IFragmentProvider NPEs
Next Topic:XTextResource not returned
Goto Forum:
  


Current Time: Thu Apr 25 13:56:09 GMT 2024

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

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

Back to the top