Class ExtendedScriptingContext

java.lang.Object
org.bzdev.scripting.ScriptingContext
org.bzdev.scripting.ExtendedScriptingContext

public class ExtendedScriptingContext extends ScriptingContext
Extended ScriptingContext class.

This class provides methods named create that will create a new instance of a class using the class or class name as create's first argument. The first argument for these methods should be either the class of the object that is to be created or a string containing the fully-qualified class name of that class. The remaining arguments are those that a constructor can use. Up to 11 arguments are supported. The original motivation for these methods was a work-around for a bug, but the methods may also be useful when a number of classes have constructors that take the same arguments and the choice of which class to use is made at run time. The create methods specify Object as the type of the object returned, which works for scripting languages as these typically are not strongly typed.

There are two methods named createArray that will create an array of a specified size, and whose first argument is the class of an array's components or the fully-qualified name of the class of the array's components. This can be used by a scripting language to create a Java array conveniently.

There are a also series of methods named createAndInitArray. The first argument of these methods are also either the class of an array's components or the fully-qualified name of the class of the array's components. The remaining arguments are the values used to initialize the array.

Several methods aid in the use of Java classes: importClass(String), importClass(String,String), importClasses(String,Object), and finishImport(). These methods allow Java classes to be imported and bound to variables in the script's name space. The method importClasses(String,Object) will import multiple classes using the scripting language to represent the class names in a succinct form. After a sequence of calls to importClass and importClasses, the method finishImport() must be called.

