The Virtual Reality Modeling Language

Annex B. Java Scripting Reference

(normative)

* Editor's Draft - NOT OFFICIAL *

ISO/IEC DIS 14772-1

21 February 1997 (revised on 25 March)

B.1 Introduction

This annex describes the Java classes and methods that allow Script nodes (see "6.40 Script") to interact with associated scenes. See "4.12 Scripting" for a general description of scripting languages in VRML. Note that Java is not required by VRML, but any implementation of Java with VRML Script nodes must conform with the requirements specified in this annex.

B.1 Introduction
B.2 Language
B.3 Supported protocol in the Script node's url field
       B.3.1 url field
       B.3.2 File extension
       B.3.3 MIME type
B.4 EventIn handling
       B.4.1 Description
       B.4.2 Parameter passing and the eventIn field/method
       B.4.3 processEvents() and processEvent() methods
       B.4.4 eventsProcessed() method
       B.4.5 shutdown() method
       B.4.6 initialize() method
B.5 Accessing fields and events
       B.5.1 Accessing fields and eventOuts of the Script
       B.5.2 Accessing fields and eventOuts of other nodes
       B.5.3 Sending eventOuts or eventIns
B.6 Exposed classes and methods for nodes and fields
       B.6.1 Introduction
       B.6.2 Field class and ConstField class
       B.6.3 Array handling
       B.6.4 Node class
       B.6.5 Browser class
       B.6.6 User-defined classes and packages
       B.6.7 Standard Java packages
B.7 Exceptions
B.8 Examples
B.9 Class definitions
       B.9.1 Class hierarchy
       B.9.2 VRML packages
                 B.9.2.1 vrml Package
                 B.9.2.2 vrml.field Package
                 B.9.2.3 vrml.node Package
B.10 Example of exception class

B.2 Language

Java(tm) is an object-oriented, platform-independent, multi-threaded, general-purpose programming environment developed at Sun Microsystems, Inc. See [JAVA] for a full description of the Java programming language . This annex describes the Java bindings of VRML to the Script node.

B.3 Supported protocol in the script node's url field

B.3.1 url field

The url field of the Script node contains the URL of a file containing the Java byte code, for example:

Script {
  url "http://foo.co.jp/Example.class"
  eventIn SFBool start
}

B.3.2 File extension

The file extension for Java byte code is .class.

B.3.3 MIME type

The MIME type for Java byte code is defined as follows:

application/x-java

B.4 EventIn handling

B.4.1 Description

Events to the Script node are passed to the corresponding Java method (processEvent or processEvents) in the script. It is necessary to specify the script in the url field of the Script node.

If a Java byte code file is specified in the url field, the following three conditions shall hold:

  1. it shall contain the class definition whose name is exactly the same as the body of the file name
  2. it shall be a subclass of the Script class (see "B.9.2.3 vrml.node Package")
  3. it shall be declared as "public" class

For example, the following Script node has one eventIn field whose name is start.

Script {
  url "http://foo.co.jp/Example1.class"
  eventIn SFBool start
}

This node points to the script file Example1.class. Its source (Example1.java) looks like this:

    import vrml.*;
    import vrml.field.*;
    import vrml.node.*;

    public class Example1 extends Script {
        ...
        // This method is called when any event is received
        public void processEvent (Event e) {
           // ... perform some operation ...
        }
    }

In the above example, when the start eventIn is sent the processEvent() method is executed and receives the eventIn.

B.4.2 Parameter passing and the eventIn field method

When a Script node receives an eventIn, a processEvent() or processEvents() method in the file specified in url field of the Script node is called, which receives the eventIn as Java objects (Event object, see "B.4.3 processEvent() and processEvents() method").

The Event object has three fields of information associated with it: name, value and timestamp whose values are passed by the eventIn. These can be retrieved using the corresponding method on the Event object.

   public class Event implements Cloneable {
      public String getName();
      public ConstField getValue();
      public double getTimeStamp();
      // other methods ...
   }

Suppose that the eventIn type is SFXXX and eventIn name is eventInYYY, then

  1. the getName() shall return the string "eventInYYY "
  2. the getValue() shall return ConstField containing the value of the eventIn
  3. getTimeStamp() shall return a double containing the timestamp when the eventIn occurred

In the example below, the eventIn name is start and the eventIn value is cast to ConstSFBool. Also, the timestamp for the time when the eventIn occurred is available as a double. These are passed as an Event object to processEvent() method:

    public void processEvent(Event e) {
        if(e.getName().equals("start")){
              ConstSFBool v = (ConstSFBool)e.getValue();
              if(v.getValue()==true){
                   // ... perform some operation with e.getTimeStamp()...
              }
         }
    }

B.4.3 processEvents() and processEvent() method

Authors can define a processEvents() method within a class that is called when the script receives some set of events. The prototype of processEvents() method is

    public void processEvents(int count, Event events[]);

count indicates the number of events delivered. events is the array of events delivered. Its default behavior is to iterate over each event, calling processEvent() on each one as follows:

    public void processEvents(int count, Event events[])
    {
        for (int i = 0; i < count; i++) {
            processEvent( events[i] );
        }
    }

Although authors might change this operation by giving a user-defined processEvents() method, in most cases, they only change processEvent() method and eventsProcessed() method as described below.

When multiple eventIns are routed from single node to single script node and eventIns which have the same timestamp are received, processEvents() receives multiple events as an event array. Otherwise, each incoming event invokes separate processEvents().

For example, the processEvents() method receives two events in the following case:

Transform {
  children [
    DEF TS TouchSensor {}
    Shape { geometry Cone {} }
  ]
}
DEF SC Script {
  url "Example.class"
  eventIn SFBool isActive
  eventIn SFTime touchTime
}
ROUTE TS.isActive  TO SC.isActive
ROUTE TS.touchTime TO SC.touchTime

Authors can define a processEvent() method within a class. The prototype of processEvent() is

    public void processEvent(Event event);

Its default behavior is no operation.

B.4.4 eventsProcessed() method

Authors can define an eventsProcessed() method within a class that is called after some set of events has been received. This allows Script nodes that do not rely on the ordering of events received to generate fewer events than an equivalent Script node that generates events whenever events are received. The eventsProcessed() method is called after every invocation of processEvents().

Events generated from an eventsProcessed() method are given the timestamp of the last event processed.

The prototype of eventsProcessed() method is

    public void eventsProcessed();

Its default behavior is no operation.

B.4.5 shutdown() method

Authors can define a shutdown() method within a class that is called when the corresponding Script node is deleted.

The prototype of shutdown() method is

    public void shutdown();

Its default behavior is no operation.

B.4.6 initialize() method

Authors can define an initialize() method within a class that is called before any event is generated. The various methods on Script such as getEventIn(), getEventOut(), getExposedField(), and getField() are not guaranteed to return correct values before the call to initialize() (i. e., in the constructor). initialize() is called once during the life of Script object.

