[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmt] Re: [MOFScript]How to write this loop in MOFScript

Hello,
When it comes to the metamodel,it's a long story to tell.As I posted before,there are four elements(N,K,S,G) which inherit an abstract class called Objects.N also contains other Objects including itself.Besides there is another class C which connects other four elements and is also contained in N. N and K can be connected by only one incoming C and one outgoing C. S has only one incoming C and more than one outgoing C. Conversely,G can hava more than one incoming C and only one outgoing C.So now imagine those elements are connected in the following simple sequence:


K
|
S
/ | \
c1 c2 c3
\ | /
G
|
N
As shown in the graph,S has 3 outports ,G has 3 inports.
Now I wanna print them into code,like:
connect K->S
connect S.outport[1]->c1->G.inport[1]
connect S.outport[2]->c2->G.inport[2]
connect S.outport[3]->c3->G.inport[3]
connect G->N
It's easier When iterate elements with only one incoming C and outgoing C.I write code like this:
in the context of N.(objects stands for reference from N to Objects)
----------------------------------------
self.objects->forEach(o:Objects){
if(o.outgoingC!=null){
if(!o.oclIsTypeOf(S)){
o.name ' -> ' o.outgoingC.first().name ' -> '
}
----------------------------------
but when it iterate to S ,the' connect ' statement should split into 3 lines, and it's getting hard to get access to objects of C because C is not Objects and has different containment relations to N. and when print branchs of S,the printed statement should stop at G.


So , generally,the metamodel is like this and my purpose is also restated.I don't know if this makes you more confused or a little bit clearer.If you still need more detail,just tell me ,thank you for your kind help!


Ye