Default Attribues Value

Hello community,

does anybody know if it is possible to filter on objects that still use the default value of an attribute?

reason: if a default value is defined for an attribute and somebody changes the default to a different value, then all objects for which the attribute was never touched get this new default. Objects, for which the attribute value was changed and then later set back to a value which happens to be the default, are not affected. I need to tell them apart.

Karl
kabr - Tue Jan 12 04:11:20 EST 2010

Re: Default Attribues Value
llandale - Tue Jan 12 12:35:43 EST 2010

I don't think you can do it with the GUI, but you can find such obj-attr values using:

bool hasSpecificValue(Object,AttrDef)

This might work:
 

Module mod = current
string NameAttr = "MyDefaultedAttr"
AttrDef ad = find(mod, NameAttr)
if (! ad.defval)
{  infoBox(NameAttr " has no default value")
   halt
}
 
string ValueDefault = ad.defval "",
       ValueCurr
Object obj
 
for obj in entire (current Module) do
{  ValueCurr = obj.NameAttr
   if (ValueCurr == ValueDefault   and
       hasSpecificValue(obj, ad))
      print (identifier(obj)) "\tHas explicit value '" ValueCurr "'\n"
}

 

 

  • Louie

 

 

Re: Default Attribues Value
bullbala - Thu Jul 21 10:39:35 EDT 2011

I tried to print the value and the default value of a module attribute "XYZ" (of type text) in all the formal modules of the current project.

The problem is that irrespective of what the value of the module attribute is, the default value is always printed as "01 January 1970" !

Here is my script:
 

Module m
AttrDef ad
string attrName = "XYZ"
 
for m in current Project do
{
    if( (!null m) && (type(m) == "Formal") )
        {
                print("\n" m."Name" "\n")
                
                for ad in m do 
                {
                        if (ad.module)
                        {
                                if(ad.name "" == attrName)
                                {
                                        if(hasSpecificValue(m, ad))
                                                print "\t" (ad.name) ": " m.(ad.name) "\n"
                                        else
                                                print "\t" (ad.name) ": " "Has No Specific Value!\n"
                                
                                        if(ad.defval)
                                                print "\tDefault Value: " ad.defval "\n"
                                        else
                                                print "\tDefault Value: Does Not Exist!\n"
                                }
                        }
                }
        }
}

 


I even tried opening all the modules first but that didn't help either :-)
Can you guys help with what went wrong ?

 

Re: Default Attribues Value
Mathias Mamsch - Thu Jul 21 11:43:03 EDT 2011

bullbala - Thu Jul 21 10:39:35 EDT 2011

I tried to print the value and the default value of a module attribute "XYZ" (of type text) in all the formal modules of the current project.

The problem is that irrespective of what the value of the module attribute is, the default value is always printed as "01 January 1970" !

Here is my script:
 

Module m
AttrDef ad
string attrName = "XYZ"
 
for m in current Project do
{
    if( (!null m) && (type(m) == "Formal") )
        {
                print("\n" m."Name" "\n")
                
                for ad in m do 
                {
                        if (ad.module)
                        {
                                if(ad.name "" == attrName)
                                {
                                        if(hasSpecificValue(m, ad))
                                                print "\t" (ad.name) ": " m.(ad.name) "\n"
                                        else
                                                print "\t" (ad.name) ": " "Has No Specific Value!\n"
                                
                                        if(ad.defval)
                                                print "\tDefault Value: " ad.defval "\n"
                                        else
                                                print "\tDefault Value: Does Not Exist!\n"
                                }
                        }
                }
        }
}

 


I even tried opening all the modules first but that didn't help either :-)
Can you guys help with what went wrong ?

 

The ambiguity daemon hit you! You need to be very careful using those x.y syntax. It is better not to embed them since most of the times the statements are ambiguous and the DXL interpreter gets the type wrong most of the time. Therefore you should do:
 