The prototype of initialize() method is

    public void initialize();

Its default behavior is no operation. See Example2.class in paragraph B.5.1 for an example user-specified initialize() method.

B.5 Accessing fields and events

B.5.1 Accessing fields, eventIns and eventOuts of the Script

The fields, eventIns, and eventOuts of a Script node are accessible from their corresponding Java classes.

Each field defined in the Script node is available to the script by using its name. Its value can be read or written. This value is persistent across function calls. EventOuts defined in the Script node can also be read. EventIns defined in the Script node can also be written to.

Accessing fields of Script node can be done by using the three following types of Script class methods:

  1. Field getField(String fieldName)
    is the method to get the reference to the Script node's field whose name is fieldName. The return value can be converted to an appropriate Java Field class or its subclasses, (see "B.6.2 Field class and ConstField class").
  2. Field getEventOut(String eventOutName)
    is the method to get the reference to the Script node's eventOut whose name is eventOutName. The return value can be converted to an appropriate Java Field class or its subclasses, see "B.6.2 Field class and ConstField class").
  3. Field getEventIn(String eventInName)
    is the method to get the reference to the Script node's eventIn whose name is eventInName. The return value can be converted to an appropriate Java Field class or its subclasses, (see "B.6.2 Field class and ConstField class"). EventIn is a write-only field. When you call getValue() method on a Field object obtained by getEventIn() method, the return value is unspecified.

When you call the setValue(), set1Value(), addValue(), insertValue(), delete() or clear() method on a Field object obtained by the getField() method, the new value is stored in the corresponding VRML node's field (see also "B.6.3 Array handling"). In the case of the set1Value(), addValue(), insertValue() or delete() methods, essentially all elements of a VRML node's field are retrieved, then the value specified as an argument is set, added, inserted, deleted (as appropriate) to/from the elements, and then stored as the elements in the corresponding VRML node's field. In the case of the clear() method, all elements of a VRML node's field are cleared (see the definition of clear() method).

When you call the setValue(), set1Value(), addValue(), insertValue(), delete() or clear() method on a Field object obtained by the getEventOut() method, the call generates an eventOut in the VRML scene (see also "B.6.3 Array handling"). The effect of this eventOut is specified by the associated Route in the VRML scene. In the case of the set1Value(), addValue(), insertValue() or delete() methods, essentially all elements of VRML node's eventOut field are retrieved, then the value specified as an argument is set, added, inserted or deleted (as appropriate) to/from the elements, then stored as the elements in the corresponding VRML node's eventOut field, and then the elements are sent as an eventOut. In the case of the clear() method, all elements of VRML node's eventOut field are cleared (see the definition of clear() method).

When you call setValue() or clear() method on a Field object obtained by getEventIn() method, the call generates an eventIn to the Script node. When you call the set1Value(), addValue(), insertValue() or delete() method on a Field object obtained by the getEventIn() method, the exception (InvalidFieldChangeException) is thrown.

For example, the following Script node (Example2) defines an eventIn start, a field state, and an eventOut on. The method initialize() is invoked before any events are received, and the method processEvent() is invoked when start receives an event:

Script {
  url      "Example2.class"
  eventIn  SFBool start
  field    SFBool state TRUE  
  eventOut SFBool on
}

Example2.java:

    
    // Example2 toggles a persistent field variables "state" in both 
    // the applet and VRML Script node each time when eventIn "start" 
    // is received, then sets eventOut "on" equal to true and returns it 
    // to the VRML Script node
    import vrml.*;
    import vrml.field.*;
    import vrml.node.*;

    public class Example2 extends Script {
        private SFBool state; // field
        private SFBool on;    // eventOut

        public void initialize(){
            state = (SFBool) getField("state");
            on = (SFBool) getEventOut("on");
        }

        public void processEvent(Event e) {
            if(state.getValue()==true){
                on.setValue(false); // set false to eventOut 'on'
                state.setValue(false);
            }
            else {
                on.setValue(true);  // set true to eventOut 'on'
                state.setValue(true);
            }
        }
    }

B.5.2 Accessing fields, eventIns and eventOuts of other nodes

If a script program has an access to a node, then any eventIn, eventOut or exposedField of that node is accessible by using the getEventIn(), getEventOut() or getExposedField() method defined on the node's class (see "B.6 Exposed classes and methods for nodes and fields").

The typical way for a script program to have an access to another VRML node is to have an SFNode field which provides a reference to the other node. The following Example3 shows how this is done:

DEF SomeNode Transform { }
Script {
  field SFNode node USE SomeNode  # SomeNode should be a Transform node
  eventIn SFVec3f pos             # new value to be inserted in SomeNode's
                                  # translation field
  url "Example3.class"
}

Example3.java:
    import vrml.*;
    import vrml.field.*;
    import vrml.node.*;

    public class Example3 extends Script {
        private SFNode node;   // field
        private SFVec3f trans; // translation field captured from remote
                               // Transform node

        public void initialize(){
            node = (SFNode) getField("node");
        }
        public void processEvent(Event e) {
            // gets the reference to 'translation' field of Transform node
            trans = (SFVec3f)((Node) node.getValue()).getExposedField("translation");
            // reset translation to value given Event e, which is eventIn pos
            // in the VRML Script node.
            trans.setValue((ConstSFVec3f)e.getValue());
        }
    }

B.5.3 Sending eventOuts or eventIns

Assume that the thread which executes processEvent() (or processEvents()) is called 'main' thread and any other thread, except for the 'main' thread, is called 'sub' thread. Sending eventOuts/eventIns in 'main' thread follows the model described in "4.10.3 Execution model" and sending eventOuts/eventIns in any 'sub' thread follows the model described in "4.12.6 Asynchronous scripts."

Note: sending eventIns is ordinarily performed by the VRML scene, not Java applets. Exceptions may result as specified in paragraph B.5.1.

B.6 Exposed classes and methods for nodes and fields

B.6.1 Introduction

Java classes for VRML are defined in the packages: vrml, vrml.node and vrml.field.

The Field class extends Java's Object class by default; thus, Field has the full functionality of the Object class, including the getClass() method. The rest of the package defines a "Const" read-only class for each VRML field type, with a getValue() method for each class; and another read/write class for each VRML field type, with both getValue() and setValue() methods for each class. A getValue() method converts a VRML-type value into a Java-type value. A setValue() method converts a Java-type value into a VRML-type value and sets it to the VRML field. Note that names for corresponding VRML-types and Java-types are identical.