Finally, the scrunner command will run scripts in an environment where a variable names scripting is predefined. This variable is an instance of this class.

  • Constructor Details

    • ExtendedScriptingContext

      public ExtendedScriptingContext(ScriptingContext parent)
      Constructor. Unless methods are overridden, the parent scripting context provides the scripting language, script engine, and bindings. This scripting context will be trusted if and only if the parent's scripting context is trusted.
      Parameters:
      parent - the parent scripting context; null if there is none.
  • Method Details

    • createArray

      public Object createArray(Class<?> clazz, int n) throws NegativeArraySizeException
      Create an array given its class. This is a convenience method so that a script does not have to call java.lang.reflect.Array.newInstance(...). The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the name of a class
      n - the number of elements in the array
      Returns:
      an array of size n
      Throws:
      NegativeArraySizeException - the array size was negative
    • createArray

      public Object createArray(String className, int n) throws NegativeArraySizeException, ClassNotFoundException
      Create an array given the class name of its element type. This is a convenience method so that a script does not have to call java.lang.reflect.Array.newInstance(...). For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".
      Parameters:
      className - the name of a class
      n - the number of elements in the array
      Returns:
      an array of size n
      Throws:
      NegativeArraySizeException - the array size was negative
      ClassNotFoundException - the class could not be found
    • createAndInitArray

      public Object createAndInitArray(Class<?> clazz) throws IllegalArgumentException, NullPointerException
      Create a zero-length array given the class of its components.

      The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the class of the array components
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
    • createAndInitArray

      public Object createAndInitArray(String className) throws IllegalArgumentException, NullPointerException, ClassNotFoundException
      Create a zero-length array given the name of the class of its components.

      For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".

      Parameters:
      className - the fully-qualified name of the class of the array's components
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
      ClassNotFoundException - the class corresponding to the class name could not be found
    • createAndInitArray

      public Object createAndInitArray(Class<?> clazz, Object arg0) throws IllegalArgumentException, NullPointerException
      Create and initialize an array of length one given the class of its components.

      The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the class of the array components
      arg0 - the 0th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
    • createAndInitArray

      public Object createAndInitArray(String className, Object arg0) throws IllegalArgumentException, NullPointerException, ClassNotFoundException
      Create and initialize an array of length one given the name of the class of its components

      For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".

      Parameters:
      className - the fully-qualified name of the class of the array's components
      arg0 - the 0th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
      ClassNotFoundException - the class corresponding to the class name could not be found
    • createAndInitArray

      public Object createAndInitArray(Class<?> clazz, Object arg0, Object arg1) throws IllegalArgumentException, NullPointerException
      Create and initialize an array of length two given the class of its components.

      The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the class of the array components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
    • createAndInitArray

      public Object createAndInitArray(String className, Object arg0, Object arg1) throws IllegalArgumentException, NullPointerException, ClassNotFoundException
      Create and initialize an array of length two given the name of the class of its components

      For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".

      Parameters:
      className - the fully-qualified name of the class of the array's components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
      ClassNotFoundException - the class corresponding to the class name could not be found
    • createAndInitArray

      public Object createAndInitArray(Class<?> clazz, Object arg0, Object arg1, Object arg2) throws IllegalArgumentException, NullPointerException
      Create and initialize an array of length three given the class of its components.

      The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the class of the array components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
    • createAndInitArray

      public Object createAndInitArray(String className, Object arg0, Object arg1, Object arg2) throws IllegalArgumentException, NullPointerException, ClassNotFoundException
      Create an array of length three given the name of the class of its components.

      For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".

      Parameters:
      className - the fully-qualified name of the class of the array's components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
      ClassNotFoundException - the class corresponding to the class name could not be found
    • createAndInitArray

      public Object createAndInitArray(Class<?> clazz, Object arg0, Object arg1, Object arg2, Object arg3) throws IllegalArgumentException, NullPointerException
      Create and initialize an array of length four given the class of its components.

      The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the class of the array components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
    • createAndInitArray

      public Object createAndInitArray(String className, Object arg0, Object arg1, Object arg2, Object arg3) throws IllegalArgumentException, NullPointerException, ClassNotFoundException
      Create an array of length four given the name of the class of its components.

      For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".

      Parameters:
      className - the fully-qualified name of the class of the array's components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
      ClassNotFoundException - the class corresponding to the class name could not be found
    • createAndInitArray

      public Object createAndInitArray(Class<?> clazz, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4) throws IllegalArgumentException, NullPointerException
      Create and initialize an array of length five given the class of its components.

      The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the class of the array components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
    • createAndInitArray

      public Object createAndInitArray(String className, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4) throws IllegalArgumentException, NullPointerException, ClassNotFoundException
      Create an array of length five given the name of the class of its components.

      For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".

      Parameters:
      className - the fully-qualified name of the class of the array's components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
      ClassNotFoundException - the class corresponding to the class name could not be found
    • createAndInitArray

      public Object createAndInitArray(Class<?> clazz, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws IllegalArgumentException, NullPointerException
      Create and initialize an array of length six given the class of its components.

      The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the class of the array components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      arg5 - the 5th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
    • createAndInitArray

      public Object createAndInitArray(String className, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws IllegalArgumentException, NullPointerException, ClassNotFoundException
      Create an array of length six given the name of the class of its components.

      For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".

      Parameters:
      className - the fully-qualified name of the class of the array's components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      arg5 - the 5th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
      ClassNotFoundException - the class corresponding to the class name could not be found
    • createAndInitArray

      public Object createAndInitArray(Class<?> clazz, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws IllegalArgumentException, NullPointerException
      Create and initialize an array of length seven given the class of its components.

      The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the class of the array components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      arg5 - the 5th component of the array
      arg6 - the 6th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
    • createAndInitArray

      public Object createAndInitArray(String className, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws IllegalArgumentException, NullPointerException, ClassNotFoundException
      Create an array of length seven given the name of the class of its components.

      For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".

      Parameters:
      className - the fully-qualified name of the class of the array's components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      arg5 - the 5th component of the array
      arg6 - the 6th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
      ClassNotFoundException - the class corresponding to the class name could not be found
    • createAndInitArray

      public Object createAndInitArray(Class<?> clazz, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) throws IllegalArgumentException, NullPointerException
      Create and initialize an array of length eight given the class of its components.

      The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the class of the array components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      arg5 - the 5th component of the array
      arg6 - the 6th component of the array
      arg7 - the 7th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
    • createAndInitArray

      public Object createAndInitArray(String className, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) throws IllegalArgumentException, NullPointerException, ClassNotFoundException
      Create an array of length eight given the name of the class of its components.

      For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".

      Parameters:
      className - the fully-qualified name of the class of the array's components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      arg5 - the 5th component of the array
      arg6 - the 6th component of the array
      arg7 - the 7th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
      ClassNotFoundException - the class corresponding to the class name could not be found
    • createAndInitArray

      public Object createAndInitArray(Class<?> clazz, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8) throws IllegalArgumentException, NullPointerException
      Create and initialize an array of length nine given the class of its components.

      The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the class of the array components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      arg5 - the 5th component of the array
      arg6 - the 6th component of the array
      arg7 - the 7th component of the array
      arg8 - the 8th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
    • createAndInitArray

      public Object createAndInitArray(String className, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8) throws IllegalArgumentException, NullPointerException, ClassNotFoundException
      Create an array of length nine given the name of the class of its components.

      For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".

      Parameters:
      className - the fully-qualified name of the class of the array's components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      arg5 - the 5th component of the array
      arg6 - the 6th component of the array
      arg7 - the 7th component of the array
      arg8 - the 8th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
      ClassNotFoundException - the class corresponding to the class name could not be found
    • createAndInitArray

      public Object createAndInitArray(Class<?> clazz, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9) throws IllegalArgumentException, NullPointerException
      Create and initialize an array of length ten given the class of its components.

      The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the class of the array components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      arg5 - the 5th component of the array
      arg6 - the 6th component of the array
      arg7 - the 7th component of the array
      arg8 - the 8th component of the array
      arg9 - the 9th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
    • createAndInitArray

      public Object createAndInitArray(String className, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9) throws IllegalArgumentException, NullPointerException, ClassNotFoundException
      Create an array of length ten given the name of the class of its components.

      For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".

      Parameters:
      className - the fully-qualified name of the class of the array's components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      arg5 - the 5th component of the array
      arg6 - the 6th component of the array
      arg7 - the 7th component of the array
      arg8 - the 8th component of the array
      arg9 - the 9th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
      ClassNotFoundException - the class corresponding to the class name could not be found
    • createAndInitArray

      public Object createAndInitArray(Class<?> clazz, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10) throws IllegalArgumentException, NullPointerException
      Create and initialize an array of length eleven given the class of its components.

      The classes Byte, Character, Double, Integer, Long, Short, have fields named "TYPE" that provide the class names for the primitive types "byte", "char", "double", "int", "long", and "short" respectively.

      Note: for Java 1.8 and 1.7, the default scripting engine (ECMAScript) differ in how objects that represent a Java class are treated. For Java 1.7, which uses the Rhino script engine, the variable used to represent a class is automatically converted to a Java class when this method is called. For Java 1.8, which uses the Nashorn script engine, one must use the "class" property of the object to get the Java class or an error will occur. Due to this incompatibility, one should use the variant of this method that accepts a string rather than a class name if the script will be used with both versions of Java.

      Parameters:
      clazz - the class of the array components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      arg5 - the 5th component of the array
      arg6 - the 6th component of the array
      arg7 - the 7th component of the array
      arg8 - the 8th component of the array
      arg9 - the 9th component of the array
      arg10 - the 10th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
    • createAndInitArray

      public Object createAndInitArray(String className, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10) throws IllegalArgumentException, NullPointerException, ClassNotFoundException
      Create an array of length eleven given the name of the class of its components.

      For convenience, the names of primitive types can be given as "byte", "char", "double", "int", "long", or "short".

      Parameters:
      className - the fully-qualified name of the class of the array's components
      arg0 - the 0th component of the array
      arg1 - the 1st component of the array
      arg2 - the 2nd component of the array
      arg3 - the 3rd component of the array
      arg4 - the 4th component of the array
      arg5 - the 5th component of the array
      arg6 - the 6th component of the array
      arg7 - the 7th component of the array
      arg8 - the 8th component of the array
      arg9 - the 9th component of the array
      arg10 - the 10th component of the array
      Returns:
      the array
      Throws:
      IllegalArgumentException - an array component had the wrong type
      NullPointerException - the first argument was null
      ClassNotFoundException - the class corresponding to the class name could not be found
    • importClass

      Import a class given its fully-qualified name and bind it to a scripting-language variable. The name of the scripting language variable will be the last component of the fully qualified name.

      Inner classes of the class imported are accessible using the normal dot (".") notation. For example,

      
            scripting.importClass("java.awt.geom.Path2D");
            scripting.finishImport();
       
      will create an ECMAScript object stored in a variable named Path2D, and the ECMAScript expression Path2D.Double will refer to the class java.awt.geom.Path2D.Double. In addition, the ECMASCript newoperator can be used to create new instances:
      
            scripting.importClass("java.awt.geom.Path2D");
            scripting.finishImport();
            path = new Path2D.Double();
       

      As a second example,

      
            scripting.importClass("java.util.Locale.Category")
            scripting.finishImport();
       
      will create an ECMAScript variable named Category whose value is the enumeration class java.util.Locale.Category.

      Note: even for the same scripting language, the type of object created will depended on the specific implementation in use.

      Parameters:
      className - the fully-qualified name of the class
      Throws:
      ClassNotFoundException - if the class could not be found
      IllegalArgumentException - if the method detected a syntax error in the package name or class name
      NullPointerException - if the class name was null
      UnsupportedOperationException - this operation is not supported (could not add a class to the scripting environment)
      ScriptException - an error occurred executing a script
      See Also:
    • importClass

      Import a class given its package and bind it to a scripting-language variable. The name of the scripting language variable will be the last component of the class name.

      Inner classes of the class imported are accessible using the normal dot (".") notation. For example,

      
            scripting.importClass("java.awt.geom", "Path2D")
            scripting.finishImport();
       
      will create an ECMAScript object stored in a variable named Path2D, and the ECMAScript expression Path2D.Double will refer to the class java.awt.geom.Path2D.Double. In addition, the ECMASCript newoperator can be used to create new instances:
      
            scripting.importClass("java.awt.geom.Path2D");
            scripting.finishImport();
            path = new Path2D.Double();
       
      As a second example,
      
            scripting.importClass("java.util", "Locale.Category")
            scripting.finishImport();
       
      will create an ECMAScript variable named Category whose value is the enumeration class java.util.Locale.Category.
      Parameters:
      packageName - the name of the class' package.
      className - the class's name, excluding its package name
      Throws:
      ClassNotFoundException - if the class could not be found
      IllegalArgumentException - if the method detected a syntax error in the package name or class name
      NullPointerException - if the class name was null
      UnsupportedOperationException - this operation is not supported (could not add a class to the scripting environment)
      ScriptException - an error occurred executing a script
      See Also:
    • importClasses

      public void importClasses(String packageName, Object scriptObject)
      Import classes, specifying the classes to import in a script. This method is provided because the Java scripting interface does not provide a standard way of importing Java classes into a scripting environment. Java-7 used the Rhino ECMAScript implementation that defined a global variable named Packages and the EMCAScript functions importPackage and importClass. Java-8 uses the Nashhorn ECMAScript implementation, which does not contain these two functions, allows them to be defined by calling
      
             load("nashorn:mozilla_compat.js");
       
      but this function call will fail when the Rhino script engine is used as the specified ECMAScript file will not be found.

      The importClasses method and importClass methods are provided to to allow a script to import various classes regardless of the script engine in use and without having to add error-handling to the script. To use importClasses, the first argument is a package name. The second argument is scripting-language dependent. For ECMA script, the second argument is an ECMA-script array of class names, excluding the package name. For inner classes, the names are a sequence of names separated by a period (".") separating a class from the name of an inner class that class contains. The first component of the name must be the name of a class in the specified package. In all cases, the inner classes must be declared to be public and static.

      If the variable scripting is an instance of ExtendedScriptingContext (it is initialized as an instance of this class when scrunner is used), and if it uses ECMAScript, the following script fragment will import several classes from the anim2d package:

      
         scripting.inputClasses("org.bzdev.anim2d",
                                ["Animation2D",
                                 "AnimationLayer2D",
                                 "GraphView]);
         scripting.finishImport();
       
      The classes imported will be the classes Animation2D, AnimationLayer2D, and GraphView, stored using variables with the same names respectively. The ECMAScript expressions that refer to the inner classes are AnimationLayer2D.Type and GraphView.ZoomMode (both are enumerations). Similarly, the statement
      
         scripting.inputClasses("org.bzdev.anim2d",
                                ["AnimationLayer2D.Type",
                                 "GraphView.ZoomMode]);
         scripting.finishImport();
       
      will define ECMAScript variables named Type and ZoomMode and their values represent the enumeration classes org.bzdev.anim2d.AnimationLayer2D.Type and org.bzdev.anim2d.GraphView.ZoomMode respectively.

      This method does not add any functionality beyond that provided by the importClass methods: it's purpose is to shorten the amount of text that must be placed in scripts to import the desired classes.

      As an aside, the ECMA scripting engine that comes with Java 7 and Java 8 allow one to construct an object named JavaImporter, with packages provided as arguments. For example,

      
      
            classes = new JavaImporter(java.util, java.io);
            ...
            with (classes) {
               var list = new LinkedList();
               ...
            }
       

      There is a recommendation to use JavaImporter to minimize the size of the scripting engine's global name space. This recommendation makes sense for long-running applications (servers, actually) that may load large numbers of classes in response to user-generated requests. The result is that unneeded classes will not be garbage-collected. When using programs such as scrunner, this is typically not an issue: scrunner is intended to perform a single task, after which it exits. Unfortunately, there is no guarantee as to what other implementations of ECMAScript will do to import java classes and specifically whether they will provide the JavaImporter class. For maximal portability, it is possibly better to use the methods importClasses(String,Object), importClass(String,String) or importClass(String) Sequences of calls these methods should be followed by a call to finishImport(). For some scripting languages the imports will not occur until finishImport() is called.

      Parameters:
      packageName - the name of the package from which classes are to be imported
      scriptObject - an object in current scripting context's scripting language that specifies the classes to import (typically an array or a list of names for the classes in the specified package)
      See Also:
    • finishImport

      public void finishImport()
      Complete a series of imports. This method should be called after a sequence of calls to importClass(String), importClass(String,String), and/or importClasses(String,Object). It is optional for some scripting languages but mandatory for others. For the ESP scripting language, a line containing '###' should be placed after this call so that the import occurs before additional parsing.