/* Copyright 1996-2003 Simon Whiteside */ package simkin.examples.array; import simkin.XMLExecutable; import simkin.Interpreter; import simkin.ExecutableContext; import java.io.InputStream; import java.io.FileInputStream; import java.io.IOException; import org.xml.sax.SAXException; /** * This class shows how an array can be accessed by a Simkin script, where the array is stored in an XML file, or as a Java array */ public class ArrayExample extends XMLExecutable { /** this java array is public, and therefore accessible to the Simkin scripts */ public String[] nativeArray={"Native Simon","Native Lee","Native Ibrar"}; /** constructor just passes the XML input stream to its parent */ public ArrayExample(InputStream in) throws SAXException,IOException{ super(in); } /** load up the xml file named in the command line into an ArrayExample object and then run the main method */ static public void main(String args[]){ if (args.length>0){ try{ // Create an interpreter and a context Interpreter interp=new Interpreter(); ExecutableContext ctxt=new ExecutableContext(interp); // create an ArrayExample object with the loaded script ArrayExample example=new ArrayExample(new FileInputStream(args[0])); // call the "main" method example.method("main",null,ctxt); }catch(Exception e){ e.printStackTrace(); } } } }