Redefine reference within SmartReference concept to point to an existing node

 Hi,

I want to create some nodes within an intention. One of the nodes is a SmartReference which should point to an already created node (the existing target node is known in the context of the intention).

My attempt was a simple assignment operation, however, the target node is detached from the existing smart reference when the new one is created. Currently, I am not sure if I just misunderstand the idea of using references and copying then.

My questions are:

- Is it possible to rearrange references in existing nodes (by code within intentions) to point to other existing nodes?

- is it possible to copy a SmartReference-Node in a way that the new node points to the same existing node like the old one?

 

 

Thank you in advance,

Henning

 

8 comments

All that what you are saying should be easily possible.

Imagine you have a Concept 'Target' and one called "SmartRef".

The SmartRef one has a reference 'target : Target'.

So, in you intention, you can do something like this:

node<SmartRef> smartRefNew = new node<SmartRef>();

smartRefNew.target.set(myExistingTarget);

Naturally, you can refer to the same node several times.

If you just want to copy a existing instance of SmartRef, you can just call 'copy' on that node.

Post some code if this does not seem to work for you.

0

Hi Robert,

thanks, I think this works now. 

However, the problem with a reference out of search scope remains in the following scenario

node<SmartRef> smartRefNew = new node<SmartRef>();

smartRefNew.target.set(myExistingTarget);

node<HasSmartRefAsChild> newNode = new node<HasSmartRefAsChild>();

newNode.referenceChild.set(smartRefNew);

//doing addtional things on newNode

node<HasChildList> node = new node<HasChildList>();

node.childList.addLast(newNode);

I want to add some nodes of concept HasSmartRefAsChild to another node (HasSmartRefAsChild is not a root concept). After executing this code snippet, the node explorer for existingNode shows the intended structure. However, there is still an out of search scope error. 

Am I required to explicitly deconstruct the newNode because the addLast concept copies it and the original node gets lost?

 

Thank you in advance,

Henning

0

The out of search scope error indicates that myExistingTarget is not in the same or imported model or violates scoping rules for SmartRef.


Vaclav

0

Hi Vaclav,

The target concept of the reference of SmartRef is defined in an other language.

I think this is the case you mentioned. Currently, my dependency structure is the following:

  • The language defining the SmartRef concept (lang. A) has a dependency declaration to the language which defines the reference target concept (lang B) with default scope
  • Each of the language aspects of A declares a dependency to the corresponding aspects of B

Are there missing declarations in the dependency structure?

 

Regards,

Henning

 

0

To avoid misunderstanding, when and in what code do you see the "out of scope" error?

Vaclav

 

0

The mentioned code snipping is executed in an intention:

execute (node)->void {
//take the context node of the intention and cast it to required type
if (node.isInstanceOf(HasChildList)) {
node<HasChildList> currentnode = node as HasChildList
}
currentNode.childList.clear

//iterate over the children of a node referenced by the current node
//refToAnotherNode is a smart-reference pointing on a concept defined in another language
foreach myExistingTarget in current.refToAnotherNode.listOfChilds {

//create new SmartReference and set its reference to the existing target
node
<SmartRef> smartRefNew = new node<SmartRef>();
smartRefNew.target.set(myExistingTarget);

//create new node that has the new SmartRef-node as child
node<HasSmartRefAsChild> newNode = new node<HasSmartRefAsChild>();
newNode.referenceChild.set(smartRefNew);
//do additional things on this node

//add new node to context node
current.childList.addLast(newNode);
}
}

The idea is that current.refToAnotherNode points to a node denoting its type. For each of the elements defined in the types children list, I want to define an instance that is added to the current node.

After executing the snippet, the out of scope error is shown at the node on which the intention is used (used as currentNode within the intention), but not within the intention. Inspecting the node after executing the intention shows the intended structure, children to be created based on the existing children  of the referenced node seems to be created and added properly to the children list.

0

Is there a scoping rule defined in Constraints for SmartRef?

0

Thanks for the hint, yes, there is a scope constraint used for another context. Thus, I have to extend the constraint that it reflects the concrete use context.

... long discussion for a simple problem :D

 

Regards,

Henning

0

Please sign in to leave a comment.