Topic
  • 7 replies
  • Latest Post - ‏2013-12-02T14:28:18Z by Mathias Mamsch
bandchef
bandchef
21 Posts

Pinned topic How to get the target object?

‏2013-11-29T11:36:51Z |

Hi!

 

How can I get the target object of a give outgoing link? I have written this:

 

myObject = target outGoingLink

 

If I write as next step a for loop, 'myObject' is the first object in the module in which the foor loop operates and not the object to which points the given link to!

 

Where is the failure?

  • pommCannelle
    pommCannelle
    92 Posts

    Re: How to get the target object?

    ‏2013-11-29T13:15:29Z  

    ( You have to ensure that the target module is open in order to avoid the null object as target ...
    According to the DXL help, you can try something like :

    Object o = current
    Link lnk; ModName_ targetMod
    for lnk in o->"*" do {
        targetMod = target lnk
        read(fullName(targetMod), true)
        // now you can use the target perm with an object !
        Object otherO = target l
    }

    Have fun ! ;) )

  • bandchef
    bandchef
    21 Posts

    Re: How to get the target object?

    ‏2013-11-29T13:24:23Z  

    ( You have to ensure that the target module is open in order to avoid the null object as target ...
    According to the DXL help, you can try something like :

    Object o = current
    Link lnk; ModName_ targetMod
    for lnk in o->"*" do {
        targetMod = target lnk
        read(fullName(targetMod), true)
        // now you can use the target perm with an object !
        Object otherO = target l
    }

    Have fun ! ;) )

    Object o = current
    Link lnk; ModName_ targetMod
    for lnk in o->"*" do {
        targetMod = target lnk
        read(fullName(targetMod), true)
        // now you can use the target perm with an object !
        Object otherO = target l
    }

     

    What do you mean in the last line with "target l"?

     

     

    My code:

    1. for lnk_InnerOutLink1 in gobj_CurrentObject1 -> "*" do
    2. {
    3. //cast von ModName_ zu Module
    4. targetMod1 = target lnk_InnerOutLink1
    5. gmod_CurrentModule2 = read(fullName targetMod1, true)
    6. //setze Startobjekt
    7. gobj_CurrentObject2 = target lnk_InnerOutLink1
    8.  
    9.  
    10. //Schaltet Objekte von "LH" weiter
    11.  
    12. for gobj_CurrentObject2 in gmod_CurrentModule2 do
    13. ...
  • bandchef
    bandchef
    21 Posts

    Re: How to get the target object?

    ‏2013-11-29T13:29:21Z  

    Mhmhmmm. My code don't work und your code also don't work. The objects which where iterated by the last for Loop are beginning with the first object and not with the object the link points to!

  • pommCannelle
    pommCannelle
    92 Posts

    Re: How to get the target object?

    ‏2013-11-30T14:59:35Z  
    • bandchef
    • ‏2013-11-29T13:29:21Z

    Mhmhmmm. My code don't work und your code also don't work. The objects which where iterated by the last for Loop are beginning with the first object and not with the object the link points to!

    ( have you tried to replace
    Object otherO = target l
    by
    Object otherO = target lnk 
    ? )

     

  • Mathias Mamsch
    Mathias Mamsch
    2159 Posts

    Re: How to get the target object?

    ‏2013-12-01T18:31:12Z  
    • bandchef
    • ‏2013-11-29T13:29:21Z

    Mhmhmmm. My code don't work und your code also don't work. The objects which where iterated by the last for Loop are beginning with the first object and not with the object the link points to!

    In this post I once showed the way to properly iterate over the links in a module (which also works with baselines / links to baselines)

    https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014702797&ps=25

    Here is the cleaned up code with leaks of ModuleVersion removed:

    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
        noError();

        if (null modTarget) modTarget = load(mvTarget,false)
        lastError();
        delete mvTarget

        if (null modTarget) { /* put error handling here! */; continue }  

        // get target object
        Object oTgt = target lnk
        if (null oTgt) { /* put error handling here! */; continue }

        if (isDeleted oTgt) { /* error handling here! */; 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
        noError();
        if (null modSrc) modSrc = load(mvSource,true)
        lastError();
        delete mvSource
      }  

      // 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

    Updated on 2013-12-02T14:28:42Z at 2013-12-02T14:28:42Z by Mathias Mamsch
  • bandchef
    bandchef
    21 Posts

    Re: How to get the target object?

    ‏2013-12-02T13:38:57Z  

    In this post I once showed the way to properly iterate over the links in a module (which also works with baselines / links to baselines)

    https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014702797&ps=25

    Here is the cleaned up code with leaks of ModuleVersion removed:

    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
        noError();

        if (null modTarget) modTarget = load(mvTarget,false)
        lastError();
        delete mvTarget

        if (null modTarget) { /* put error handling here! */; continue }  

        // get target object
        Object oTgt = target lnk
        if (null oTgt) { /* put error handling here! */; continue }

        if (isDeleted oTgt) { /* error handling here! */; 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
        noError();
        if (null modSrc) modSrc = load(mvSource,true)
        lastError();
        delete mvSource
      }  

      // 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

    Hi!

    Thx for your info, but this is not a code which I search for. I have a for-loop:

    Object globalObject

     

    for lnk_InnerOutLink2 in gobj_CurrentObject2 -> * do

    {

         //Here, I will get from lnk_InnerOutLink2 the actually object!

         //globalObject = object(lnk_InnerOutLink2) //e.g.

    }

     

    Are you understanding my problem? For your Information: The link Points to another Module, which the link comes from!

    Updated on 2013-12-02T13:46:33Z at 2013-12-02T13:46:33Z by bandchef
  • Mathias Mamsch
    Mathias Mamsch
    2159 Posts

    Re: How to get the target object?

    ‏2013-12-02T14:28:18Z  
    • bandchef
    • ‏2013-12-02T13:38:57Z

    Hi!

    Thx for your info, but this is not a code which I search for. I have a for-loop:

    Object globalObject

     

    for lnk_InnerOutLink2 in gobj_CurrentObject2 -> * do

    {

         //Here, I will get from lnk_InnerOutLink2 the actually object!

         //globalObject = object(lnk_InnerOutLink2) //e.g.

    }

     

    Are you understanding my problem? For your Information: The link Points to another Module, which the link comes from!

    Yes, so the code I posted is indeed what you need. I just noticed that the link "Object oTgt = target lnk" was still inside a comment (due to the problematic formatting issues from the old posts). So you only need this part:

      // 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
        noError();

        if (null modTarget) modTarget = load(mvTarget,false)
        lastError();
        delete mvTarget

        if (null modTarget) { /* put error handling here! */; continue }  

        // get target object
       
    Object oTgt = target lnk
        if (null oTgt) { /* put error handling here! */; continue }

        if (isDeleted oTgt) { /* error handling here! */; continue }   

        print "Out: '" (oTgt."Object Text") "'\n"
      }

    oTgt is the object you are looking for (target object of the link). o is the object that is the source of the outlink. But the above code is the proper way to iterate over the outlinks of an object, and reliably get a handle to the link target while handling the corner cases (stale links, module deleted, target object is deleted, no access, link goes to baseline, link comes from baseline, ...).

    Regards, Mathias

    Updated on 2013-12-02T14:30:34Z at 2013-12-02T14:30:34Z by Mathias Mamsch