The RsiObject Class Next: MachinesUp: ObjectsPrevious: Objects

The RsiObject Class

RsiObject  extends UnaryInstruction  and implementsSelector . The activation method sets this to the appropriate Java object before running the body and restores the old binding on return. The method select retransmits method calls to the Java object with same name.

Object fields (managed in a Hashtable) can be dynamically added toRsiObject  instances, using the setField and getField methods.

public class RsiObject extends UnaryInstruction 
implements Selector
{
  protected String name;
  protected External externalContext = null;
  protected Hashtable objectVar = new Hashtable();
  public void setExternalContext(External eC){
     externalContext = eC;
  }

  public RsiObject(String name,Instruction body,External eC)
  {
    this.name = name;
    this.body = body;
    externalContext = eC;
  }

  public String toString(){ 
     return "object " + name + " " + body + " end"; 
  }

  public String select(String methName,Vector args){
    if(methName.equals("getName")) return name;
    if(methName.equals("setField")) return setField(args);
    if(methName.equals("newField")) return newField(args);
    if(methName.equals("removeField")) return removeField(args);
    return externalContext.getExternObject(name).
                                 select(methName,args);
  }
  ...

  public Selector getObjectInSelectorContext(String name)
  {
     return (Selector)objectVar.get(name);
  }

  final protected byte activation(Machine machine)
  {
     Selector sel = externalContext.getThisContext();
     externalContext.setThisContext(this);
     byte res = body.activ(machine);
     externalContext.setThisContext(sel);
     return res;
  }
}

According to the semantics defined in 1.2, an object x whose body isinstruction body, with methods m1,...,mk, is expanded into:

do
     body

  || control m1 by x_m1
  || ...
  || control mk by x_mk    
until x-destroy

The following methods are used at parsing to build the corresponding RsiObject instruction:

private Instruction objectShell(String name,Instruction body){
  return new RsiObject(name,new Until(name + "-destroy",body));
}

public Instruction object(String name,Instruction body,
                                      Vector list)
{
  Instruction res = body;
  for(int i = 0; i<list.size();i++){
    Run run = (Run)list.elementAt(i);
    res = new Merge(res,new Control(name + "-" + run.name,run));
  }
  return objectShell(name,res);
}

public Instruction object(String name,Instruction body){
  return objectShell(name,body);
}