Events Handling in BlueJscript

What we are going to see here is what kind of events are available and how to use them.

There are two events queue in the blueJscript environment:

If you have read something on Rhino (The javascript interpreter that I am using) you will have noticed that you can access Java object from javascript much like using any other javascript object. To make a long story short, let see some code.

 * This looks in between all events coming for the ones of type InvocationEvent, START
 * This IS javascript code, NOT java code !
function waitInvocation ( )
  anEvent = null;
  jsConsole.statusSet ('Waiting for an Event');

  while (   (anEvent = jsEvent.get()) != null )
    if ( anEvent.getClass() == "class" ) break;
    if ( anEvent.getClass() != "class bluej.extensions.event.InvocationEvent" ) continue;
    if ( anEvent.getEvent() != anEvent.INVOCATION_STARTED ) continue;

  return anEvent;

The above is a function that you may call from your Javascript program and it will wait for events posted into the jsEvent Object. When the right type is found it will return the object. You may appreciate the simplicity of the System. It is almost like using Java but scripted. Do not get fooled by the fact that there is no variable declaration. This IS a strong typed language !

Another example, this time we are sending a reply to the soap engine. The function will wait for a specified class name and when found it will return "done" to the soap queue.

function soapWaitObjectClass ( objectClassName )
   for (;;)
      waitClass = waitInvocation();
      if ( waitClass.getClassName() == objectClassName ) break;
      print ('soapWaitObjectClass got=', waitClass.getClassName(), ' want=',objectClassName,'\n');

  // This is what we are really looking.
  soapEvent.put ('done');