looping over incoming links of certain link Module

Hello together,

as a newbie in dxl can't resolve (probably) a very simple issue: each entry in the Module has 0..N incoming links which are stored in different link modules. I need to loop through the links of only one of those link modules. According to the reference manual it coud be implemented as follows:
 

Link in_lnk
Module md = current
Object md_entry_ptr,src_obj
for md_entry_ptr in md do
{
  //loop over LinkModule links (incoming) of the entry:         
  for in_lnk in all ((md_entry_ptr) <- ("name_of_LinkModule")) do 
  {
    my code
  }


the point is that even if I take the module name out of the module entry properties (it looks there like "/RootFolder/subfolder/LnkMod"), my loop will never execute (((((.
if I put debug info in code:

 

...
{
  //loop over all links (incoming) of the entry:        
  for in_lnk in all ((md_entry_ptr) <- ("*")) do 
  {
    fnm = name module in_lnk
    print fnm "\n"
  }


I get "LnkMod". But again, if I use this result like here:

 

 

...
{
  //loop over LnkMod links (incoming) of the entry:     
  for in_lnk in all ((md_entry_ptr) <- ("LnkMod")) do 
  {
    my code
  }


the loop never executes. Where is the mistery?
Thanks in advance!

 


SystemAdmin - Fri Nov 11 10:00:12 EST 2011

Re: looping over incoming links of certain link Module
Mathias Mamsch - Fri Nov 11 10:50:22 EST 2011

The mistery is, that a "Link" is only available if the source module (i.e. the module where the link comes from is loaded). So you cannot use "for Link in Object do" if you want to interate all links. The proper approach for iterating over links is:
 

Object o
Link lnk
for o in entire current Module do {
        // Outlinks can be iterated, since the source is already loaded
    for lnk in all o -> "*" do {
                // load target
                ModuleVersion mvTarget = targetVersion lnk
                Module modTarget = data mvTarget
                if (null modTarget) modTarget = load(mvTarget, false)
                if (null modTarget) { /* error handling */; continue }
 
                // get target object
                Object oTgt = target lnk 
                if (null oTgt) { /* error handling */; continue }
                if (isDeleted oTgt) { /* error handling */; continue }
 
                print "Out: '" (oTgt."Object Text") "'\n"
        }
        
        // load source modules of in-link references
        LinkRef lr; for lr in all (o <- "*") do {
                ModuleVersion mvSource = sourceVersion lr
                Module modSrc = data mvSource 
                if (null modSrc) modSrc = load(mvSource, true)
        }
 
        // Iterate in-links and navigate (source modules are now open)
        for lnk in all (o <- "*") do {
                Object oSrc = source lnk
                if (null oSrc) { /* error handling */; continue }
                if (isDeleted oSrc) { /* error handling */; continue }
                print "In: '"(oSrc."Object Text") "'\n"
        }
}

 


Maybe that helps, Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: looping over incoming links of certain link Module
limengale - Fri Nov 11 11:47:08 EST 2011

i'm happy with using

load(mvTarget, false)

 


but one error trapping i've not been able to overcome is the case where there is a dxl error in the target module. Using the code above does not clear the error, and the only way to make your dxl attribute work is to manually open the target modules, and manually clear the error messages.

Ideally i'd just fix the dxl errors - but unfortunately when i've encountered this it's been on db's where i havn't had the ability to poke around quite as much as i can on my own databases.

Is there a way to clear errors on load without doing it manually?

 

Re: looping over incoming links of certain link Module
Mathias Mamsch - Fri Nov 11 16:18:29 EST 2011

limengale - Fri Nov 11 11:47:08 EST 2011

i'm happy with using

load(mvTarget, false)

 


but one error trapping i've not been able to overcome is the case where there is a dxl error in the target module. Using the code above does not clear the error, and the only way to make your dxl attribute work is to manually open the target modules, and manually clear the error messages.

Ideally i'd just fix the dxl errors - but unfortunately when i've encountered this it's been on db's where i havn't had the ability to poke around quite as much as i can on my own databases.

Is there a way to clear errors on load without doing it manually?

 

You are right, thanks for the hint. You would need to surround the load function by noError(); ... lastError();
 

...
   noError() 
   if (null modTarget) modTarget = load(mvTarget, false)
   lastError()
   ...

 


That usually worked fine for me. Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: looping over incoming links of certain link Module
llandale - Sat Nov 12 10:31:57 EST 2011

Mathias Mamsch - Fri Nov 11 16:18:29 EST 2011

You are right, thanks for the hint. You would need to surround the load function by noError(); ... lastError();
 

...
   noError() 
   if (null modTarget) modTarget = load(mvTarget, false)
   lastError()
   ...

 


That usually worked fine for me. Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

I'm also having luck turning triggers off and autodeclare on before opening up other modules, in my big scripts. Reset them afterwards.

I don't recall if I've trapped no-such-incude-file errors or not.

Re: looping over incoming links of certain link Module
llandale - Sat Nov 12 10:43:16 EST 2011

Yes, you must load the source module in order to see the "Link" in the target.

In your second block:
fnm = name module in_lnk

This retrieves the base name of the module "LnkMod", which is interesting for reports but practically useless when used as input to other commands. The LinkModule name must be fully qualified:
for lnk in obj <- "/MyProject1/MyLinkModFolder/LnkMod" do

Hard coding that into a script fails if you intend to run the script on a similarly constructed project /MyProject2. What I do is this:

for lnk in obj <- "*" do
{  NameFullLM = fullName(module(lnk))
   if (!matches("MyLinkModFolder/LnkMod", NameFullLM)) continue  // Ignore this link


So I look at all the links but exclude (continue) those in some other link module.
(Actually I've wrote my own 'matches' function just for this purpose).
(Actually, I make sure my LinkModule names never appear also as folder names, so I can simply match against "Requirements_Links".)

 

 

  • Louie

 

 

Re: looping over incoming links of certain link Module
SystemAdmin - Mon Nov 14 06:22:21 EST 2011

Thanks for the replies,

the simpliest method did work with minor adjustments. The crucial thing was that if the name of the table is in German then my IDE probably doesn't come clear with the umlauts.

Re: looping over incoming links of certain link Module
SystemAdmin - Mon Nov 14 06:23:24 EST 2011

The last method did the job.