2 * Copyright (c) 2003 University of Murcia. All rights reserved.
\r
3 * --------------------------------------------------------------
\r
4 * For more information, please see <http://www.umu.euro6ix.org/>.
\r
7 package org.umu.cops.stack;
\r
10 * COPS Message Parser
\r
12 * @version COPSMsgParser.java, v 1.00 2003
\r
16 // import org.umu.cops.common.COPSDebug;
\r
18 public class COPSMsgParser {
\r
20 public COPSMsgParser() {
\r
24 /** Parses the given COPS data and returns a COPSMsg object
\r
25 * with COPS object filed in.The COPSMsg object is allocated in the
\r
26 * call and it is the responsibility of the caller to free the memory
\r
28 * @param data a byte[]
\r
32 * @throws COPSException
\r
35 public COPSMsg parse(byte[] data) throws COPSException {
\r
36 COPSHeader hdr = new COPSHeader(data);
\r
38 byte[] buf = new byte[data.length - 8];
\r
39 System.arraycopy(data,8,buf,0,data.length - 8);
\r
41 return (parse(hdr, buf));
\r
45 * Parse the message with given header , the data is pointing
\r
46 * to the data following the header
\r
48 * @param hdr a COPSHeader
\r
49 * @param data a byte[]
\r
53 * @throws COPSException
\r
56 public COPSMsg parse(COPSHeader hdr, byte[] data) throws COPSException {
\r
57 COPSMsg copsMsg = null;
\r
58 short cCode = hdr.getOpCode();
\r
60 case COPSHeader.COPS_OP_REQ: {
\r
61 // COPSDebug.out(getClass().getName(), "Creating REQ msg");
\r
62 copsMsg = new COPSReqMsg();
\r
63 copsMsg.parse(hdr, data);
\r
66 case COPSHeader.COPS_OP_DEC: {
\r
67 // COPSDebug.out(getClass().getName(), "Creating DEC msg");
\r
68 copsMsg = new COPSDecisionMsg();
\r
69 copsMsg.parse(hdr, data);
\r
72 case COPSHeader.COPS_OP_RPT: {
\r
73 // COPSDebug.out(getClass().getName(), "Creating RPT msg");
\r
74 copsMsg = new COPSReportMsg();
\r
75 copsMsg.parse(hdr, data);
\r
78 case COPSHeader.COPS_OP_DRQ: {
\r
79 // COPSDebug.out(getClass().getName(), "Creating DRQ msg");
\r
80 copsMsg = new COPSDeleteMsg();
\r
81 copsMsg.parse(hdr, data);
\r
84 case COPSHeader.COPS_OP_OPN: {
\r
85 // COPSDebug.out(getClass().getName(), "Creating Client-Open msg");
\r
86 copsMsg = new COPSClientOpenMsg();
\r
87 copsMsg.parse(hdr, data);
\r
90 case COPSHeader.COPS_OP_CAT: {
\r
91 // COPSDebug.out(getClass().getName(), "Creating Client-Accept msg");
\r
92 copsMsg = new COPSClientAcceptMsg();
\r
93 copsMsg.parse(hdr, data);
\r
96 case COPSHeader.COPS_OP_CC: {
\r
97 // COPSDebug.out(getClass().getName(), "Creating Client-Close msg");
\r
98 copsMsg = new COPSClientCloseMsg();
\r
99 copsMsg.parse(hdr, data);
\r
102 case COPSHeader.COPS_OP_KA: {
\r
103 // COPSDebug.out(getClass().getName(), "Creating KA msg");
\r
104 copsMsg = new COPSKAMsg();
\r
105 copsMsg.parse(hdr, data);
\r
108 case COPSHeader.COPS_OP_SSQ: {
\r
109 // COPSDebug.out(getClass().getName(), "Creating Sync-State Request msg");
\r
110 copsMsg = new COPSSyncStateMsg();
\r
111 copsMsg.parse(hdr, data);
\r
114 case COPSHeader.COPS_OP_SSC: {
\r
115 // COPSDebug.out(getClass().getName(), "Creating Sync-State Complete msg");
\r
116 copsMsg = new COPSSyncStateMsg();
\r
117 copsMsg.parse(hdr, data);
\r
121 // COPSDebug.out(getClass().getName(), "Unknown message type");
\r
126 // if(copsMsg != null)
\r
127 // try { copsMsg.dump(COPSDebug.out); } catch (Exception e) {};
\r