Most of the setValue() methods and set1Value() methods are listed as "throws exception," meaning that errors are possible. It may be necessary to write exception handlers (using Java's catch() method) when those methods are used. Any method not listed as "throws exception" is guaranteed to generate no exceptions. Each method that throws an exception includes a prototype showing which exception(s) can be thrown.

B.6.2 Field class and ConstField class

All VRML data types have equivalent classes in Java. The Field class is the root of all field types.

    public abstract class Field implements Cloneable {
        // methods
    }

This class has two subclasses: read-only classes and writable classes

  1. Read-only classes
    These classes support the getValue() method. Some classes support additional convenience methods to get value(s) from the object.

    ConstSFBool, ConstSFColor, ConstMFColor, ConstSFFloat, ConstMFFloat, ConstSFImage, ConstSFInt32, ConstMFInt32, ConstSFNode, ConstMFNode, ConstSFRotation, ConstMFRotation, ConstSFString, ConstMFString, ConstSFVec2f, ConstMFVec2f, ConstSFVec3f, ConstMFVec3f, ConstSFTime, ConstMFTime

  2. Writable classes
    These classes support both getValue() and setValue() methods. If the class name is prefixed with MF(meaning that it is a multiple valued field class), the class also supports the set1Value(), addValue() and insertValue() methods. Some classes support additional convenience methods to get and set value(s) from the object.
  3. SFBool, SFColor, MFColor, SFFloat, MFFloat, SFImage, SFInt32, MFInt32, SFNode, MFNode, SFRotation, MFRotation, SFString, MFString, SFVec2f, MFVec2f, SFVec3f, MFVec3f, SFTime, MFTime

The Java Field class and its subclasses have several methods to get and set values: getSize(), getValue(), get1Value(), setValue(), set1Value(), addValue(), insertValue(), clear(), delete() and toString(). In these methods, getSize(), get1Value(), set1Value(), addValue(), insertValue(), clear() and delete() are only available for multiple value field classes(MF classes). See also "B.6.3 Array handling" and "B.9.2.1 vrml Package" for each class' methods definition.

  1. getSize()
    is the method to return the number of elements of each multiple value field class(MF class).
  2. getValue()
    is the method to convert a VRML-type value into a Java-type value and return it.
  3. get1Value(int index)
    is the method to convert a single VRML-type value (index-th element of an array) and return it as a single Java-type value. The index of the first element is 0. Attempting to get an element beyond the length of the element array throws an exception (ArrayIndexOutOfBoundsException).
  4. setValue(value)
    is the method to convert a Java-type value into a VRML-type value and send it to the VRML field.
  5. set1Value(int index, value)
    is the method to convert from a Java-type value to a VRML-type value and send it to the index-th element of a VRML multiple-valued field. The index of the first element is 0. Attempting to send an element beyond the length of the element array throws an exception (ArrayIndexOutOfBoundsException).
  6. addValue(value)
    is the method to convert from a Java-type value to a VRML-type value and append it to a VRML MF node, thus adding element.
  7. insertValue(int index, value)
    is the method to convert from a Java-type value to a VRML-type value and insert it as a new element at the index-th position. The index of the first element is 0. Attempting to insert the element beyond the length of the element array throws an exception (ArrayIndexOutOfBoundsException).
  8. clear()
    is the method to clear all elements from the MF field so that it has no more elements in it.
  9. delete(int index)
    is the method to delete the index-th element from the MF field and then the length of the element array is decreased by one. The index of the first element is 0. Attempting to delete the element beyond the length of the element array throws an exception (ArrayIndexOutOfBoundsException).
  10. toString()
    is the method to return a String containing the VRML utf8 encoded value (or values) of the equivalent of the field. In the case of the SFNode(ConstSFNode) and MFNode (ConstMFNode),

B.6.3 Array handling

Some constructors and other methods of the field classes take an array as an argument.

  1. A single-dimensional array
    Some constructors and other methods of the following classes take a single-dimensional array as an argument. The array is treated as follows:
    1. ConstSFColor, ConstMFColor, SFColor and MFColor
    2.         float colors[]
      

      colors[] consists of a set of three float-values (representing red, green and blue).

    3. ConstSFRotation, ConstMFRotation, SFRotation and MFRotation
    4.         float rotations[]
      

      rotations[] consists of a set of four float-values (representing axisX, axisY, axisZ and angle).

    5. ConstSFVec2f, ConstMFVec2f, SFVec2f and MFVec2f
    6.         float vec2s[]
      

      vec2s[] consists of a set of two float-values (representing x and y).

    7. ConstSFVec3f, ConstMFVec3f, SFVec3f and MFVec3f
    8.         float vec3s[]
      

      vec3s[] consists of a set of three float-values (representing x, y and z).

  2. A single integer and a single-dimensional array
    Some constructors and other methods take a single integer value (called size) and a single-dimensional array as arguments: for example, MFFloat(int size, float values[]). The size parameter specifies the number of valid elements in the array - from 0-th element to (size - 1)-th element - all other values are ignored. The same rule for a single-dimensional array is applied to the valid elements. This means that the method may be passed an array of length size or larger.
  3. An array of arrays
    Some constructors and other methods alternatively take an array of arrays as an argument. The array is treated as follows:
    1. ConstMFColor and MFColor
    2.         float colors[][]
      

      colors[][] consists of an array of three float-values (representing red, green and blue).

    3. ConstMFRotation and MFRotation
    4.         float rotations[][]
      

      rotations[][] consists of an array of four float-values (representing axisX, axisY, axisZ and angle).

    5. ConstMFVec2f and MFVec2f
    6.         float vec2s[][]
      

      vec2s[][] consists of an array of two float-values (representing x and y).

    7. ConstMFVec3f and MFVec3f
    8.         float vec3s[][]
      

      vec3s[][] consists of an array of three float-values (representing x, y and z).

The following describes how arrays are interpreted in detail for each constructor and method.

Suppose NA represents the number of elements in the array specified as an argument of some constructors and other methods, and NT represents the number of elements which the target object requires or has. For example, if the target object is SFColor, it requires exactly 3 float values.

In the following description, suppose SF* represents subclasses of Field class, ConstSF* represents subclasses of ConstField class, MF* represents subclasses of MField class and ConstMF* represents subclasses of ConstMField class.

  1. A single-dimensional array
    In the following description, if the target object is
    1. For SF* objects and ConstSF* objects

      For all constructors and methods which take a single-dimensional array as an argument, the following rules are applied.

      NA
      shall be larger than or equal to NT. If NA is larger than NT, the elements from the 0-th to the (NT - 1)-th element are used and remaining elements are ignored. Otherwise, an exception(ArrayIndexOutOfBoundsException) is thrown.
    2. For example, when the array is used as an argument of the setValue() for SFColor, the array shall contain at least 3 float values. If the array contains more than 3 float values, the first 3 values are used.

    3. For MF* objects and ConstMF* objects
  2. A single integer and a single-dimensional array
    For all constructors and methods which take a single integer value (called size) and a single-dimensional array arguments; for example, MFFloat(int size, float values[]), the following rule is applied.

    The size parameter specifies the number of valid elements in the array from the 0-th element to the (size - 1)-th element; all other values are ignored. This means that the method may be passed an array of length size or larger.
  3. The valid elements are copied to a new array and the rules for a single-dimensional array are applied to the new array for each methods.

  4. An array of arrays
    This argument is used only for MF* objects and ConstMF* objects. In the following case, suppose NA is the number of arrays (for example float f[4][3], NA is 4) specified as an argument of some constructors and other methods and NT is the return value of getSize() method of each object.

B.6.4 Node class

The Node class has several methods: getType(), getEventOut(), getEventIn(), getExposedField(), getBrowser() and toString().

  1. String getType()
    is the method to return the type of the node.
  2. ConstField getEventOut(String eventOutName)
    is the method to get the reference to the node's eventOut whose name is eventOutName. The return value can be converted to an appropriate Java Field class or its subclasses, (see "B.6.2 Field class and ConstField class").
  3. Field getEventIn(String eventInName)
    is the method to get the reference to the node's eventIn whose name is eventInName. The return value can be converted to an appropriate Java Field class or its subclasses, (see "B.6.2 Field class and ConstField class"). EventIn is a write-only field. When you call getValue() method on a Field object obtained by getEventIn() method, the return value is unspecified.
  4. Field getExposedField(String exposedFieldName)
    is the method to get the reference to the node's 'exposedField' whose name is exposedFieldName. The return value can be converted to an appropriate Java Field class or its subclasses, (see "B.6.2 Field class and ConstField class").
  5. Browser getBrowser()
    is method to get the browser object that this node is contained in (see "B.6.5 Browser class").
  6. String toString()
    is the same as toString() method of SFNode (ConstSFNode).

When you call the setValue(), set1Value(), addValue(), insertValue(), delete() or clear() method on a Field object obtained by the getExposedField() method, the call generates an eventOut in the VRML scene (see also "B.6.3 Array handling"). The effect of this eventOut is specified by the associated Route in the VRML scene. In the case of the set1Value(), addValue(), insertValue() or delete() methods, essentially all elements of VRML node's exposedField are retrieved, then the value specified as an argument is set, added, inserted or deleted (as appropriate) to/from the elements, then stored as the elements in the corresponding VRML node's exposedField, and then the elements are sent as an eventOut. In the case of the clear() method, all elements of VRML node's exposedField are cleared (see the definition of clear() method).

When you call setValue() or clear() method on a Field object obtained by getEventIn() method, the call generates an eventIn to the Script node. When you call the set1Value(), addValue(), insertValue() or delete() method on the Field object, an exception (InvalidFieldChangeException) is thrown.

B.6.5 Browser class

This section lists the public Java interfaces to the Browser class, which allows scripts to get and set browser information. For descriptions of the following methods, see "4.12.10 Browser Script Interface." Table B.1 lists the Browser class methods.

Table B.1: Browser class methods

Return value

Method name

String getName()
String getVersion()
float getCurrentSpeed()
float getCurrentFrameRate()
String getWorldURL()
void replaceWorld(BaseNode[] nodes)
BaseNode[] createVrmlFromString(String vrmlSyntax)
void createVrmlFromURL(String[] url, BaseNode node

                  String event)

void addRoute(BaseNode fromNode, String fromEventOut,

         BaseNode toNode, String toEventIn)

void deleteRoute(BaseNode fromNode,  String fromEventOut, 

            BaseNode toNode, String toEventIn)

void loadURL(String[] url, String[] parameter)
void setDescription(String description)

See "B.9.2.1 vrml Package" for each method's definition.

Table B.2 contains conversions from the types used in Browser class to Java types.

Table B.2: VRML and Java types

VRML type

Java type

SFString

String

SFFloat

float

MFString

String[]

MFNode

BaseNode[]

When a relative URL is specified as an argument of loadURL() and createVrmlFromURL(), the path is relative to the VRML file that contains the Script node.

B.6.6 User-defined classes and packages

The Java classes defined by a user can be used in the Java program. They are first searched from the directories specified in the CLASSPATH environment variable and then the directory where the Java program is placed.

If the Java class is in a package, this package is searched from the directories specified in the CLASSPATH environment variable and then the directory where the Java program is placed.

B.6.7 Standard Java packages

Java programs have access to the full set of classes available in java.*. All parts of Java are required to work as "normal" for Java. So all methods specified in this annex are required to be thread-safe. The security model is browser specific.

B.7 Exceptions

Java methods may throw the following exceptions:

  1. InvalidFieldException
    is thrown at the time getField() is executed and the field name is invalid.
  2. InvalidEventInException
    is thrown at the time getEventIn() is executed and the eventIn name is invalid.
  3. InvalidEventOutException
    is thrown at the time getEventOut() or getEventOut() is executed and the eventOut name is invalid.
  4. InvalidExposedFieldException
    is thrown at the time getExposedField() is executed and the exposedField name is invalid.
  5. InvalidVRMLSyntaxException
    is thrown at the time createVrmlFromString(), createVrmlFromURL() or loadURL() is executed and the vrml string is invalid.
  6. InvalidRouteException
    is thrown at the time addRoute() or deleteRoute() is executed and one or more the arguments is invalid.
  7. InvalidFieldChangeException
    may be thrown as a result of all sorts of illegal field changes, for example:
    1. Adding a node from one World as the child of a node in another World.
    2. Creating a circularity in a scene graph.
    3. Setting an invalid string on enumerated fields, such as the fogType field of the Fog node.
    4. Calling set1Value(), addValue() or delete() on a Field object obtained by the getEventIn() method.

    It is not guaranteed that such exceptions will be thrown.

  8. ArrayIndexOutOfBoundsException
    is generated at the time getValue(), set1Value(), insertValue() or delete() is executed and the index is out of bound (see "B.6.2 Field class and ConstField class"). This is the standard exception defined in the Java Array class.

If exceptions are not redefined by authors, a browser's behavior is unspecified (see "B.10 Example of exception class").

B.8 Examples

The following is an example of a Script node which determines whether a given color contains a lot of red. The Script node exposes a color field, an eventIn, and an eventOut:

Script {
    field    SFColor currentColor 0 0 0
    eventIn  SFColor colorIn
    eventOut SFBool  isRed
    url      "Example4.class"
}

The following is the source code for the Example4.java file that gets called every time an eventIn is routed to the above Script node:

Example4.java:

Details on when the methods defined in Example4.java are called may be found in "4.10.3 Execution Model."


Example5 createVrmlFromUrl

DEF Example5 Script {
   url "Example5.class"
   field   MFString target_url "foo.wrl"
   eventIn MFNode   nodesLoaded
   eventIn SFBool   trigger_event
}

Example5.java:
  import vrml.*;
  import vrml.field.*;
  import vrml.node.*;

  public class Example5 extends Script {
      private MFString target_url; // field
      private Browser browser;

      public void initialize(){
          target_url = (MFString)getField("target_url");
          browser = this.getBrowser();
      }

      public void processEvent(Event e){
          if(e.getName().equals("trigger_event")){
               // do something and then fetch values
               String[] urls;
               urls = new String[target_url.getSize()];
               target_url.getValue(urls);
               browser.createVrmlFromURL(urls, this, "nodesLoaded");
          }
          if(e.getName().equals("nodesLoaded")){
              // do something
          }
      }
  }



Example6 addRoute

DEF Sensor TouchSensor {}
DEF Example Script {
   url     "Example6.class"
   field   SFNode fromNode USE Sensor
   eventIn SFBool clicked
   eventIn SFBool trigger_event
}
Example6.java:
  import vrml.*;
  import vrml.field.*;
  import vrml.node.*;

  public class Example6 xtends Script {
      private SFNode fromNode;
      private Browser browser;

      public void initialize(){
          fromNode = (SFNode) getField("fromNode");
          browser = this.getBrowser();
      }

      public void processEvent(Event e){
          if(e.getName().equals("trigger_event")){
              // do something and then add routing
              browser.addRoute(fromNode.getValue(), "isActive", this, "clicked");
          }
          if(e.getName().equals("clicked")){
              // do something
          }
      }
  }

B.9 Class definitions

B.9.1 Class hierarchy

The classes are divided into three packages: vrml, vrml.field and vrml.node.

java.lang.Object
     |
     +- vrml.Event
     +- vrml.Browser
     +- vrml.Field
     |       +- vrml.field.SFBool
     |       +- vrml.field.SFColor
     |       +- vrml.field.SFFloat
     |       +- vrml.field.SFImage
     |       +- vrml.field.SFInt32
     |       +- vrml.field.SFNode
     |       +- vrml.field.SFRotation
     |       +- vrml.field.SFString
     |       +- vrml.field.SFTime
     |       +- vrml.field.SFVec2f
     |       +- vrml.field.SFVec3f
     |       |
     |       +- vrml.MField
     |       |       +- vrml.field.MFColor
     |       |       +- vrml.field.MFFloat
     |       |       +- vrml.field.MFInt32
     |       |       +- vrml.field.MFNode
     |       |       +- vrml.field.MFRotation
     |       |       +- vrml.field.MFString
     |       |       +- vrml.field.MFTime
     |       |       +- vrml.field.MFVec2f
     |       |       +- vrml.field.MFVec3f
     |       |
     |       +- vrml.ConstField
     |               +- vrml.field.ConstSFBool
     |               +- vrml.field.ConstSFColor
     |               +- vrml.field.ConstSFFloat
     |               +- vrml.field.ConstSFImage
     |               +- vrml.field.ConstSFInt32
     |               +- vrml.field.ConstSFNode
     |               +- vrml.field.ConstSFRotation
     |               +- vrml.field.ConstSFString
     |               +- vrml.field.ConstSFTime
     |               +- vrml.field.ConstSFVec2f
     |               +- vrml.field.ConstSFVec3f
     |               |
     |               +- vrml.ConstMField
     |                       +- vrml.field.ConstMFColor
     |                       +- vrml.field.ConstMFFloat
     |                       +- vrml.field.ConstMFInt32
     |                       +- vrml.field.ConstMFNode
     |                       +- vrml.field.ConstMFRotation
     |                       +- vrml.field.ConstMFString
     |                       +- vrml.field.ConstMFTime
     |                       +- vrml.field.ConstMFVec2f
     |                       +- vrml.field.ConstMFVec3f
     |
     +- vrml.BaseNode
             +- vrml.node.Node
             +- vrml.node.Script

java.lang.Exception
     +- java.lang.RuntimeException
             +- vrml.InvalidEventInException
             +- vrml.InvalidEventOutException
             +- vrml.InvalidExposedFieldException
             +- vrml.InvalidFieldChangeException
             +- vrml.InvalidFieldException
             +- vrml.InvalidRouteException
             +- vrml.InvalidVRMLSyntaxException

B.9.2 VRML packages

B.9.2.1 vrml Package

package vrml;

public class Event implements Cloneable {
  public String getName();
  public double getTimeStamp();
  public ConstField getValue();
  public Object clone();
  // This overrides a method in Object
  public String toString();
}

public class Browser {
  private Browser();
  // This overrides a method in Object
  public String toString();

  // Browser interface
  public String getName();    
  public String getVersion();    

  public float getCurrentSpeed();

  public float getCurrentFrameRate();

  public String getWorldURL();
  public void replaceWorld(BaseNode[] nodes);

  public BaseNode[] createVrmlFromString(String vrmlSyntax)
    throws InvalidVRMLSyntaxException;

  public void createVrmlFromURL(String[] url, BaseNode node, String event)

  public void addRoute(BaseNode fromNode, String fromEventOut,
    BaseNode toNode, String toEventIn);

  public void deleteRoute(BaseNode fromNode, String fromEventOut,
    BaseNode toNode, String toEventIn);

  public void loadURL(String[] url, String[] parameter)

  public void setDescription(String description);
}

public abstract class Field implements Cloneable
{
   public Object clone();
}

public abstract class MField extends Field
{
   public abstract int getSize();
   public abstract void clear();
   public abstract void delete(int index);
}

public abstract class ConstField extends Field
{
}

public abstract class ConstMField extends ConstField
{
   public abstract int getSize();
}

//
// This is the general BaseNode class
// 
public abstract class BaseNode 
{
  // Returns the type of the node.  If the node is a prototype
  //   it returns the name of the prototype.
  public String getType();

  // Get the Browser that this node is contained in.
  public Browser getBrowser();
}

B.9.2.2 vrml.field Package

package vrml.field;

public class SFBool extends Field
{
   public SFBool();
   public SFBool(boolean value);
   public boolean getValue();
   public void setValue(boolean b);
   public void setValue(ConstSFBool b);
   public void setValue(SFBool b);
   // This overrides a method in Object
   public String toString();
}

public class SFColor extends Field
{
   public SFColor();
   public SFColor(float red, float green, float blue);
   public void getValue(float colors[]);
   public float getRed();
   public float getGreen();
   public float getBlue();
   public void setValue(float colors[]);
   public void setValue(float red, float green, float blue);
   public void setValue(ConstSFColor color);
   public void setValue(SFColor color);
   // This overrides a method in Object
   public String toString();
}

public class SFFloat extends Field
{
   public SFFloat();
   public SFFloat(float f);
   public float getValue();
   public void setValue(float f);
   public void setValue(ConstSFFloat f);
   public void setValue(SFFloat f);
   // This overrides a method in Object
   public String toString();
}

public class SFImage extends Field
{
   public SFImage();
   public SFImage(int width, int height, int components, byte pixels[]);
   public int getWidth();
   public int getHeight();
   public int getComponents();
   public void getPixels(byte pixels[]);
   public void setValue(int width, int height, int components,
                        byte pixels[]);
   public void setValue(ConstSFImage image);
   public void setValue(SFImage image);
   // This overrides a method in Object
   public String toString();
}

public class SFInt32 extends Field
{
   public SFInt32();
   public SFInt32(int value);
   public int getValue();
   public void setValue(int i);
   public void setValue(ConstSFInt32 i);
   public void setValue(SFInt32 i);
   // This overrides a method in Object
   public String toString();
}

public class SFNode extends Field
{
   public SFNode();
   public SFNode(BaseNode node);

   public BaseNode getValue();
   public void setValue(BaseNode node);
   public void setValue(ConstSFNode node);
   public void setValue(SFNode node);
   // This overrides a method in Object
   public String toString();
}

public class SFRotation extends Field
{
   public SFRotation();
   public SFRotation(float axisX, float axisY, float axisZ, float angle);
   public void getValue(float rotations[]);
   public void setValue(float rotations[]);
   public void setValue(float axisX, float axisY, float axisZ, float angle);
   public void setValue(ConstSFRotation rotation);
   public void setValue(SFRotation rotation);
   // This overrides a method in Object
   public String toString();
}

public class SFString extends Field
{
   public SFString();
   public SFString(String s);
   public String getValue();
   public void setValue(String s);
   public void setValue(ConstSFString s);
   public void setValue(SFString s);
   // This overrides a method in Object
   public String toString();
}

public class SFTime extends Field
{
   public SFTime();
   public SFTime(double time);
   public double getValue();
   public void setValue(double time);
   public void setValue(ConstSFTime time);
   public void setValue(SFTime time);
   // This overrides a method in Object
   public String toString();
}

public class SFVec2f extends Field
{
   public SFVec2f();
   public SFVec2f(float x, float y);
   public void getValue(float vec2s[]);
   public float getX();
   public float getY();
   public void setValue(float vec2s[]);

   public void setValue(float x, float y);
   public void setValue(ConstSFVec2f vec);
   public void setValue(SFVec2f vec);
   // This overrides a method in Object
   public String toString();
}

public class SFVec3f extends Field
{
   public SFVec3f();
   public SFVec3f(float x, float y, float z);
   public void getValue(float vec3s[]);
   public float getX();
   public float getY();
   public float getZ();
   public void setValue(float vec3s[]);
   public void setValue(float x, float y, float z);
   public void setValue(ConstSFVec3f vec);
   public void setValue(SFVec3f vec);
   // This overrides a method in Object
   public String toString();
}

public class MFColor extends MField
{
   public MFColor();
   public MFColor(float colors[][]);
   public MFColor(float colors[]);
   public MFColor(int size, float colors[]);

   public void getValue(float colors[][]);
   public void getValue(float colors[]);

   public void setValue(float colors[][]);
   public void setValue(float colors[]);
   public void setValue(int size, float colors[]);
   /****************************************************
    color[0] ... color[size - 1] are used as color data
    in the way that color[0], color[1], and color[2] 
    represent the first color. The number of colors
    is defined as "size / 3".
    ***************************************************/
   public void setValue(MFColor colors);
   public void setValue(ConstMFColor colors);

   public void get1Value(int index, float colors[]);
   public void get1Value(int index, SFColor color);

   public void set1Value(int index, ConstSFColor color);
   public void set1Value(int index, SFColor color);
   public void set1Value(int index, float red, float green, float blue);

   public void addValue(ConstSFColor color);
   public void addValue(SFColor color);
   public void addValue(float red, float green, float blue);

   public void insertValue(int index, ConstSFColor color);
   public void insertValue(int index, SFColor color);
   public void insertValue(int index, float red, float green, float blue);
   // This overrides a method in Object
   public String toString();
}


public class MFFloat extends MField
{
   public MFFloat();
   public MFFloat(int size, float values[]);
   public MFFloat(float values[]);

   public void getValue(float values[]);

   public void setValue(float values[]);
   public void setValue(int size, float values[]);
   public void setValue(MFFloat value);
   public void setValue(ConstMFFloat value);

   public float get1Value(int index);

   public void set1Value(int index, float f);
   public void set1Value(int index, ConstSFFloat f);
   public void set1Value(int index, SFFloat f);

   public void addValue(float f);
   public void addValue(ConstSFFloat f);
   public void addValue(SFFloat f);

   public void insertValue(int index, float f);
   public void insertValue(int index, ConstSFFloat f);
   public void insertValue(int index, SFFloat f);
   // This overrides a method in Object
   public String toString();
}

public class MFInt32 extends MField
{
   public MFInt32();
   public MFInt32(int size, int values[]);
   public MFInt32(int values[]);

   public void getValue(int values[]);

   public void setValue(int values[]);
   public void setValue(int size, int values[]);
   public void setValue(MFInt32 value);
   public void setValue(ConstMFInt32 value);

   public int get1Value(int index);

   public void set1Value(int index, int i);
   public void set1Value(int index, ConstSFInt32 i);
   public void set1Value(int index, SFInt32 i);

   public void addValue(int i);
   public void addValue(ConstSFInt32 i);
   public void addValue(SFInt32 i);

   public void insertValue(int index, int i);
   public void insertValue(int index, ConstSFInt32 i);
   public void insertValue(int index, SFInt32 i);
   // This overrides a method in Object
   public String toString();
}

public class MFNode extends MField
{
   public MFNode();
   public MFNode(int size, BaseNode node[]);
   public MFNode(BaseNode node[]);

   public void getValue(BaseNode node[]);

   public void setValue(BaseNode node[]);
   public void setValue(int size, BaseNode node[]);
   public void setValue(MFNode node);
   public void setValue(ConstMFNode node);

   public BaseNode get1Value(int index);

   public void set1Value(int index, BaseNode node);
   public void set1Value(int index, ConstSFNode node);
   public void set1Value(int index, SFNode node);

   public void addValue(BaseNode node);
   public void addValue(ConstSFNode node);
   public void addValue(SFNode node);

   public void insertValue(int index, BaseNode node);
   public void insertValue(int index, ConstSFNode node);
   public void insertValue(int index, SFNode node);

   // This overrides a method in Object
   public String toString();
}

public class MFRotation extends MField
{
   public MFRotation();
   public MFRotation(float rotations[][]);
   public MFRotation(float rotations[]);
   public MFRotation(int size, float rotations[]);

   public void getValue(float rotations[][]);
   public void getValue(float rotations[]);

   public void setValue(float rotations[][]);
   public void setValue(float rotations[]);
   public void setValue(int size, float rotations[]);
   public void setValue(MFRotation rotations);
   public void setValue(ConstMFRotation rotations);

   public void get1Value(int index, float rotations[]);
   public void get1Value(int index, SFRotation rotation);

   public void set1Value(int index, ConstSFRotation rotation);
   public void set1Value(int index, SFRotation rotation);
   public void set1Value(int index, float axisX, float axisY, float axisZ, float angle);

   public void addValue(ConstSFRotation rotation);
   public void addValue(SFRotation rotation);
   public void addValue(float axisX, float axisY, float axisZ, float angle);

   public void insertValue(int index, ConstSFRotation rotation);
   public void insertValue(int index, SFRotation rotation);
   public void insertValue(int index, float axisX, float axisY, float axisZ, float angle);

   // This overrides a method in Object
   public String toString();
}

public class MFString extends MField
{
   public MFString();
   public MFString(int size, String s[]);
   public MFString(String s[]);

   public void getValue(String s[]);

   public void setValue(String s[]);
   public void setValue(int size, String s[]);
   public void setValue(MFString s);
   public void setValue(ConstMFString s);

   public String get1Value(int index);

   public void set1Value(int index, String s);
   public void set1Value(int index, ConstSFString s);
   public void set1Value(int index, SFString s);

   public void addValue(String s);
   public void addValue(ConstSFString s);
   public void addValue(SFString s);

   public void insertValue(int index, String s);
   public void insertValue(int index, ConstSFString s);
   public void insertValue(int index, SFString s);

   // This overrides a method in Object
   public String toString();
}

public class MFTime extends MField
{
   public MFTime();
   public MFTime(int size, double times[]);
   public MFTime(double times[]);

   public void getValue(double times[]);

   public void setValue(double times[]);
   public void setValue(int size, double times[]);
   public void setValue(MFTime times);
   public void setValue(ConstMFTime times);

   public double get1Value(int index);

   public void set1Value(int index, double time);
   public void set1Value(int index, ConstSFTime time);
   public void set1Value(int index, SFTime time);

   public void addValue(double time);
   public void addValue(ConstSFTime time);
   public void addValue(SFTime time);

   public void insertValue(int index, double time);
   public void insertValue(int index, ConstSFTime time);
   public void insertValue(int index, SFTime time);

   // This overrides a method in Object
   public String toString();
}

public class MFVec2f extends MField
{
   public MFVec2f();
   public MFVec2f(float vec2s[][]);
   public MFVec2f(float vec2s[]);
   public MFVec2f(int size, float vec2s[]);

   public void getValue(float vec2s[][]);
   public void getValue(float vec2s[]);

   public void setValue(float vec2s[][]);
   public void setValue(float vec2s[]);
   public void setValue(int size, float vec2s[]);
   public void setValue(MFVec2f vecs);
   public void setValue(ConstMFVec2f vecs);

   public void get1Value(int index, float vec2s[]);
   public void get1Value(int index, SFVec2f vec);

   public void set1Value(int index, float x, float y);
   public void set1Value(int index, ConstSFVec2f vec);
   public void set1Value(int index, SFVec2f vec);

   public void addValue(float x, float y);
   public void addValue(ConstSFVec2f vec);
   public void addValue(SFVec2f vec);

   public void insertValue(int index, float x, float y);
   public void insertValue(int index, ConstSFVec2f vec);
   public void insertValue(int index, SFVec2f vec);

   // This overrides a method in Object
   public String toString();
}

public class MFVec3f extends MField
{
   public MFVec3f();
   public MFVec3f(float vec3s[][]);
   public MFVec3f(float vec3s[]);
   public MFVec3f(int size, float vec3s[]);

   public void getValue(float vec3s[][]);
   public void getValue(float vec3s[]);

   public void setValue(float vec3s[][]);
   public void setValue(float vec3s[]);
   public void setValue(int size, float vec3s[]);
   public void setValue(MFVec3f vecs);
   public void setValue(ConstMFVec3f vecs);

   public void get1Value(int index, float vec3s[]);
   public void get1Value(int index, SFVec3f vec);

   public void set1Value(int index, float x, float y, float z);
   public void set1Value(int index, ConstSFVec3f vec);
   public void set1Value(int index, SFVec3f vec);

   public void addValue(float x, float y, float z);
   public void addValue(ConstSFVec3f vec);
   public void addValue(SFVec3f vec);

   public void insertValue(int index, float x, float y, float z);
   public void insertValue(int index, ConstSFVec3f vec);
   public void insertValue(int index, SFVec3f vec);

   // This overrides a method in Object
   public String toString();
}

public class ConstSFBool extends ConstField
{
   public ConstSFBool(boolean value);
   public boolean getValue();
   // This overrides a method in Object
   public String toString();
}

public class ConstSFColor extends ConstField
{
   public ConstSFColor(float red, float green, float blue);
   public void getValue(float colors[]);
   public float getRed();
   public float getGreen();
   public float getBlue();
   // This overrides a method in Object
   public String toString();
}

public class ConstSFFloat extends ConstField
{
   public ConstSFFloat(float value);
   public float getValue();
   // This overrides a method in Object
   public String toString();
}

public class ConstSFImage extends ConstField
{
   public ConstSFImage(int width, int height, int components, byte pixels[]);
   public int getWidth();
   public int getHeight();
   public int getComponents();
   public void getPixels(byte pixels[]);
   // This overrides a method in Object
   public String toString();
}

public class ConstSFInt32 extends ConstField
{
   public ConstSFInt32(int value);
   public int getValue();
   // This overrides a method in Object
   public String toString();
}

public class ConstSFNode extends ConstField
{
   public ConstSFNode(BaseNode node);
   public BaseNode getValue();
   // This overrides a method in Object
   public String toString();
}

public class ConstSFRotation extends ConstField
{
   public ConstSFRotation(float axisX, float axisY, float axisZ, float angle);
   public void getValue(float rotations[]);
   // This overrides a method in Object
   public String toString();
}

public class ConstSFString extends ConstField
{
   public ConstSFString(String value);
   public String getValue();
   // This overrides a method in Object
   public String toString();
}

public class ConstSFTime extends ConstField
{
   public ConstSFTime(double time);
   public double getValue();
   // This overrides a method in Object
   public String toString();
}

public class ConstSFVec2f extends ConstField
{
   public ConstSFVec2f(float x, float y);
   public void getValue(float vec2s[]);
   public float getX();
   public float getY();
   // This overrides a method in Object
   public String toString();
}

public class ConstSFVec3f extends ConstField
{
   public ConstSFVec3f(float x, float y, float z);
   public void getValue(float vec3s[]);
   public float getX();
   public float getY();
   public float getZ();
   // This overrides a method in Object
   public String toString();
}

public class ConstMFColor extends ConstMField
{
   public ConstMFColor(float colors[][]);
   public ConstMFColor(float colors[]);
   public ConstMFColor(int size, float colors[]);

   public void getValue(float colors[][]);
   public void getValue(float colors[]);
   public void get1Value(int index, float colors[]);
   public void get1Value(int index, SFColor color);
   // This overrides a method in Object
   public String toString();
}

public class ConstMFFloat extends ConstMField
{
   public ConstMFFloat(int size, float values[]);
   public ConstMFFloat(float values[]);

   public void getValue(float values[]);
   public float get1Value(int index);
   // This overrides a method in Object
   public String toString();
}

public class ConstMFInt32 extends ConstMField
{
   public ConstMFInt32(int size, int values[]);
   public ConstMFInt32(int values[]);

   public void getValue(int values[]);
   public int get1Value(int index);
   // This overrides a method in Object
   public String toString();
}

public class ConstMFNode extends ConstMField
{
   public ConstMFNode(int size, BaseNode node[]);
   public ConstMFNode(BaseNode node[]);

   public void getValue(BaseNode node[]);
   public BaseNode get1Value(int index);
   // This overrides a method in Object
   public String toString();
}

public class ConstMFRotation extends ConstMField
{
   public ConstMFRotation(float rotations[][]);
   public ConstMFRotation(float rotations[]);
   public ConstMFRotation(int size, float rotations[]);

   public void getValue(float rotations[][]);
   public void getValue(float rotations[]);
   public void get1Value(int index, float rotations[]);
   public void get1Value(int index, SFRotation rotation);
   // This overrides a method in Object
   public String toString();
}

public class ConstMFString extends ConstMField
{
   public ConstMFString(int size, String s[]);
   public ConstMFString(String s[]);

   public void getValue(String values[]);
   public String get1Value(int index);
   // This overrides a method in Object
   public String toString();
}

public class ConstMFTime extends ConstMField
{
   public ConstMFTime(int size, double times[]);
   public ConstMFTime(double times[]);

   public void getValue(double times[]);
   public double get1Value(int index);
   // This overrides a method in Object
   public String toString();
}

public class ConstMFVec2f extends ConstMField
{
   public ConstMFVec2f(float vec2s[][]);
   public ConstMFVec2f(float vec2s[]);
   public ConstMFVec2f(int size, float vec2s[]);

   public void getValue(float vec2s[][]);
   public void getValue(float vec2s[]);
   public void get1Value(int index, float vec2s[]);
   public void get1Value(int index, SFVec2f vec);
   // This overrides a method in Object
   public String toString();
}

public class ConstMFVec3f extends ConstMField
{
   public ConstMFVec3f(float vec3s[][]);
   public ConstMFVec3f(float vec3s[]);
   public ConstMFVec3f(int size, float vec3s[]);

   public void getValue(float vec3s[][]);
   public void getValue(float vec3s[]);
   public void get1Value(int index, float vec3s[]);
   public void get1Value(int index, SFVec3f vec);
   // This overrides a method in Object
   public String toString();
}

B.9.2.3 vrml.node Package

package vrml.node;

//
// This is the general Node class
// 
public abstract class Node extends BaseNode
{ 
  
  // Get an EventIn by name. Return value is write-only.
  //   Throws an InvalidEventInException if eventInName isn't a valid
  //   eventIn name for a node of this type.
  public final Field getEventIn(String eventInName);

  // Get an EventOut by name. Return value is read-only.
  //   Throws an InvalidEventOutException if eventOutName isn't a valid
  //   eventOut name for a node of this type.
  public final ConstField getEventOut(String eventOutName);

  // Get an exposed field by name. 
  //   Throws an InvalidExposedFieldException if exposedFieldName isn't a valid
  //   exposedField name for a node of this type.
  public final Field getExposedField(String exposedFieldName);

  // This overrides a method in Object
  public String toString();
}

//
// This is the general Script class, to be subclassed by all scripts.
// Note that the provided methods allow the script author to explicitly
// throw tailored exceptions in case something goes wrong in the
// script.
//
public abstract class Script extends BaseNode
{ 
 
  // This method is called before any event is generated
  public void initialize();

  // Get a Field by name.
  //   Throws an InvalidFieldException if fieldName isn't a valid
  //   field name for a node of this type.
  protected final Field getField(String fieldName);

  // Get an EventOut by name.
  //   Throws an InvalidEventOutException if eventOutName isn't a valid
  //   eventOut name for a node of this type.
  protected final Field getEventOut(String eventOutName);

  // Get an EventIn by name.
  //   Throws an InvalidEventInException if eventInName isn't a valid
  //   eventIn name for a node of this type.
  protected final Field getEventIn(String eventInName);

  // processEvents() is called automatically when the script receives 
  //   some set of events. It shall not be called directly except by its subclass.
  //   count indicates the number of events delivered.
  public void processEvents(int count, Event events[]);

  // processEvent() is called automatically when the script receives 
  // an event. 
  public void processEvent(Event event);

  // eventsProcessed() is called after every invocation of processEvents().
  public void eventsProcessed()

  // shutdown() is called when this Script node is deleted.
  public void shutdown();

  // This overrides a method in Object
  public String toString();
}

B.10 Example of exception class

public class InvalidEventInException extends IllegalArgumentException
{
   /**
    * Constructs an InvalidEventInException with no detail message.
    */
   public InvalidEventInException(){
      super();
   }
   /**
    * Constructs an InvalidEventInException with the specified detail message.
    * A detail message is a String that describes this particular exception.
    * @param s the detail message
    */
   public InvalidEventInException(String s){
      super(s);
   }
}

public class InvalidEventOutException extends IllegalArgumentException
{
   public InvalidEventOutException(){
      super();
   }
   public InvalidEventOutException(String s){
      super(s);
   }
}

public class InvalidExposedFieldException extends IllegalArgumentException
{
   public InvalidExposedFieldException(){
      super();
   }
   public InvalidExposedFieldException(String s){
      super(s);
   }
}

public class InvalidFieldChangeException extends IllegalArgumentException
{
   public InvalidFieldChangeException(){
      super();
   }
   public InvalidFieldChangeException(String s){
      super(s);
   }
}

public class InvalidFieldException extends IllegalArgumentException
{
   public InvalidFieldException(){
      super();
   }
   public InvalidFieldException(String s){
      super(s);
   }
}

public class InvalidRouteException extends IllegalArgumentException
{
   public InvalidRouteException(){
      super();
   }
   public InvalidRouteException(String s){
      super(s);
   }
}

public class InvalidVRMLSyntaxException extends Exception
{
   public InvalidVRMLSyntaxException(){
      super();
   }
   public InvalidVRMLSyntaxException(String s){
      super(s);
   }
   // This overrides a method in Exception
   public String getMessage();
}

http://vag.vrml.org/VRML97/DIS/part1/java.html