Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Nested model transformation(How to create a transformation that calls N transformation on N models...)
icon5.gif  [Acceleo] Nested model transformation [message #643784] Wed, 08 December 2010 09:44 Go to next message
Cedric Gava is currently offline Cedric Gava
Messages: 41
Registered: July 2009
Member
Hello,

I must do the following transformation :

My transformation (T1) shall be runned on a model (M1) conforms to a metamodel (MM)... in this model, there is a list of file (FL), and a template (T2) shall be run onto each file to produce content for my first transformation.
Length of FL is N, and, each file of FL is a serialization of models that conforms to MM

So, in summary :

  1. T1 produces one File, using M1 model and (T2) on N other models listed in M1
  2. T2 does not produce a file
  3. Every model conforms to the same MM metamodel


I don't know how to do that...
Shall I use T2 with java API, and encapsulate the java methods that calls T2 in a query/template, with a string=filename parameter, to be able to reuse it in my transformation ?

Any clue would be very very appreciable.

Best regards



sooo lonely friends of eclipse on forum
http://www.eclipse.org/donate/images/friendslogo160.jpg
Re: [Acceleo] Nested model transformation [message #643804 is a reply to message #643784] Wed, 08 December 2010 10:48 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020905030007020402070000
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Cedric,

I couldn't really grasp what you want to do, and since I see no
difficulty in doing what I understood, I believe I understood the wrong
thing :p.

You can have module M1 containing templates T1 and T2, T1 being the
"[@main]" template, applied on your "Model" Object, and containing a
[file] block in which it will iterate on the "files" references and call
T2 on each...

[module mod(...)]

[template T1(m : Model)]
[comment @main /]
[file (...)]
[for (file : FL | m.files)]
[file.T2()/]
[/for]
[/file]
[/template]

[template T2(file : FL)]
....
[/template]

Wouldn't that do the trick?

Laurent

On 08/12/2010 10:44, Cedric Gava wrote:
> Hello,
>
> I must do the following transformation :
>
> My transformation (T1) shall be runned on a model (M1) conforms to a
> metamodel (MM)... in this model, there is a list of file (FL), and a
> template (T2) shall be run onto each file to produce content for my
> first transformation.
> Length of FL is N, and, each file of FL is a serialization of models
> that conforms to MM
>
> So, in summary :
>
> T1 produces one File, using M1 model and (T2) on N other models listed
> in M1
> T2 does not produce a file
> Every model conforms to the same MM metamodel
>
>
> I don't know how to do that...
> Shall I use T2 with java API, and encapsulate the java methods that
> calls T2 in a query/template, with a string=filename parameter, to be
> able to reuse it in my transformation ?
>
> Any clue would be very very appreciable.
>
> Best regards
>
>


--------------020905030007020402070000
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------020905030007020402070000--
Re: [Acceleo] Nested model transformation [message #643819 is a reply to message #643804] Wed, 08 December 2010 11:52 Go to previous messageGo to next message
Cedric Gava is currently offline Cedric Gava
Messages: 41
Registered: July 2009
Member
Hi Laurent,

Quote:
[template T2(file : FL)]
....
[/template]

Wouldn't that do the trick?


I don't think so... because the parameter file is a string (indeed, a filename) pointing to a real file (a ressource in eclipse terminology)...
This ressource is a serialization of a Model,

So, what I expect the template T2 to do is :


  1. open the file pointed by 'file' string
  2. the file shall be of MM metamodel
  3. if there is a problem opening this file, or the content of the file is not a valid serialization of MM metamodel, raise an error and return empty string
  4. else, run a T3 template on it and return the result of this template



Do you catch up ?
Let me know if you want me to create a more detailed example ?

Kind regards


sooo lonely friends of eclipse on forum
http://www.eclipse.org/donate/images/friendslogo160.jpg
Re: [Acceleo] Nested model transformation [message #643864 is a reply to message #643819] Wed, 08 December 2010 13:58 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000009040306010107070805
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

So that's what I didn't understand :).

Unfortunately, there is no simple way of doing what you seek, you'll
have to call from T2 a Java service in charge of loading the model and
check for errors, then return it. You can do something similar to
(passing an EObject as parameter of the service is not mandatory, but I
recommend it in order to share the same resource set between the model
you load and the model Acceleo is currently iterating on) :

-----

public EObject loadModel(EObject current, String filePath) {
ResourceSet rs = current.eResource().getResourceSet();
Resource res = rs.getResource(filePath);
if (res != null && res.getErrors().isEmpty()) {
if (!res.getContents().isEmpty()) {
return res.getContents().get(0);
}
}
// either the resource is empty, there wasn't any resource at that
location, or there were errors loading it
return null;
}

-----

And, in your template :

[public template T2(model : Model, file : String)]
[let model : OclAny = loadModel(model, file)]
[if (model.isUndefined())]
[T3()/]
[else]
[doSomethingWithModel(model)/]
[/if]
[/let]
[/template]

Laurent Goubet
Obeo

On 08/12/2010 12:52, Cedric Gava wrote:
> Hi Laurent,
> Quote:
>> [template T2(file : FL)]
>> ....
>> [/template]
>>
>> Wouldn't that do the trick?
>
>
> I don't think so... because the parameter file is a string (indeed, a
> filename) pointing to a real file (a ressource in eclipse
> terminology)... This ressource is a serialization of a Model,
>
> So, what I expect the template T2 to do is :
>
>
> open the file pointed by 'file' string
> the file shall be of MM metamodel
> if there is a problem opening this file, or the content of the file is
> not a valid serialization of MM metamodel, raise an error and return
> empty string
> else, run a T3 template on it and return the result of this template
>
>
>
> Do you catch up ?
> Let me know if you want me to create a more detailed example ?
>
> Kind regards


--------------000009040306010107070805
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------000009040306010107070805--
Re: [Acceleo] Nested model transformation [message #643867 is a reply to message #643864] Wed, 08 December 2010 14:25 Go to previous messageGo to next message
Cedric Gava is currently offline Cedric Gava
Messages: 41
Registered: July 2009
Member
Thank you, I'll do this and tell you hiw successfull I am

sooo lonely friends of eclipse on forum
http://www.eclipse.org/donate/images/friendslogo160.jpg
Re: [Acceleo] Nested model transformation [message #644261 is a reply to message #643867] Fri, 10 December 2010 09:58 Go to previous messageGo to next message
Cedric Gava is currently offline Cedric Gava
Messages: 41
Registered: July 2009
Member
Hi Laurent...

The thing goes in the right way :

I've created the service, and invoke it from a template :
[let model : OclAny = loadModel(c.oclAsType(ecore::EObject), 'filename.xml')]
		[if (model.oclIsUndefined())]
Cannot load model from file !!!
		[else]
Model is defined !!!		
		[/if]
	[/let]



but, when it returns null, I got an exception :

Quote:
!ENTRY org.eclipse.ocl 4 10 2010-12-10 10:44:40.914
!MESSAGE ERROR in (visitOperationCallExp): (null)
!STACK 0
org.eclipse.acceleo.engine.AcceleoEvaluationException
at org.eclipse.acceleo.engine.internal.environment.AcceleoLibra ryOperationVisitor.invoke(AcceleoLibraryOperationVisitor.jav a:926)
at org.eclipse.acceleo.engine.internal.environment.AcceleoLibra ryOperationVisitor.callNonStandardOperation(AcceleoLibraryOp erationVisitor.java:119)
at org.eclipse.acceleo.engine.internal.environment.AcceleoEvalu ationEnvironment.callOperation(AcceleoEvaluationEnvironment. java:167)
at org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.callOperati on(EcoreEvaluationEnvironment.java:1)
at org.eclipse.ocl.EvaluationVisitorImpl.visitOperationCallExp( EvaluationVisitorImpl.java:193)




sooo lonely friends of eclipse on forum
http://www.eclipse.org/donate/images/friendslogo160.jpg
Re: [Acceleo] Nested model transformation [message #644263 is a reply to message #644261] Fri, 10 December 2010 10:05 Go to previous messageGo to next message
Cedric Gava is currently offline Cedric Gava
Messages: 41
Registered: July 2009
Member
Shocked Forget my previous message, it seems that the error comes from my service itself rather than the call to it...

sooo lonely friends of eclipse on forum
http://www.eclipse.org/donate/images/friendslogo160.jpg
Re: [Acceleo] Nested model transformation [message #644285 is a reply to message #644263] Fri, 10 December 2010 11:46 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040209080903080703030403
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Cedric,

Yes, there's a good chance this exception is due to Acceleo handling an
exception that was thrown by the service itself. If everything went
"right" on that matter, you should find the real cause of the exception
in the "caused by:" section of the trace you see logged.

Laurent Goubet
Obeo

On 10/12/2010 11:05, Cedric Gava wrote:
> 8o Forget my previous message, it seems that the error comes from my
> service itself rather than the call to it...


--------------040209080903080703030403
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------040209080903080703030403--
Re: [Acceleo] Nested model transformation [message #644293 is a reply to message #644285] Fri, 10 December 2010 12:37 Go to previous messageGo to next message
Cedric Gava is currently offline Cedric Gava
Messages: 41
Registered: July 2009
Member
Yes you are right, it is caused by :
org.eclipse.core.internal.resources.ResourceException: Resource 'xxxxx' does not exist

when calling :
rs.getResource(uri, true);


If I set the option to false, then I don't get the exception...



sooo lonely friends of eclipse on forum
http://www.eclipse.org/donate/images/friendslogo160.jpg
Re: [Acceleo] Nested model transformation [message #644296 is a reply to message #644293] Fri, 10 December 2010 12:46 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010304000600080408010304
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Cedric,

the boolean you pass to "getResource" tells EMF to load it from disc if
it isn't already present in the resource set. Some of the resources you
need may already be in the resource set, but not all (or so I think).

The exception "Resource does not exist" means that EMF couldn't manage
to find a file corresponding to the given path. Is that not a problem in
itself, or are you expecting some of the files not to be there?

Either way, having it set to "false" will make it so that EMF will never
try and load the resource, I believe you need something a little smarter
(such as "if (new File(path).exists()) then load else nothing). That
depends on what you need though.

Laurent Goubet
Obeo

On 10/12/2010 13:37, Cedric Gava wrote:
> Yes you are right, it is caused by :
> org.eclipse.core.internal.resources.ResourceException: Resource 'xxxxx'
> does not exist
> when calling :
> rs.getResource(uri, true);
>
> If I set the option to false, then I don't get the exception...
>
>


--------------010304000600080408010304
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------010304000600080408010304--
Re: [Acceleo] Nested model transformation [message #644323 is a reply to message #644285] Fri, 10 December 2010 14:28 Go to previous messageGo to next message
Cedric Gava is currently offline Cedric Gava
Messages: 41
Registered: July 2009
Member
I'm stuck with URI problems. Damn, I lack skills in general eclipse programming, and I feel It hard by this time...
I want to know the name of the project associated with the EObject passed as parameter...

Resource res = rs.getResources().get(0);
IProject iProject =  getWorkspaceRoot().getFile(new Path(res.getURI().toString())).getProject();


give me "C:" as project... Mad


sooo lonely friends of eclipse on forum
http://www.eclipse.org/donate/images/friendslogo160.jpg
Re: [Acceleo] Nested model transformation [message #644349 is a reply to message #644323] Fri, 10 December 2010 16:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4046
Registered: July 2009
Senior Member
Hi Cedric

Your code is similar but not identical to the logic in
EditUIUtil.openEditor(EObject). You might want to see if you covered all
the cases.

It would seem useful to have an EditUIUtil.getFile(EObject) method.
Perhaps you could contribute.

Regards

Ed Willink


On 10/12/2010 14:28, Cedric Gava wrote:
> I'm stuck with URI problems. Damn, I lack skills in general eclipse
> programming, and I feel It hard by this time...
> I want to know the name of the project associated with the EObject
> passed as parameter...
>
>
> Resource res = rs.getResources().get(0);
> IProject iProject = getWorkspaceRoot().getFile(new
> Path(res.getURI().toString())).getProject();
>
> give me "C:" as project... :x
Re: [Acceleo] Nested model transformation [message #644666 is a reply to message #644349] Mon, 13 December 2010 17:10 Go to previous messageGo to next message
Cedric Gava is currently offline Cedric Gava
Messages: 41
Registered: July 2009
Member
Hi Edward....

I would be pleased to contribute, but you will have to drive me a little, as I'm very far away from being an eclipse developper...


1st - I don't understand clearly the implementation of EditUIUtil.EclipseUtil...
for instance, I don't see why "fileClass = IFile.class" would rise an exception...
Since the EditUIUtil.java imports "org.eclipse.core.resources.IFile", why would the JVM do not know about IFile.class ??

2nd - Here we go in EclipseUtil.getURI(), where, according to the classes "known", the URI of editorInput is calculated :

  1. if editorInput has been adapted to an IFile, then we use it's IFile adaptation to compute a PlatformURI
  2. else if ... adapted to a certain FILE_REVISION_CLASS, then we call a certain FILE_REVISION_GET_URI_METHOD to compute URI
  3. else if ... is an instance of IURIEditorInput, then we call the getURI() method of IURIEditorInput
  4. else return a null URI


What I understand here :

  1. either the editorInput object can be adapted to a class that we know how to compute its URI (file, fileRevision)
  2. either the editorInput is an instance of URIEditorInput class, that already have a getURI() Method

If we are not in thoses 2 cases, then we don't know how to cumpute URI of this kind of IEditorInput

3nd
- What method shall I do?
public static URI getURI(EObject eObject){
  Resource res = eObject.eResource();
  if (res!= null) return eObject.eResource().getURI();
  return null
}

public static IFile GetFile(EObject eObject){
  URI u = getURI(eObject);
  if (u!= null){
    if (u is a file URI) then return a Ifile ??
  }
}


4th - Is a IFile necessary in an eclipse workspace (or it can be outside ) ?
What do I miss ?

Kind regards


sooo lonely friends of eclipse on forum
http://www.eclipse.org/donate/images/friendslogo160.jpg
Re: [Acceleo] Nested model transformation [message #644780 is a reply to message #644666] Tue, 14 December 2010 08:40 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030808060504080608070000
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Cedric,

Before going into this whole process, let's see the basic information :
which form do your "strings" look like? (The strings representing the
location of the models you wish to load.)

As Ed mentionned, there are numerous cases to take into account when
trying to load models... but there usually is no need for all of them in
our uses cases. You probably only need to handle the case where models
are in your workspace or models in your plugins.

You could also add a dependency from your plugin to
org.eclipse.acceleo.common, and simply try and use
ModelUtils.load(String, ResourceSet) to check whether this utility
method we use throughout Acceleo wouldn't do the trick for you.

Laurent Goubet
Obeo

On 13/12/2010 18:10, Cedric Gava wrote:
> Hi Edward....
>
> I would be pleased to contribute, but you will have to drive me a
> little, as I'm very far away from being an eclipse developper...
>
>
> 1st - I don't understand clearly the implementation of
> EditUIUtil.EclipseUtil...
> for instance, I don't see why "fileClass = IFile.class" would rise an
> exception...
> Since the EditUIUtil.java imports "org.eclipse.core.resources.IFile",
> why would the JVM do not know about IFile.class ??
>
> 2nd - Here we go in EclipseUtil.getURI(), where, according to the
> classes "known", the URI of editorInput is calculated :
>
> if editorInput has been adapted to an IFile, then we use it's IFile
> adaptation to compute a PlatformURI
> else if ... adapted to a certain FILE_REVISION_CLASS, then we call a
> certain FILE_REVISION_GET_URI_METHOD to compute URI
> else if ... is an instance of IURIEditorInput, then we call the getURI()
> method of IURIEditorInput
> else return a null URI
>
>
> What I understand here :
>
> either the editorInput object can be adapted to a class that we know how
> to compute its URI (file, fileRevision)
> either the editorInput is an instance of URIEditorInput class, that
> already have a getURI() Method
> If we are not in thoses 2 cases, then we don't know how to cumpute URI
> of this kind of IEditorInput
>
> 3nd - What method shall I do?
> public static URI getURI(EObject eObject){
> Resource res = eObject.eResource();
> if (res!= null) return eObject.eResource().getURI();
> return null
> }
>
> public static IFile GetFile(EObject eObject){
> URI u = getURI(eObject);
> if (u!= null){
> if (u is a file URI) then return a Ifile ??
> }
> }
>
> 4th - Is a IFile necessary in an eclipse workspace (or it can be outside
> ) ?
> What do I miss ?
>
> Kind regards


--------------030808060504080608070000
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------030808060504080608070000--
Re: [Acceleo] Nested model transformation [message #644801 is a reply to message #644780] Tue, 14 December 2010 09:45 Go to previous messageGo to next message
Cedric Gava is currently offline Cedric Gava
Messages: 41
Registered: July 2009
Member
Hi Laurent...


My strings (filepath) is a path to a file relative to the current project...My code is below. It works today, but there are still , at least, 2 weaknesses :


  1. Adding a / at workspace Path, to get sure it is completely stripped from the file full path, when calling URI.deresolve(getWorkspaceURI())
  2. Resource res = rs.getResource(uri, true), can raise an exception if file is not present in the project, and since getResource is not declared as an Exception thrower, and don't know how to catch it


I'm looking at ModelUtils.load(String, ResourceSet).
My goal now is to master URI/Ressource programming... to get sure, after that, that I will be at ease with these concepts.

What do you think of it ?
Kind regards

	private static IWorkspaceRoot getWorkspaceRoot() throws Exception {
		if (workspaceRoot==null){
			workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
			if (workspaceRoot==null) throw  new  Exception("No workspace defined, running outside of eclipse is forbidden"); 
		}		
		return  workspaceRoot;
	}

	private static URI getWorkspaceURI() throws Exception {
		if (workspaceURI==null){
			workspaceURI = URI.createFileURI(getWorkspaceRoot().getLocationURI().getPath() + "/");
    }		
		return  workspaceURI;
	}
	
	public static EObject loadModel(EObject current, String filePath) throws Exception {
	     ResourceSet rs = current.eResource().getResourceSet();
	     Resource res = current.eResource();
	     if (res != null){
	    	 URI u = res.getURI().deresolve(getWorkspaceURI());	    
         return loadModel(rs, filePath, u.segment(0).toString());
	     }
	     return null; 
	}
	
	public static EObject loadModel(ResourceSet rs, String filePath, String project) {
		   URI uri = URI.createURI(uriString, true);		 
                   Resource res = rs.getResource(uri, true);

	     if (res != null && res.getErrors().isEmpty()) {
	         if (!res.getContents().isEmpty()) {
	             return res.getContents().get(0);
	         }
	     }	     			 
	     return null;
	}


sooo lonely friends of eclipse on forum
http://www.eclipse.org/donate/images/friendslogo160.jpg
Re: [Acceleo] Nested model transformation [message #644856 is a reply to message #644801] Tue, 14 December 2010 13:49 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26058
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000602070305090903010008
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Cedric,

Comments below.


Cedric Gava wrote:
> Hi Laurent...
>
>
> My strings (filepath) is a path to a file relative to the current
> project...My code is below. It works today, but there are still , at
> least, 2 weaknesses :
>
> Adding a / at workspace Path, to get sure it is completely stripped
> from the file full path, when calling URI.deresolve(getWorkspaceURI())
> Resource res = rs.getResource(uri, true), can raise an exception if
> file is not present in the project, and since getResource is not
> declared as an Exception thrower, and don't know how to catch it
Use RuntimeException.
>
>
> I'm looking at ModelUtils.load(String, ResourceSet).
> My goal now is to master URI/Ressource programming... to get sure,
> after that, that I will be at ease with these concepts.
Learn about platform:/resource URIs.

2.44 How do I map between an EMF Resource and an Eclipse IFile?
< http://wiki.eclipse.org/index.php/EMF/FAQ#How_do_I_map_betwe en_an_EMF_Resource_and_an_Eclipse_IFile.3F>

>
> What do you think of it ?
> Kind regards
>
> private static IWorkspaceRoot getWorkspaceRoot() throws Exception {
> if (workspaceRoot==null){
> workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
> if (workspaceRoot==null) throw new Exception("No
> workspace defined, running outside of eclipse is forbidden");
> }
> return workspaceRoot;
> }
>
> private static URI getWorkspaceURI() throws Exception {
> if (workspaceURI==null){
> workspaceURI =
> URI.createFileURI(getWorkspaceRoot().getLocationURI().getPat h() + "/");
> }
> return workspaceURI;
> }
>
> public static EObject loadModel(EObject current, String filePath)
> throws Exception {
> ResourceSet rs = current.eResource().getResourceSet();
> Resource res = current.eResource();
> if (res != null){
> URI u = res.getURI().deresolve(getWorkspaceURI());
> return loadModel(rs, filePath, u.segment(0).toString());
> }
> return null; }
>
> public static EObject loadModel(ResourceSet rs, String filePath,
> String project) {
> URI uri = URI.createURI(uriString, true);
> Resource res = rs.getResource(uri, true);
>
> if (res != null && res.getErrors().isEmpty()) {
> if (!res.getContents().isEmpty()) {
> return res.getContents().get(0);
> }
> } return null;
> }

--------------000602070305090903010008
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Cedric,<br>
<br>
Comments below.<br>
<br>
<br>
Cedric Gava wrote:
<blockquote cite="mid:ie7e2g$p92$1@news.eclipse.org" type="cite">Hi
Laurent...
<br>
<br>
<br>
My strings (filepath) is a path to a file relative to the current
project...My code is below. It works today, but there are still , at
least, 2 weaknesses :
<br>
      <br>
Adding a / at workspace Path, to get sure it is completely stripped
from the file full path, when calling URI.deresolve(getWorkspaceURI())
<br>
 Resource res = rs.getResource(uri, true), can raise an exception if
file is not present in the project, and since getResource is not
declared as an Exception thrower, and don't know how to catch it
<br>
</blockquote>
Use RuntimeException.<br>
<blockquote cite="mid:ie7e2g$p92$1@news.eclipse.org" type="cite"><br>
<br>
I'm looking at ModelUtils.load(String, ResourceSet).
<br>
My goal now is to master URI/Ressource programming... to get sure,
after that, that I will be at ease with these concepts.
<br>
</blockquote>
Learn about platform:/resource URIs.<br>
<blockquote><a
href=" http://wiki.eclipse.org/index.php/EMF/FAQ#How_do_I_map_betwe en_an_EMF_Resource_and_an_Eclipse_IFile.3F"><span
class="tocnumber">2.44</span> <span class="toctext">How do I map
between an EMF Resource and an Eclipse IFile?</span></a><br>
</blockquote>
<blockquote cite="mid:ie7e2g$p92$1@news.eclipse.org" type="cite"><br>
What do you think of it ?
<br>
Kind regards
<br>
<br>
    private static IWorkspaceRoot getWorkspaceRoot() throws Exception {
<br>
        if (workspaceRoot==null){
<br>
            workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
<br>
            if (workspaceRoot==null) throw  new  Exception("No
workspace defined, running outside of eclipse is forbidden");        
}        <br>
        return  workspaceRoot;
<br>
    }
<br>
<br>
    private static URI getWorkspaceURI() throws Exception {
<br>
        if (workspaceURI==null){
<br>
            workspaceURI =
URI.createFileURI(getWorkspaceRoot().getLocationURI().getPat h() + "/");
<br>
   }        <br>
        return  workspaceURI;
<br>
    }
<br>
    
<br>
    public static EObject loadModel(EObject current, String filePath)
throws Exception {
<br>
         ResourceSet rs = current.eResource().getResourceSet();
<br>
         Resource res = current.eResource();
<br>
         if (res != null){
<br>
             URI u = res.getURI().deresolve(getWorkspaceURI());       
        return loadModel(rs, filePath, u.segment(0).toString());
<br>
         }
<br>
         return null;     }
<br>
    
<br>
    public static EObject loadModel(ResourceSet rs, String filePath,
String project) {
<br>
           URI uri = URI.createURI(uriString, true);        
                  Resource res = rs.getResource(uri, true);
<br>
<br>
         if (res != null &amp;&amp; res.getErrors().isEmpty()) {
<br>
             if (!res.getContents().isEmpty()) {
<br>
                 return res.getContents().get(0);
<br>
             }
<br>
         }                               return null;
<br>
    }
<br>
</blockquote>
</body>
</html>

--------------000602070305090903010008--
Previous Topic:[Acceleo 3] continuous integration on acceleo projects
Next Topic:[Xpand & Xtend] OCL to Java
Goto Forum:
  


Current Time: Mon Sep 22 16:16:13 GMT 2014

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

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