001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Alexei S. Vaskin
021: * @version $Revision: 1.6 $
022: */
023:
024: /**
025: * Created on 22.04.2005
026: */package org.apache.harmony.jpda.tests.framework.jdwp;
027:
028: import java.util.ArrayList;
029: import java.util.Iterator;
030:
031: /**
032: * This class provides description of frame.
033: *
034: */
035: public class Frame {
036:
037: protected long threadID;
038:
039: protected Location loc;
040:
041: protected long id;
042:
043: protected ArrayList vars;
044:
045: /**
046: * Default constructor.
047: */
048: public Frame() {
049: threadID = -1;
050: id = -1L;
051: loc = new Location();
052: vars = null;
053: }
054:
055: /**
056: * Constructor initializing all members of the Frame instance.
057: *
058: * @param threadID
059: * thread id
060: * @param id
061: * frame id
062: * @param location
063: * frame location
064: * @param vars
065: * list of variables
066: */
067: Frame(long threadID, long id, Location location, ArrayList vars) {
068: this .threadID = threadID;
069: this .id = id;
070: this .loc = location;
071: this .vars = vars;
072: }
073:
074: /**
075: * Gets thread id.
076: *
077: * @return long
078: */
079: public long getThreadID() {
080: return threadID;
081: }
082:
083: /**
084: * Sets new thread id.
085: *
086: * @param threadID
087: * new thread id
088: */
089: public void setThreadID(long threadID) {
090: this .threadID = threadID;
091: }
092:
093: /**
094: * Gets frame id.
095: *
096: * @return long
097: */
098: public long getID() {
099: return id;
100: }
101:
102: /**
103: * Sets new frame id.
104: *
105: * @param id
106: * new frame id
107: */
108: public void setID(long id) {
109: this .id = id;
110: }
111:
112: /**
113: * Gets frame location.
114: *
115: * @return Location
116: */
117: public Location getLocation() {
118: return loc;
119: }
120:
121: /**
122: * Sets new frame location.
123: *
124: * @param location
125: * new frame location
126: */
127: public void setLocation(Location location) {
128: this .loc = location;
129: }
130:
131: /**
132: * Gets frame variables.
133: *
134: * @return list of frame variables
135: */
136: public ArrayList getVars() {
137: return vars;
138: }
139:
140: /**
141: * Sets new frame variables.
142: *
143: * @param vars
144: * list of new frame variables
145: */
146: public void setVars(ArrayList vars) {
147: this .vars = vars;
148: }
149:
150: /**
151: * Converts Frame object to String.
152: *
153: * @see java.lang.Object#toString()
154: * @return String
155: */
156: public String toString() {
157: String string = "Frame: id=" + id + ", threadID=" + threadID
158: + ", location=" + loc.toString() + "\n";
159: string += "--- Variables ---";
160: Iterator it = vars.iterator();
161: while (it.hasNext()) {
162: string += ((Variable) it.next()).toString();
163: }
164: return string;
165: }
166:
167: /**
168: * Compares two Frame objects.
169: *
170: * @see java.lang.Object#equals(java.lang.Object)
171: * @return boolean
172: */
173: public boolean equals(Object obj) {
174: if (!(obj instanceof Frame)) {
175: return false;
176: }
177:
178: if (this .getClass() != obj.getClass()) {
179: return false;
180: }
181:
182: Frame frame = (Frame) obj;
183: if (this .threadID != frame.threadID || this .id != frame.id
184: || !(this .loc.equals(frame.loc))) {
185: return false;
186: }
187:
188: if (vars.size() != frame.vars.size()) {
189: return false;
190: }
191:
192: if (!vars.equals(frame.vars)) {
193: return false;
194: }
195:
196: return true;
197: }
198:
199: /**
200: * This describing frame variable.
201: *
202: */
203: public final class Variable {
204: private long codeIndex;
205:
206: private String name;
207:
208: private String signature;
209:
210: private int length;
211:
212: private int slot;
213:
214: private byte tag;
215:
216: private String type;
217:
218: /**
219: * Constructor.
220: *
221: */
222: public Variable() {
223: codeIndex = -1;
224: name = "unknown";
225: signature = "unknown";
226: length = -1;
227: slot = -1;
228: tag = JDWPConstants.Tag.NO_TAG;
229: type = "unknown type";
230: }
231:
232: /**
233: * Gets code index of variable.
234: *
235: * @return long
236: */
237: public long getCodeIndex() {
238: return codeIndex;
239: }
240:
241: /**
242: * Sets new code index for variable.
243: *
244: * @param codeIndex
245: */
246: public void setCodeIndex(long codeIndex) {
247: this .codeIndex = codeIndex;
248: }
249:
250: /**
251: * Gets variable name.
252: *
253: * @return String
254: */
255: public String getName() {
256: return name;
257: }
258:
259: /**
260: * Sets new variable name.
261: *
262: * @param name
263: * new variable name
264: */
265: public void setName(String name) {
266: this .name = name;
267: }
268:
269: /**
270: * Gets signature of the variable reference type.
271: *
272: * @return String
273: */
274: public String getSignature() {
275: return signature;
276: }
277:
278: /**
279: * Sets new signature and detects value of a type tag.
280: *
281: * @param signature
282: */
283: public void setSignature(String signature) {
284: switch (signature.charAt(0)) {
285: case '[':
286: tag = JDWPConstants.Tag.ARRAY_TAG;
287: break;
288: case 'B':
289: tag = JDWPConstants.Tag.BYTE_TAG;
290: break;
291: case 'C':
292: tag = JDWPConstants.Tag.CHAR_TAG;
293: break;
294: case 'L':
295: tag = JDWPConstants.Tag.OBJECT_TAG;
296: break;
297: case 'F':
298: tag = JDWPConstants.Tag.FLOAT_TAG;
299: break;
300: case 'D':
301: tag = JDWPConstants.Tag.DOUBLE_TAG;
302: break;
303: case 'I':
304: tag = JDWPConstants.Tag.INT_TAG;
305: break;
306: case 'J':
307: tag = JDWPConstants.Tag.LONG_TAG;
308: break;
309: case 'S':
310: tag = JDWPConstants.Tag.SHORT_TAG;
311: break;
312: case 'V':
313: tag = JDWPConstants.Tag.VOID_TAG;
314: break;
315: case 'Z':
316: tag = JDWPConstants.Tag.BOOLEAN_TAG;
317: break;
318: case 's':
319: tag = JDWPConstants.Tag.STRING_TAG;
320: break;
321: case 't':
322: tag = JDWPConstants.Tag.THREAD_TAG;
323: break;
324: case 'g':
325: tag = JDWPConstants.Tag.THREAD_GROUP_TAG;
326: break;
327: case 'l':
328: tag = JDWPConstants.Tag.CLASS_LOADER_TAG;
329: break;
330: case 'c':
331: tag = JDWPConstants.Tag.CLASS_OBJECT_TAG;
332: break;
333: }
334:
335: this .signature = signature;
336: }
337:
338: /**
339: * Gets variable length.
340: *
341: * @return int
342: */
343: public int getLength() {
344: return length;
345: }
346:
347: /**
348: * Sets new variable length.
349: *
350: * @param length
351: * new variable length
352: */
353: public void setLength(int length) {
354: this .length = length;
355: }
356:
357: /**
358: * Returns variable slot value.
359: *
360: * @return int
361: */
362: public int getSlot() {
363: return slot;
364: }
365:
366: /**
367: * Assigns new slot value.
368: *
369: * @param slot
370: * new slot value
371: */
372: public void setSlot(int slot) {
373: this .slot = slot;
374: }
375:
376: /**
377: * Gets variable type tag value.
378: *
379: * @return byte
380: */
381: public byte getTag() {
382: return tag;
383: }
384:
385: /**
386: * Gets variable java type.
387: *
388: * @return String
389: */
390: public String getType() {
391: switch (tag) {
392: case JDWPConstants.Tag.ARRAY_TAG:
393: switch (signature.charAt(1)) {
394: case 'B':
395: type = "byte[]";
396: break;
397: case 'C':
398: type = "char[]";
399: break;
400: case 'J':
401: type = "long[]";
402: break;
403: case 'F':
404: type = "float[]";
405: break;
406: case 'D':
407: type = "double[]";
408: break;
409: case 'I':
410: type = "int[]";
411: break;
412: case 'S':
413: type = "short[]";
414: break;
415: case 'V':
416: type = "void[]";
417: break;
418: case 'Z':
419: type = "boolean[]";
420: break;
421: case 's':
422: type = "java.Lang.String[]";
423: break;
424: case 'L':
425: type = signature.substring(2,
426: signature.length() - 1 /*
427: * skip
428: * ending
429: * ';'
430: */).replaceAll("/", ".")
431: + "[]"; // skip ending ';'
432: break;
433: }
434: break;
435: case JDWPConstants.Tag.OBJECT_TAG:
436: type = signature.substring(1, signature.length() - 1 /*
437: * skip ending
438: * ';'
439: */).replaceAll("/", "."); // skip ending ';'
440: break;
441: case JDWPConstants.Tag.BOOLEAN_TAG:
442: type = "boolean";
443: break;
444: case JDWPConstants.Tag.BYTE_TAG:
445: type = "byte";
446: break;
447: case JDWPConstants.Tag.CHAR_TAG:
448: type = "char";
449: break;
450: case JDWPConstants.Tag.DOUBLE_TAG:
451: type = "double";
452: break;
453: case JDWPConstants.Tag.FLOAT_TAG:
454: type = "float";
455: break;
456: case JDWPConstants.Tag.INT_TAG:
457: type = "int";
458: break;
459: case JDWPConstants.Tag.LONG_TAG:
460: type = "long";
461: break;
462: case JDWPConstants.Tag.SHORT_TAG:
463: type = "short";
464: break;
465: case JDWPConstants.Tag.STRING_TAG:
466: type = "string";
467: break;
468: default:
469: break;
470: }
471:
472: return type;
473: }
474:
475: /**
476: * Converts Variable object to String.
477: *
478: * @see java.lang.Object#toString()
479: * @return String
480: */
481: public String toString() {
482: return "Variable: codeIndex=" + codeIndex + ", name="
483: + name + ", signature=" + signature + ", length="
484: + length + ", slot=" + slot + ", tag="
485: + JDWPConstants.Tag.getName(tag) + ", type=" + type;
486: }
487:
488: /**
489: * Compares two Variable objects.
490: *
491: * @see java.lang.Object#equals(java.lang.Object)
492: * @return boolean
493: */
494: public boolean equals(Object obj) {
495: if (!(obj instanceof Variable)) {
496: return false;
497: }
498:
499: if (this .getClass() != obj.getClass()) {
500: return false;
501: }
502:
503: Variable var = (Variable) obj;
504: return this.codeIndex == var.codeIndex
505: && this.name.equals(var.name)
506: && this.signature.equals(var.signature)
507: && this.length == var.length
508: && this.slot == var.slot && this.tag == var.tag
509: && this.type.equals(var.type);
510:
511: }
512: }
513: }
|