2 * (c) 2015 Cable Television Laboratories, Inc. All rights reserved.
5 package org.pcmm.gates.impl;
7 import org.pcmm.base.impl.PCMMBaseObject;
8 import org.pcmm.gates.ITransactionID;
9 import org.umu.cops.stack.COPSMsgParser;
12 * Implementation of the ITransactionID interface
14 public class TransactionID extends PCMMBaseObject implements ITransactionID {
17 * The transaction identifier
19 private final short transId;
22 * The gate command type
24 private final GateCommandType gateCommandType;
28 * @param transId - the transaction identifier
29 * @param gateCommandType - the gate command type
31 public TransactionID(final short transId, final GateCommandType gateCommandType) {
32 super(SNum.TRANSACTION_ID, STYPE);
33 if (gateCommandType == null)
34 throw new IllegalArgumentException("Invalid gate command type");
35 this.transId = transId;
36 this.gateCommandType = gateCommandType;
40 public short getTransactionIdentifier() {
45 public GateCommandType getGateCommandType() {
46 return gateCommandType;
50 protected byte[] getBytes() {
51 final byte[] transIdBytes = COPSMsgParser.shortToBytes(transId);
52 final byte[] data = new byte[transIdBytes.length + transIdBytes.length];
53 System.arraycopy(transIdBytes, 0, data, 0, transIdBytes.length);
55 final byte[] gateCmdBytes = COPSMsgParser.shortToBytes(gateCommandType.getValue());
56 System.arraycopy(gateCmdBytes, 0, data, transIdBytes.length, gateCmdBytes.length);
61 * Returns a TransactionID object from a byte array
62 * @param data - the data to parse
63 * @return - the object
64 * TODO - make me more robust as RuntimeExceptions can be thrown here.
66 public static TransactionID parse(final byte[] data) {
67 return new TransactionID(COPSMsgParser.bytesToShort(data[0], data[1]),
68 GateCommandType.valueOf(COPSMsgParser.bytesToShort(data[2], data[3])));