Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Navigating a non-navigable (one way) association(Is it possible to navigate along a non-navigable (one way) association?)
icon5.gif  Navigating a non-navigable (one way) association [message #694498] Fri, 08 July 2011 13:54 Go to next message
Mark Sluser is currently offline Mark Sluser
Messages: 15
Registered: June 2011
Location: Calgary
Junior Member
I have the following XML model:


MultiBlock
     Block
          BlockDef
               Parameters
                    Parameter
          EmbBlocks
               Block
                    BlockDef
               Block
                    BlockDef




Block must contain BlockDef
Block can contain EmbBlocks
EmbBlocks can contain Block


I want to select all the Block objects contained in the EmbBlock object if the top level BlockDef has certain values.

I was trying

context MultiBlock
block.embBlocks->excluding(null).block->select(this.block.blockDef.templateName='SYSTEM:CPM200')



but this fails.

Evaluating:
block.embBlocks->excluding(null).block->select(this.block.blockDef.templateName='SYSTEM:CPM200')
Results:
Parsing failure
null
Unresolved property 'block' for 'unknown-type'
Unresolved property 'embBlocks' for 'OclInvalid'
Unresolved property 'block' for 'Set<OclInvalid>'
Unresolved property 'this' for 'Bag<OclInvalid>'
Unresolved property 'block' for 'OclInvalid'
Unresolved property 'blockDef' for 'OclInvalid'
Unresolved property 'templateName' for 'OclInvalid'
Unresolved property 'block' for 'Bag<OclInvalid>'



Because the model is XML it does not contain opposite navigations
IE, I can't navigate from BlockDef up to its container Block.

Does OCL have the capability to select objects based on a condition that must be computed from on a non-navigable (one way) association? How do I reference back to the starting context?

I was thinking:

context MultiBlock
block.embBlocks->excluding(null).block->select(<<embBlocks_opposite>>.<<block_opposite>>.block.blockDef.templateName='SYSTEM:CPM200')




what would be a query that works?

This query is going to feed a QVTO transform.

Thank you,

-Mark
Re: Navigating a non-navigable (one way) association [message #694528 is a reply to message #694498] Fri, 08 July 2011 15:08 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3842
Registered: July 2009
Senior Member
Hi

Navigation of unnavigable opposites is an optional compliance point for OCL.

This is available from the Indigo release onwards. See "Customizing
Hidden Opposite Lookup and Navigation" in the OCL Documentation.

Navigation of hidden opposites can be expensive. It is usually better to
build a source match in an alternate order that is better defined.

Regards

Ed Willink

On 08/07/2011 18:54, Mark Sluser wrote:
> I have the following XML model:
>
>
>
> MultiBlock
> Block
> BlockDef
> Parameters
> Parameter
> EmbBlocks
> Block
> BlockDef
> Block
> BlockDef
>
>
>
>
> Block must contain BlockDef
> Block can contain EmbBlocks
> EmbBlocks can contain Block
>
>
> I want to select all the Block objects contained in the EmbBlock
> object if the top level BlockDef has certain values.
>
> I was trying
>
>
> context MultiBlock
> block.embBlocks->excluding(null).block->select(this.block.blockDef.templateName='SYSTEM:CPM200')
>
>
>
>
> but this fails.
>
>
> Evaluating:
> block.embBlocks->excluding(null).block->select(this.block.blockDef.templateName='SYSTEM:CPM200')
>
> Results:
> Parsing failure
> null
> Unresolved property 'block' for 'unknown-type'
> Unresolved property 'embBlocks' for 'OclInvalid'
> Unresolved property 'block' for 'Set<OclInvalid>'
> Unresolved property 'this' for 'Bag<OclInvalid>'
> Unresolved property 'block' for 'OclInvalid'
> Unresolved property 'blockDef' for 'OclInvalid'
> Unresolved property 'templateName' for 'OclInvalid'
> Unresolved property 'block' for 'Bag<OclInvalid>'
>
>
>
> Because the model is XML it does not contain opposite navigations
> IE, I can't navigate from BlockDef up to its container Block.
>
> Does OCL have the capability to select objects based on a condition
> that must be computed from on a non-navigable (one way) association?
> How do I reference back to the starting context?
>
> I was thinking:
>
>
> context MultiBlock
> block.embBlocks->excluding(null).block->select(<<embBlocks_opposite>>.<<block_opposite>>.block.blockDef.templateName='SYSTEM:CPM200')
>
>
>
>
>
> what would be a query that works?
>
> This query is going to feed a QVTO transform.
>
> Thank you,
>
> -Mark
Re: Navigating a non-navigable (one way) association [message #694547 is a reply to message #694528] Fri, 08 July 2011 15:48 Go to previous messageGo to next message
Mark Sluser is currently offline Mark Sluser
Messages: 15
Registered: June 2011
Location: Calgary
Junior Member
Thank you Ed for your reply.

Can you make some suggestions on how I might get a collection of objects that depend on the attributes of parent node or sibling?

Something in XPath would be

select="Block/EmbBlocks/Block[../../BlockDef/templateName='SYSTEM:CPM200']"

Thank you,

-Mark



Re: Navigating a non-navigable (one way) association [message #694554 is a reply to message #694547] Fri, 08 July 2011 15:57 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3842
Registered: July 2009
Senior Member
Hi Mark

Try "select()" and "or".

Regards

Ed Willink

On 08/07/2011 20:48, Mark Sluser wrote:
> Thank you Ed for your reply.
>
> Can you make some suggestions on how I might get a collection of
> objects that depend on the attributes of parent node or sibling?
>
> Something in XPath would be
>
> select="Block/EmbBlocks/Block[../../BlockDef/templateName='SYSTEM:CPM200']"
>
>
> Thank you,
>
> -Mark
>
>
>
>
Re: Navigating a non-navigable (one way) association [message #694562 is a reply to message #694554] Fri, 08 July 2011 16:46 Go to previous message
Mark Sluser is currently offline Mark Sluser
Messages: 15
Registered: June 2011
Location: Calgary
Junior Member
Ahhh I get it.

Here is my new query:

context MultiBlock
block->select(blockDef.templateName='SYSTEM:CPM200').embBlocks.block.blockDef



Thank you for your help.

I am just new to this OCL thing and I have 10s of hours trying to figure out what is possible or not worth its time. Ed you helped me understand that what I was doing was possible with OCL so thank you.

-Mark
Previous Topic:OCL Interactive Query fails for large file
Next Topic:oclAsType for external classes
Goto Forum:
  


Current Time: Thu Apr 17 14:24:04 EDT 2014

Powered by FUDForum. Page generated in 0.03969 seconds