if(ad.defval) print "\tDefault Value: " ((ad.defval) string) "\n" 
// OR: 
    if (ad.defval) { string s = ad.defval; print "\tDefault Value: " s "\n"

 


which should remove the problem. See a similar post here and an explanation here:

https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14463626&#14463626

Regards, Mathias

 

 


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

 

Re: Default Attribues Value
llandale - Thu Jul 21 15:41:53 EDT 2011

bullbala - Thu Jul 21 10:39:35 EDT 2011

I tried to print the value and the default value of a module attribute "XYZ" (of type text) in all the formal modules of the current project.

The problem is that irrespective of what the value of the module attribute is, the default value is always printed as "01 January 1970" !

Here is my script:
 

Module m
AttrDef ad
string attrName = "XYZ"
 
for m in current Project do
{
    if( (!null m) && (type(m) == "Formal") )
        {
                print("\n" m."Name" "\n")
                
                for ad in m do 
                {
                        if (ad.module)
                        {
                                if(ad.name "" == attrName)
                                {
                                        if(hasSpecificValue(m, ad))
                                                print "\t" (ad.name) ": " m.(ad.name) "\n"
                                        else
                                                print "\t" (ad.name) ": " "Has No Specific Value!\n"
                                
                                        if(ad.defval)
                                                print "\tDefault Value: " ad.defval "\n"
                                        else
                                                print "\tDefault Value: Does Not Exist!\n"
                                }
                        }
                }
        }
}

 


I even tried opening all the modules first but that didn't help either :-)
Can you guys help with what went wrong ?

 

So many years ago reading the DXL manual for first time I was flabergasted that they used "defval" as two different valid AttrDef properties. Gads.

Mathias is right, if you want to know if the attr has a default value you need to use the boolean form of "ad.defval", and to find out what that value is you need to use the string form (or I suppose int or real or char).

Here's a function I wrote years ago that resolves it for me. This command:
string Results = ad.defval
does the same thing as Mathias forcing the string version.

//********************
string    fDefVal(AttrDef ad)
{     // Retrieve the default value, if any, for the attribute.
        // Return null if it has no default value.
        // Returns 'True' or 'False' for Booleans that have a Default.
        // Programs can determine IF an attr has a default value like this:
        //      if (ad.defval){}
 
        if (null ad)    return("")    // Bad Input
        if (!ad.defval) return("")    // This attr has no default value
 
        string  Results = ad.defval
 
        return(Results)
        // Note: Consider a Boolean attribute that true has a default value of False.  
        // Since 'ad.defval' can mean either [1] does it have a default value,
        //      and [2] what that default value is, testing shows DXL should do this:
        //      [1] >> Use [print (bool ad.defval)]   or [bool IsDef = ad.defval] or [if (ad.defval)]
        //      [2] >> Use [print (string ad.defval)] or [string Value = ad.defval]
 
        // This also works, but not recommended:
        //      AttrDef ad = find(current Module, "aBool")
        //      string DefVal = ad.(ADADefault_ defval)
        //      bool   DefHas = ad.(ADABool_    defval)
        //      print DefVal "\t" DefHas "\n"
 
}     // end fDefVal()


As for your script, perhaps you also need to handle the case where the value is inherited.

 

bool HasDef = ad.defval
string DefVal = ""
if (HasDef) DefVal = ad.defval
string Value = probeAttr_(m, attrName)
 
if (null Value)
         print "\t" attrName ": " Value "\tIs Null\n"
elseif(hasSpecificValue(m, ad)) 
         print "\t" attrName ": " Value "\tIs Specific\n"
elseif(Value == DefVal) 
         print "\t" attrName ": " Value "\tIs Defaulted\n"
else     print "\t" attrName ": " Value "\tIs Inherited\n"


Actually, its possible that a non-specific value can be the same as the default yet its inherited, as when a parent object explicitely sets its value the same as the default. So we really should recursively examine parent objects but who really cares.

Also, I see your main loop looks through all open modules in the Project. That's rarely useful. Usually you open-examine-close all the modules to get a full report.

 

 

 

  • Louie

 

 

Re: Default Attribues Value
bullbala - Fri Jul 22 04:16:01 EDT 2011

llandale - Thu Jul 21 15:41:53 EDT 2011

So many years ago reading the DXL manual for first time I was flabergasted that they used "defval" as two different valid AttrDef properties. Gads.

Mathias is right, if you want to know if the attr has a default value you need to use the boolean form of "ad.defval", and to find out what that value is you need to use the string form (or I suppose int or real or char).

Here's a function I wrote years ago that resolves it for me. This command:
string Results = ad.defval
does the same thing as Mathias forcing the string version.

//********************
string    fDefVal(AttrDef ad)
{     // Retrieve the default value, if any, for the attribute.
        // Return null if it has no default value.
        // Returns 'True' or 'False' for Booleans that have a Default.
        // Programs can determine IF an attr has a default value like this:
        //      if (ad.defval){}
 
        if (null ad)    return("")    // Bad Input
        if (!ad.defval) return("")    // This attr has no default value
 
        string  Results = ad.defval
 
        return(Results)
        // Note: Consider a Boolean attribute that true has a default value of False.  
        // Since 'ad.defval' can mean either [1] does it have a default value,
        //      and [2] what that default value is, testing shows DXL should do this:
        //      [1] >> Use [print (bool ad.defval)]   or [bool IsDef = ad.defval] or [if (ad.defval)]
        //      [2] >> Use [print (string ad.defval)] or [string Value = ad.defval]
 
        // This also works, but not recommended:
        //      AttrDef ad = find(current Module, "aBool")
        //      string DefVal = ad.(ADADefault_ defval)
        //      bool   DefHas = ad.(ADABool_    defval)
        //      print DefVal "\t" DefHas "\n"
 
}     // end fDefVal()


As for your script, perhaps you also need to handle the case where the value is inherited.

 

bool HasDef = ad.defval
string DefVal = ""
if (HasDef) DefVal = ad.defval
string Value = probeAttr_(m, attrName)
 
if (null Value)
         print "\t" attrName ": " Value "\tIs Null\n"
elseif(hasSpecificValue(m, ad)) 
         print "\t" attrName ": " Value "\tIs Specific\n"
elseif(Value == DefVal) 
         print "\t" attrName ": " Value "\tIs Defaulted\n"
else     print "\t" attrName ": " Value "\tIs Inherited\n"


Actually, its possible that a non-specific value can be the same as the default yet its inherited, as when a parent object explicitely sets its value the same as the default. So we really should recursively examine parent objects but who really cares.

Also, I see your main loop looks through all open modules in the Project. That's rarely useful. Usually you open-examine-close all the modules to get a full report.

 

 

 

  • Louie

 

 

Mathias and Louie,
Thanks so much for the great inputs.

It works now :-)

