swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can I add super class's variables to proveMap with java code?


From: Marcus G. Daniels
Subject: Re: Can I add super class's variables to proveMap with java code?
Date: 11 Aug 2000 17:33:46 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "KY" == Kazuko Yamasaki <address@hidden> writes:

KY> I would like to add the "super" class's variables and messeges to
KY> the "this" class's proveMap.

KY> Will you please tell me how to do with java code?

You may need to build the snapshot sources¹ to get this working...
   
¹ ftp://ftp.swarm.org/pub/swarm/src/testing/swarm-2000-08-11.tar.gz

Below is Java code that demonstrates one approach.  
(Step toward the base of the class hierarchy, checking each ProbeMap.)

import swarm.Globals;
import swarm.objectbase.VarProbe;
import swarm.objectbase.EmptyProbeMapImpl;
import swarm.objectbase.ProbeMap;
import swarm.defobj.Zone;
import swarm.simtoolsgui.GUISwarm;
import swarm.simtoolsgui.GUISwarmImpl;

class BaseClass {
  public double val1;
  public String val2;
}

class SubClass extends BaseClass {
  public int val3;

  SubClass (double val1, String val2, int val3) {
    super ();
    
    this.val1 = val1;
    this.val2 = val2;
    this.val3 = val3;
  }
}

class SuperProbeMap extends EmptyProbeMapImpl {
  SuperProbeMap (Zone aZone, Class aClass) {
    super (aZone, aClass);
  }

  VarProbe getProbeForVariable (String name, Class clas) {
    VarProbe vp =
      Globals.env.probeLibrary.getProbeForVariable$inClass (name, clas);

    if (vp == null)
      {
        clas = clas.getSuperclass ();
        if (clas != null)
          vp = getProbeForVariable (name, clas);
      }
    return vp;
  }

  void addProbeForVariable (String name) {
    addProbe (getProbeForVariable (name, getProbedClass ()));
  }
}

public class SuperProbeMapTest extends GUISwarmImpl {
  SuperProbeMapTest (Zone aZone) {
    super (aZone);
  }

  public Object buildObjects () {
    super.buildObjects ();

    SubClass subClass = new SubClass (1.0, "Hello World", 2);
    SuperProbeMap probeMap = new SuperProbeMap (getZone (),
                                                subClass.getClass ());

    probeMap.addProbeForVariable ("val1");
    // probeMap.addProbeForVariable ("val2");
    probeMap.addProbeForVariable ("val3");

    Globals.env.probeLibrary.setProbeMap$For ((Object) probeMap,
                                              subClass.getClass ());

    Globals.env.createProbeDisplay (subClass);
    return this;
  }

  public Object buildActions () {
    super.buildActions ();
    return this;
  }

  public static void main(String[] args) {
    Globals.env.initSwarm ("SuperProbeMap", "0.0","address@hidden", args);
    
    GUISwarm guiSwarm = new SuperProbeMapTest (Globals.env.globalZone);

    guiSwarm.buildObjects ();
    guiSwarm.buildActions ();
    guiSwarm.activateIn (null);
    guiSwarm.go ();
  }
}


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]