/* * ArrayObject.java -- * * This class implements the Array Object Command, which is a special case * of the Object Command. * * See the file "license.terms" for information on usage and * redistribution of this file, and for a DISCLAIMER OF ALL * WARRANTIES. * * RCS: @(#) $Id: ArrayObject.java,v 1.1.1.1 1998/10/14 21:09:13 cvsadmin Exp $ * */ package tcl.lang; import java.lang.reflect.*; import java.util.*; import java.beans.*; /* * An ArrayObject is used to create and access Java Array objects * using the Java Reflection API. It wraps around a Java Array object (i.e., * an instance of any Java Array class) and expose it to Tcl scripts. */ class ArrayObject extends tcl.lang.ReflectObject { static final private String validCmds[] = { "length", "get", "getrange", "set", "setrange" }; static final private int OPT_LENGTH = 0; static final private int OPT_GET = 1; static final private int OPT_GETRANGE = 2; static final private int OPT_SET = 3; static final private int OPT_SETRANGE = 4; /* *----------------------------------------------------------------------------- * * cmdProc -- * * This cmdProc implements the Tcl command used to invoke methods * of the java.lang.Object stored in this ArrayObject internal * rep. For example, this method is called to process the "$v" * command at the second line of this script: * * set v [java::new java.util.Vector] * $v addElement "foo" * * Results: * None. * * Side effects: * May set the value of array elements or default to the super class * implementation of cmdProc. * *----------------------------------------------------------------------------- */ public void cmdProc( Interp interp, // Current interpreter. TclObject argv[]) // Argument list. throws TclException // If wrong number of args, a // standard Tcl exception; // If an exception is encountered // during the invokation of the method, // the Exception object will be stored // in the errorCode of the interp. { boolean convert; int optionIdx, numArgs; Object subArrayObj; Class subArrayClass; int option, index, numDims, count; TclObject indexListObj; if (argv.length < 2) { throw new TclNumArgsException(interp, 1, argv, "?-noconvert? option ?arg arg ...?"); } String arg1 = argv[1].toString(); if ((arg1.length() >= 2) && (NOCONVERT.startsWith(arg1))) { /* * numArgs is the number of optional arguments after the sub-command. */ convert = false; optionIdx = 2; numArgs = argv.length - 3; } else { convert = true; optionIdx = 1; numArgs = argv.length - 2; } if (numArgs < 0) { throw new TclNumArgsException(interp, 1, argv, "?-noconvert? option ?arg arg ...?"); } /* * If the