Louie, I used you logic above and found that for one of the modules in the current project, the module attribute "XYZ" has a value which "Is Inherited".
I checked that the "Inherit" option was not enabled in that module for the attribute "XYZ".
Do you know what can cause this ?

Re: Default Attribues Value
Mathias Mamsch - Fri Jul 22 05:46:38 EDT 2011

bullbala - Fri Jul 22 04:16:01 EDT 2011
Mathias and Louie,
Thanks so much for the great inputs.

It works now :-)

Louie, I used you logic above and found that for one of the modules in the current project, the module attribute "XYZ" has a value which "Is Inherited".
I checked that the "Inherit" option was not enabled in that module for the attribute "XYZ".
Do you know what can cause this ?

Louies code does not check for richText attributes. You probably have a default richText value, which leads Louies code into printing "Inherited" (how can a module inherit an attribute value anyway?). Regards, Mathias

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

Re: Default Attribues Value
bullbala - Fri Jul 22 05:51:14 EDT 2011

Mathias Mamsch - Fri Jul 22 05:46:38 EDT 2011
Louies code does not check for richText attributes. You probably have a default richText value, which leads Louies code into printing "Inherited" (how can a module inherit an attribute value anyway?). Regards, Mathias


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

Yes indeed, Mathias !

My module attribute's default value is of rich text.
I had to strip the rich text tags away before printing !

How can Louie's code be improved to work for both rich text and non-rich text default values ?

Re: Default Attribues Value
Mathias Mamsch - Fri Jul 22 06:39:46 EDT 2011

bullbala - Fri Jul 22 05:51:14 EDT 2011
Yes indeed, Mathias !

My module attribute's default value is of rich text.
I had to strip the rich text tags away before printing !

How can Louie's code be improved to work for both rich text and non-rich text default values ?

For module attributes just delete the "inherited" line. Module attributes can inherit their value from nowhere, so the setting does not affect them. For object attributes you would need to use probeRichAttr_ instead of probeAttr_ . This might resolve the issue. Regards, Mathias

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

Re: Default Attribues Value
llandale - Fri Jul 22 14:21:40 EDT 2011

Mathias Mamsch - Fri Jul 22 06:39:46 EDT 2011
For module attributes just delete the "inherited" line. Module attributes can inherit their value from nowhere, so the setting does not affect them. For object attributes you would need to use probeRichAttr_ instead of probeAttr_ . This might resolve the issue. Regards, Mathias


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

Yes probeRichAttr_.

But for module attributes I'd be tempted to replace the "Is Inherited" line with one that says "Impossible Error" or something like that, prompting folks to fix the DXL.