Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Help with Query and OCL
[ATL] Help with Query and OCL [message #665740] Fri, 15 April 2011 16:51 Go to next message
Thanasis Naskos is currently offline Thanasis Naskos
Messages: 22
Registered: March 2011
Junior Member
Hi,

I have an XML file holding parameters, called "parameters.xml":
<parameters>
        <param name="prototypePackage" value="ConcretePackage"/>
	<param name="prototypeClass" value="ConcreteClass1"/>
	<param name="prototypeClass" value="ConcreteClass2"/>
                                              ...
        <param name="prototypeClass" value="ConcreteClassN"/>
</parameters>


I want to make a Query that gets the parameters and produces a file containing the above text:
This is a list with parameters
This is a Class parameter: ConcreteClass1;
This is a Class parameter: ConcreteClass2;
                           ...
This is a  Class parameter: ConcreteClassN;
End of parameters list


I figure out how to get the parameters from the XML but i can't find how to use iteration to produce the text above.

This is the code I have written so far:
query prototypeManager = ('This is a list with parameters'+

		for (c in getConcreteClasses()) {
			'This is a Class parameter: '+c.getAttrVal('value')+';'
		}

+'End of parameters list').writeTo('prototypeTransformation/PrototypeManager.txt');

uses XMLHelpers;

helper def : getConcreteClasses() : Sequence(String) =
	XML!Element.allInstances()->select(e |
		e.name = 'param'
	)->select(e |
		e.getAttrVal('name') = 'prototypeClass');



I'm getting the following error in "for" expression:
no viable alternative at input 'for'
mismatched input '{' expecting SEMI


I'm not used to the ATL and OCL so any help would be appreciated!!

[Updated on: Fri, 15 April 2011 16:55]

Report message to a moderator

Re: [ATL] Help with Query and OCL [message #665771 is a reply to message #665740] Fri, 15 April 2011 20:10 Go to previous messageGo to next message
Thanasis Naskos is currently offline Thanasis Naskos
Messages: 22
Registered: March 2011
Junior Member
I'm close to a solution...

I've changed "for expression" with "collect". Now the code looks like this:
query prototypeManager = ('This is a list with parameters'+

		thisModule.getConcreteClasses()->collect(c | '\nThis is a Class parameter: '+c.getAttrVal('value')+';')

+'\nEnd of parameters list').writeTo('prototypeTransformation/PrototypeManager.txt');

uses XMLHelpers;

helper def : getConcreteClasses() : Sequence(String) =
	XML!Element.allInstances()->select(e |
		e.name = 'param'
	)->select(e |
		e.getAttrVal('name') = 'prototypeClass');


The only problem now is that I'm getting the output with brackets "[" "]"
This is a list with parameters[
This is a Class parameter: ConcreteClass1;
This is a Class parameter: ConcreteClass2;
                           ...
This is a  Class parameter: ConcreteClassN;]
End of parameters list


Is there a way to get rid of those?
Re: [ATL] Help with Query and OCL [message #665919 is a reply to message #665740] Mon, 18 April 2011 07:30 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARD
Messages: 523
Registered: July 2009
Senior Member
you can use an iterate :
thisModule.getConcreteClasses()->iterate(c; res : String = 'This is a list with parameters' | res +  '\nThis is a Class parameter: '+c.getAttrVal('value')+';')+'\nEnd of parameters list').writeTo('prototypeTransformation/PrototypeManager.txt');
Re: [ATL] Help with Query and OCL [message #665958 is a reply to message #665740] Mon, 18 April 2011 11:23 Go to previous messageGo to next message
Thanasis Naskos is currently offline Thanasis Naskos
Messages: 22
Registered: March 2011
Junior Member
Sylvain, THANK you very much!!
Re: [ATL] Help with Query and OCL [message #682319 is a reply to message #665740] Fri, 10 June 2011 20:33 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 1
Registered: June 2011
Junior Member
Hello,

I have a smiliar problem like Thanasis. Unfortunatelly I am not able to solve it.

This is my XML File (shortened):
<?xml version="1.0" encoding="ISO-8859-1"?>
<MYFILE xmi:version="2.0" xmlns:xmi="http:..." xmlns:xsi="..." xmlns="...">
  <root>
     <incl name="MainItem">
		<incl name="Item1">
		</incl>
		<inclname="Item2">
		</incl>
		<incl name="Item">
		</incl>
	</incl>
  </root>
</MYFILE>


And this is what I want to produce:
<?xml version="1.0" encoding="UTF-8"?>
  <MainItem>
    <item1>
    </Item1>
	<item2>
    </Item2>
	<item3>
    </Item3>
  </MainItem>


Tried so start like Thanasis for the MainItem, but output is just "This is a list with parameters"..
query now = thisModule.getConcreteClasses()->iterate(c; res : String = 'This is a list with parameters' | res +  '\nThis is a Class parameter: '+c.getAttrVal('name')+';'+'\nEnd of parameters list').writeTo('fu.txt');


helper def : getConcreteClasses() : Sequence(String) =
	XML!Element.allInstances()->select(e |e.name = 'incl')->select(e |e.getAttrVal('name') = 'MainItem');


Sitting here since hours for a couple of transformations - Cannot find a solution to this one. Anybody can help?

[Updated on: Fri, 10 June 2011 20:49]

Report message to a moderator

Re: [ATL] Help with Query and OCL [message #682337 is a reply to message #682319] Fri, 10 June 2011 20:48 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4098
Registered: July 2009
Senior Member
Hi

Why would you think that getConcreteClasses() can return a Sequence(String)?

Regards

Ed Willink

On 10/06/2011 21:33, forums-noreply@eclipse.org wrote:
> Hello,
>
> I have a smiliar problem like Thanasis. Unfortunatelly I am not able
> to solve it.
>
> This is my XML File (shortened):
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <MYFILE xmi:version="2.0" xmlns:xmi="http:..." xmlns:xsi="..."
> xmlns="...">
> <root>
> <incl name="MainItem">
> <incl name="Item1">
> </incl>
> <inclname="Item2">
> </incl>
> <incl name="Item">
> </incl>
> </incl>
> </root>
> </MYFILE>
>
>
> And this is what I want to produce:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <MainItem>
> <item1>
> </Item1>
> <item2>
> </Item2>
> <item3>
> </Item3>
> </MainItem>
>
>
> Tried so start like Thanasis for the MainItem, but output is just
> "This is a list with parameters"..
>
> query now = thisModule.getConcreteClasses()->iterate(c; res : String =
> 'This is a list with parameters' | res + '\nThis is a Class
> parameter: '+c.getAttrVal('name')+';'+'\nEnd of parameters
> list').writeTo('fu.txt');
>
>
> helper def : getConcreteClasses() : Sequence(String) =
> XML!Element.allInstances()->select(e |e.name = 'incl')->select(e
> |e.getAttrVal('name') = 'MainItem');
>
>
> Sitting here since 12 hours for a couple of transformations - Cannot
> find a solution to this one. Anybody can help?
Previous Topic:[QVTO] Substitute to ResolverUtils.createUnitProxy
Next Topic:[ATL] Multiple input with references
Goto Forum:
  


Current Time: Sat Oct 25 21:30:55 GMT 2014

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

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