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 Khen G. Kim
021: * @version $Revision: 1.2 $
022: */
023:
024: /**
025: * Created on 10.01.2004
026: */package org.apache.harmony.jpda.tests.framework.jdwp;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.Packet;
029:
030: /**
031: * This class represents JDWP command packet.
032: */
033: public class CommandPacket extends Packet {
034: private final int COMMAND_SET_INDEX = 9;
035: private final int COMMAND_INDEX = 10;
036:
037: private byte command_set;
038: private byte command;
039:
040: /**
041: * Creates an empty CommandPacket with empty header and no data.
042: */
043: public CommandPacket() {
044: super ();
045: }
046:
047: /**
048: * Creates an empty CommandPacket for specific JDWP command with no data.
049: */
050: public CommandPacket(byte commandSet, byte command) {
051: super ();
052: this .command_set = commandSet;
053: this .command = command;
054: }
055:
056: /**
057: * Creates CommandPacket from given array of bytes including header and data sections.
058: *
059: * @param bytes_array the JDWP packet, given as array of bytes.
060: */
061: public CommandPacket(byte bytes_array[]) {
062: super (bytes_array);
063: command_set = bytes_array[COMMAND_SET_INDEX];
064: command = bytes_array[COMMAND_INDEX];
065: }
066:
067: /**
068: * Sets command set value of the header of the CommandPacket as byte.
069: *
070: * @param val the command set.
071: */
072: public void setCommandSet(byte val) {
073: command_set = val;
074: }
075:
076: /**
077: * Gets command set value of the header of the CommandPacket as byte.
078: *
079: * @return the command set value of the header of the CommandPacket as byte.
080: */
081: public byte getCommandSet() {
082: return command_set;
083: }
084:
085: /**
086: * Sets command value of the header of the CommandPacket as byte.
087: *
088: * @param val the command.
089: */
090: public void setCommand(byte val) {
091: command = val;
092: }
093:
094: /**
095: * Sets command value of the header of the CommandPacket as byte.
096: *
097: * @param commandSet number of the command set.
098: * @param command number of the command.
099: */
100: public void setCommand(byte commandSet, byte command) {
101: this .command_set = commandSet;
102: this .command = command;
103: }
104:
105: /**
106: * Gets command value of the header of the CommandPacket as byte.
107: *
108: * @return the command value of the header of the CommandPacket as byte.
109: */
110: public byte getCommand() {
111: return command;
112: }
113:
114: /**
115: * Gets the representation of the CommandPacket as array of bytes in the
116: * JDWP format including header and data sections.
117: *
118: * @return the representation of the CommandPacket as array of bytes in the
119: * JDWP format.
120: */
121: public byte[] toBytesArray() {
122: byte res[] = super.toBytesArray();
123: res[COMMAND_SET_INDEX] = command_set;
124: res[COMMAND_INDEX] = command;
125: return res;
126: }
127:
128: }
|