External class Next: Extern NodeUp: External InstructionsPrevious: External Instructions

External class

Each instance of Interpretor  has a field which is an instance ofExternal  and is used as an interface between reactive scripts and external Java objects. When an external statement is encountered, the string between braces is passed to this object as a parameter of the parseExpression method. While parsing, when anidentifier is found, the External  object checks if this identifier references a registered object (Javaobjects that implement the Selector  interface have to registerthemself to the External  instance, through the register method) and if so, calls the select method on this registered object with the method name and its parameters as arguments. Each implementation of the select method is responsible for the correct redirection to Java methods.

public class External implements Selector
{
   private Hashtable objEnv = new Hashtable();
   public Interpretor currentInterp = null;

   public External(Interpretor anInterp)
   {
      currentInterp = anInterp;
      register("External",this);
   }

   public void setThisContext(Selector selObj){
   {
      if(selObj!=null) objEnv.put("this",selObj);
      else objEnv.remove("this");
   }

   public Selector getThisContext(){
      return (Selector)objEnv.get("this");
   }

   public Selector getExternObject(String aName){
        return (Selector)objEnv.get(aName);
   }

   public boolean unregister(String objectName)
   {
     if(objectName.equals("External")) {
        System.out.println(
               "Unable to remove the External object!");
        return false;
     }
     objEnv.remove(objectName);
     return true;
   }
 
   public boolean register(String objectName, Selector selObj)
   {
     if(objectName.equals("this"))
     {
       System.out.println(
           "no object can be registered as \"this\"");
       return false;
     }
     Object o = objEnv.get(objectName);
     if (o==null) objEnv.put(objectName,selObj);
     else{ 
       System.err.println("already registered object: ");
       return false; 
     }
     return true;
   }
    .......
}