Attribute embedded DXL

I am trying to apply some rules to auto populate a resultant "Acceptance" attribute value.

The aim is that when the script is run, the result for each object is based upon a specific rule (if any) defined within an attribute of that object. eg
Object n Rule attribute states "if (o."Compliance Statement"" == "Partially Complies") { o."Acceptance" = "Rejected"}
Object n+1 Rule attribute states "if (o."Comments"" != "") { o."Acceptance" = "Rejected"}

The Acceptance attribute is enumerated and where no rule exists the user must manually select a value. I think this effectively precludes the use of attribute or layout dxl.

The plan is to run the module script manually (as necessary) to update the results.

Module m = current
Object o

for o in m do {
//apply object specific rule

}

Any ideas how I can get my module script to read and apply the code embedded within the specific object attribute?
Martin_Hunter - Tue Jun 22 09:28:15 EDT 2010

Re: Attribute embedded DXL
meherts - Tue Jun 22 14:55:16 EDT 2010

1. Make sure the module is open for editing:
 

//Open module for reading
m = read(...)
 
//Open module for editing
m = edit(...)

 


2. Loop appropriately, that is, if I'm understanding you correctly:

 

 

 

//Extract attribute definitions
AttrDef ad
for ad in m do{
        
        //Check if object
        if(ad.object){
               //modifications go here
        }
}
 
//Save changes
save(m)
 
//Close module
close(m)

 

 

Re: Attribute embedded DXL
Martin_Hunter - Wed Jun 23 09:50:56 EDT 2010

meherts - Tue Jun 22 14:55:16 EDT 2010

1. Make sure the module is open for editing:
 

//Open module for reading
m = read(...)
 
//Open module for editing
m = edit(...)

 


2. Loop appropriately, that is, if I'm understanding you correctly:

 

 

 

//Extract attribute definitions
AttrDef ad
for ad in m do{
        
        //Check if object
        if(ad.object){
               //modifications go here
        }
}
 
//Save changes
save(m)
 
//Close module
close(m)

 

 

The rule for each object needs to be read from its "Rule" attribute.

I have achieved an ugly solution by writing the rule to a temp file and then including the file.
 

Module m = current
Object o
stream rule = write tempFileName
 
for o in m do {
    clear rule
    out << o."Rule" "" //Object rule eg if (o."Compliance Statement"" == "Partially Complies") { o."Acceptance" = "Rejected"}
    #include tempFileName
}

 


Writing to a file then including that file is going to be very slow, there must be a slicker solution.

 

Re: Attribute embedded DXL
Mathias Mamsch - Wed Jun 23 10:35:48 EDT 2010

Martin_Hunter - Wed Jun 23 09:50:56 EDT 2010

The rule for each object needs to be read from its "Rule" attribute.

I have achieved an ugly solution by writing the rule to a temp file and then including the file.
 

Module m = current
Object o
stream rule = write tempFileName
 
for o in m do {
    clear rule
    out << o."Rule" "" //Object rule eg if (o."Compliance Statement"" == "Partially Complies") { o."Acceptance" = "Rejected"}
    #include tempFileName
}

 


Writing to a file then including that file is going to be very slow, there must be a slicker solution.

 

This is not going to work! The #include is done only once before you run the script (like in C by the preprocessor) and if you change the file during the run of the script you won't get any changes.

I find it strange to put DXL source code in an attribute (imagine someone puts some virus code in there!). But if you really want to go that way you can do something like this:
 

Object o
string s = "print identifier o \"\n\"" 
 
for o in current Module do {
     eval_ "Object o = (addr_ " ((addr_ o) int) ") Object\n" s 
}

 


instead of s you can use the code in your attribute. This is how you pass Object variables or stuff to an eval_ context. It might seem a little confusing - you actually just create dummy code like this:

 

 

 

Object o = (addr_ 12345) Object
    // your code
    print identifier o "\n"



The addr_ 12345 is just the reference to the Object var outside the eval context.

Regards, Mathias



 

 

 

 


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

 

 

Re: Attribute embedded DXL
llandale - Wed Jun 23 17:30:46 EDT 2010

Seems strange to put DXL code in an attribute. I didn't try it but am sure Malias' solution will work.

I would put a flag in the Rules attribute. The DXL script reads the Rule flag and determines what to do; something like this:

string   NameAttrAcceptance = "Acceptence"
 
void  AutoSetAcceptance(Object obj)
{     if (null obj) return
 
      Rule = probeAttr_(obj, "MyRulesAttr")
      if (null Rule)
      {  Accept = probeAttr_(obj, NameAttrAcceptance)
         if (null Accept) then do something manual for this object
      }
      elseif (Rule == "Check Compliance")
      {  if (o."Compliance Statement"" == "Partially Complies")
         {  oNameAttrAcceptance = "Rejected"
         }
         else ???
      }
      elseif (Rule == "Check Comments)
      {  if (null (o."Comments" ""))
         {  oNameAttrAcceptance = "Rejected"
         }
         else ???
      }
      elseif (Rule == "Check something else")
      {...
      }
      else
      {  deal with illegal rule, like suggesting this DXL be updated
      }
}

 

  • Louie

 

Re: Attribute embedded DXL
Mathias Mamsch - Wed Jun 23 17:45:37 EDT 2010

llandale - Wed Jun 23 17:30:46 EDT 2010

Seems strange to put DXL code in an attribute. I didn't try it but am sure Malias' solution will work.

I would put a flag in the Rules attribute. The DXL script reads the Rule flag and determines what to do; something like this:

string   NameAttrAcceptance = "Acceptence"
 
void  AutoSetAcceptance(Object obj)
{     if (null obj) return
 
      Rule = probeAttr_(obj, "MyRulesAttr")
      if (null Rule)
      {  Accept = probeAttr_(obj, NameAttrAcceptance)
         if (null Accept) then do something manual for this object
      }
      elseif (Rule == "Check Compliance")
      {  if (o."Compliance Statement"" == "Partially Complies")
         {  oNameAttrAcceptance = "Rejected"
         }
         else ???
      }
      elseif (Rule == "Check Comments)
      {  if (null (o."Comments" ""))
         {  oNameAttrAcceptance = "Rejected"
         }
         else ???
      }
      elseif (Rule == "Check something else")
      {...
      }
      else
      {  deal with illegal rule, like suggesting this DXL be updated
      }
}

 

  • Louie

 

I like the new nickname 'malias' ... It has this little evil but still powerful sound :-) Regards, Mathias

Re: Attribute embedded DXL
llandale - Fri Jun 25 14:36:22 EDT 2010

Mathias Mamsch - Wed Jun 23 17:45:37 EDT 2010
I like the new nickname 'malias' ... It has this little evil but still powerful sound :-) Regards, Mathias

Sorry, I'm terrible with names and spelling due to 2 rather odd but serious limitations [1] I have a bit of reverse-photographic memory: I cannot visualize my Mother's face and cannot put into words what she looks like [2] my mind works on concepts not labels: after reading a novel I can more easily tell you what the Protagonist did than tell you her name. Turns out I know about half the folks name's I've been working with for 4 years. When I misspell a word I can usually tell its wrong, but I have to rearrange the letters fairly randomly until it looks right.

Now my Recognition is just fine, just not my Recall. Had someone else written "Malius Mamsch" I probably would recognize it as wrong.

  • Louie

Yup, 'Mathias' does sound a bit 'Quaker' compared to 'Malius'. lol