Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
5 replies Latest Post - ‏2012-11-30T14:27:53Z by SystemAdmin
kabr
kabr
115 Posts
ACCEPTED ANSWER

Pinned topic removeLinkModuleDescriptor

‏2012-11-29T08:43:51Z |

Has anybody ever tried to delete link module descriptors via DXL?

when I try this code

LinkModuleDescriptor lmd
Folder lmdFolder = getParentFolder(current Module)
 
for lmd in lmdFolder do {
    string src = getSourceName(lmd)
        string tgt = getTargetName(lmd)
        string err = removeLinkModuleDescriptor(lmdFolder, src, tgt) 
        if ( err != "" ) print err ""
}


DOORS always crashed with an EXEPTION_ACCESS_VIOLATION error.

Karl

Updated on 2014-01-06T14:30:25Z at 2014-01-06T14:30:25Z by iron-man
  • SystemAdmin
    SystemAdmin
    3180 Posts
    ACCEPTED ANSWER

    Re: removeLinkModuleDescriptor

    ‏2012-11-29T09:20:30Z  in response to kabr
    Hi Karl,

    haven't evaluated this but it sounds like the usual "never delete something you iterate over".

    Make two loops. In the first one (for lmd in lmdFolder) put the lmd in a skip list
    in the second one (for lmd in mySkip) delete the lmd.
    Cu
    Mike
    • kabr
      kabr
      115 Posts
      ACCEPTED ANSWER

      Re: removeLinkModuleDescriptor

      ‏2012-11-29T13:13:19Z  in response to SystemAdmin
      Thank you, Mike,

      you're perfectly right.
      Trying to delete the lmd inside the loop caused the crash.

      I really should have known myself actually.

      Karl
      • SystemAdmin
        SystemAdmin
        3180 Posts
        ACCEPTED ANSWER

        Re: removeLinkModuleDescriptor

        ‏2012-11-29T18:27:34Z  in response to kabr
        string RemoveLinkPairing(Module SourceMod, string TargetORLink, bool flag)
        {
            //If flag is false it removes all linking pairing through supplied LINKMODULE
                const Regexp SrcRegx = regexp2 fullName(SourceMod)
                const Regexp TrgRegx = regexp2 TargetORLink     
                int LMDcnt = 0
                
                Folder fol = getParentFolder (SourceMod)
                LinkModuleDescriptor LMD = null
                string ret = null
                Skip skp = create()
                
                for LMD in fol do { 
                        string modSource = getSourceName(LMD) 
                        string modTarget = getTargetName(LMD)
                        string modTargetORlinkmodule = null
                        
                        if(flag) { modTargetORlinkmodule = getTargetName(LMD) } else { modTargetORlinkmodule = getName(LMD) }
                        if((SrcRegx modSource) && (TrgRegx modTargetORlinkmodule)) { put(skp, LMDcnt++, LMD) }
                }
                
                for LMD in skp do {
                        string modSource = getSourceName(LMD) 
                        string modTarget = getTargetName(LMD)
                    ret = removeLinkModuleDescriptor(fol, modSource, modTarget)
                }
                
                delete(skp)
                delete(SrcRegx)
                delete(TrgRegx)
                
                return ((ret!=null)?ret:LMDcnt"")
        }
         
        string RemoveLinkPairing(Module SourceMod, string TargetORLink) { RemoveLinkPairing(SourceMod, TargetORLink, true) }
         
        print RemoveLinkPairing(current Module, "/New Family Car Project/Admin/Satisfies", false)
        
        Updated on 2014-01-06T14:30:45Z at 2014-01-06T14:30:45Z by iron-man
        • llandale
          llandale
          2943 Posts
          ACCEPTED ANSWER

          Re: removeLinkModuleDescriptor

          ‏2012-11-29T21:12:19Z  in response to SystemAdmin
          This looks pretty good.
          • I don't think you need (or want) the Regexp. getSourceName(lmd) returns a full name and you can compare it directly to fullName(SourceMod). As it is if you want to remove an LMD from a module named "A" you may create a lot of havok if your path contains "A" anywhere.
          • This may relieve callers from worrying about "flag"; adding an "s" to the name:
            • string RemoveLinkPairings(Module SourceMod, string LinkModName) { RemoveLinkPairing(SourceMod, LinkModName, false) }
          • you don't need the first "modTarget".

          -Louie
          • SystemAdmin
            SystemAdmin
            3180 Posts
            ACCEPTED ANSWER

            Re: removeLinkModuleDescriptor

            ‏2012-11-30T14:27:53Z  in response to llandale

            Updates based on comments!!!!

            string RemoveLinkPairings(Module SourceMod, string TargetORLink, bool flag)
            {
                //If flag is false it removes all linking pairing through supplied LINKMODULE
                    int LMDcnt = 0
                    
                    Folder fol = getParentFolder (SourceMod)
                    LinkModuleDescriptor LMD = null
                    string ret = null
                    Skip skp = create()
                    
                    for LMD in fol do { 
                            string modSource = getSourceName(LMD) 
                            string modTargetORlinkmodule = null
                            
                            if(flag) { modTargetORlinkmodule = getTargetName(LMD) } else { modTargetORlinkmodule = getName(LMD) }
                            if((fullName(SourceMod) == modSource) && (TargetORLink == modTargetORlinkmodule)) { put(skp, LMDcnt++, LMD) }
                    }
                    
                    for LMD in skp do {
                            string modSource = getSourceName(LMD) 
                            string modTarget = getTargetName(LMD)
                        ret = removeLinkModuleDescriptor(fol, modSource, modTarget)
                    }
                    
                    delete(skp)
                    
                    return ((ret!=null)?ret:LMDcnt"")
            }
             
            string RemoveLinkPairings(Module SourceMod, string TargetORLink) { return RemoveLinkPairings(SourceMod, TargetORLink, true) }
             
            print RemoveLinkPairings(current Module, "/New Family Car Project/Admin/Satisfies", false)
            
            Updated on 2014-01-06T14:31:09Z at 2014-01-06T14:31:09Z by iron-man