1 package jde.debugger.command;
3 import java.util.Iterator;
6 import com.sun.jdi.ArrayReference;
7 import com.sun.jdi.ObjectReference;
8 import com.sun.jdi.Value;
9 import jde.debugger.Etc;
10 import jde.debugger.JDEException;
11 import jde.debugger.JDE;
12 import jde.debugger.Rep;
15 * 'get_array' command. Information about a given array, and,
16 * optionally, values of a range of indices
21 * get_array objectID [index, length]
26 * (jde-dbo-command-result cmd_id {@link Rep#getArrayRep(ArrayReference, String) array})
29 * Copyright (c) 2000, 2001, 2003 Paul Kinnucan
31 * @author Paul Kinnucan
32 * @version $Revision: 1.3 $
34 public class GetArray extends DebugProcessCommand {
35 private static final int MAX_DISPLAY_ELEMENTS = 30;
39 * @exception jde.debugger.JDEException <description>
41 public void doCommand() throws JDEException {
43 if (m_args.size() < 1)
44 throw new JDEException("Insufficient arguments");
46 Long uniqueID = Etc.safeGetLong(m_args.remove(0), "object ID");
47 ObjectReference oRef = m_debugger.getStore().get(uniqueID);
50 throw new JDEException("No such object exists");
51 } else if (!(oRef instanceof ArrayReference)) {
52 throw new JDEException("Object is not an array");
55 // Keep track of this array for later reference.
56 m_debugger.getStore().put(oRef);
58 if (m_args.size() == 0) {
59 m_debugger.signalCommandResult(m_cmdID,
60 Rep.getArrayRep((ArrayReference)oRef, ""),
62 } else if (m_args.size() == 2) {
63 StringBuffer elements = new StringBuffer();
65 int index = Etc.safeGetint(m_args.remove(0), "index");
66 int length = Etc.safeGetint(m_args.remove(0), "length");
68 List elementList = ((ArrayReference) oRef).getValues(index, length);
69 Iterator it = elementList.iterator();
72 while (it.hasNext() && numElements < MAX_DISPLAY_ELEMENTS) {
74 Value value = (Value) it.next();
76 // store the fields in this object that themselves are objects in the
77 // ObjectStore, since the user may query for more information about those.
78 if (value instanceof ObjectReference) {
79 m_debugger.getStore().put((ObjectReference) value);
83 elements.append(Rep.getValueRep(value));
87 JDE.debug(EVENTS, "did not list all elements");
88 // XXX - should be a way to indicate to the debugger that there are more elts.
91 m_debugger.signalCommandResult(m_cmdID,
92 Rep.getArrayRep((ArrayReference)oRef, elements.toString()),
95 throw new JDEException("Syntax error: Wrong number of arguments");
100 public Object clone() {return new GetArray();}
105 * $Log: GetArray.java,v $
106 * Revision 1.3 2003/01/15 05:56:26 paulk
107 * Add Petter Mahlen's changes.
109 * Revision 1.2 2001/03/24 05:42:36 paulk
110 * Updated to reflect reorganization of debugger code.
112 * Revision 1.1 2000/03/03 07:08:39 paulk
117 // End of GetArray.java