Check whether a module contains a specific attribute

I am writing some DXL for use as a DXL column that for each object in a module, looks at the in-links and returns the link name. Then if the link name starts with "VERIF", it will get the object text from an attribute "TestResultFloating" in the linked module and show it in the current module, in the DXL column.

The problem I will have when I use this on the whole database (currently I am just using a sandbox) is that some of the modules linked through the "VERIF" link module will not contain the "TestResultFloating" attribute. For these I would like to oppress the 'unknown Object attribute (TestResultFloating)' error and instead display something like N/A for that Object in the current module.  

Below is my code that currently works as long as the "TestResultFloating" attribute is present in the linked module, but will throw the error if the attribute is not present. I have commented out my attempts at finding whether the attribute exists or not as it doesn't work. But maybe it is a basis that could work?

 

ModName_ mSrc
Object o = current
Object oSrc, oDest
LinkRef lr = null
Link l = null
string linkname = ""
string attrbExists

  for mSrc in (obj <- "*") do {
    if (!open(mSrc)) {
      read(fullName(mSrc), true)
    }
  }


for l in (obj <- "*") do {

  oSrc = source(l)
  linkname = name(module(l))
  string linkmodname = upper(linkname[0:4])

  // attrbExists = probeAttr_(obj,"TestResultFloating")

  if(linkmodname == "VERIF") {
    // print "attrib-" attrbExists
    // if(attrbExists != "") {
      string objText = oSrc."TestResultFloating"
      display(objText)
    // }
  }
  // else {
    // print attrbExists
    // display(attrbExists)
  // }
}

I tried one way of doing it which I got from the dxl reference manual which was to check whether the attribute exists and then do the operation. This is what I added but it doesn't seem to work, I still get the same error "unknown Object attribute (TestResultFloating)"
What I tried is shown below:

    if(linkmodname == "VERIF") {
          if(exists attribute "TestResultFloating"){
            string objText = oSrc."TestResultFloating"
            display(objText)
        }
          else {
            display("N/A")
          }
        }

 

Please also note that i'm very new to DOORS and DXL so if I am doing something drastically wrong or I am asking a simple question please forgive me.


gurn64 - Tue Dec 06 10:42:50 EST 2016

Re: Check whether a module contains a specific attribute
Mike.Scharnow - Tue Dec 06 11:50:16 EST 2016

Hm, a) I would say you rather would want to say 

attrbExists = probeAttr_(oSrc,"TestResultFloating")

instead of

attrbExists = probeAttr_(obj,"TestResultFloating")

b)

the result of probeAttr_ is already the content that you need, so in total you would have something like 

  // 

  if(linkmodname == "VERIF") {
    string objText = probeAttr_(oSrc,"TestResultFloating")
     display objText
  }

 

Re: Check whether a module contains a specific attribute
thsturm - Wed Dec 07 03:13:45 EST 2016

I use for the access to a Module attribute this routine:

/** @brief get the value of a module attribute
 *
 * @param mod the module
 * @param attr the name of the module attribute
 * @return the value of the module attribute
 */
string getAttribute(Module mod, string attr) 
{
        AttrDef ad = find(mod, attr)
        if (ad != null) {
                return mod.attr ""
        } else {
                print "*** Error reading: '" name mod "'.\"" attr "\" ***\n"
        }
        return ""
}

For an Object attribute the routine is:

string getAttribute(Object obj, string attr) 
{
        AttrDef ad = find(module(obj), attr)
        if (ad != null) {
                return obj.attr ""
        } else {
                print "*** Error reading: '" identifier obj "'.\"" attr "\" ***\n"
        }
        return ""
}

 

Re: Check whether a module contains a specific attribute
gurn64 - Wed Dec 07 09:13:07 EST 2016

Mike.Scharnow - Tue Dec 06 11:50:16 EST 2016

Hm, a) I would say you rather would want to say 

attrbExists = probeAttr_(oSrc,"TestResultFloating")

instead of

attrbExists = probeAttr_(obj,"TestResultFloating")

b)

the result of probeAttr_ is already the content that you need, so in total you would have something like 

  // 

  if(linkmodname == "VERIF") {
    string objText = probeAttr_(oSrc,"TestResultFloating")
     display objText
  }

 

Thank you for this, your "part b" solved my problem and was a simple implementation!

 

Thanks @thsturm 8edf9132-c1a3-42b7-97b7-6a563ab61072 for your help too.​