2 * Copyright (c) 2003 University of Murcia. All rights reserved.
3 * --------------------------------------------------------------
4 * For more information, please see <http://www.umu.euro6ix.org/>.
7 package org.umu.cops.stack;
9 import java.io.IOException;
10 import java.io.OutputStream;
11 import java.net.Socket;
14 * Represents messages coming from and going to a COPS device such as a CMTS
16 abstract public class COPSMsg {
19 * The COPS header that is associated with all COPS messages
21 private final COPSHeader _hdr;
25 * @param hdr - the header
27 public COPSMsg(final COPSHeader hdr) {
28 if (hdr == null) throw new IllegalArgumentException("Header must not be null");
32 * Returns the message header object
33 * @return a COPSHeader
35 public COPSHeader getHeader() {
40 * Method writeData. Implementers should be calling super.writeData() for the header prior to writing out the rest.
41 * @param socket a Socket
44 public final void writeData(final Socket socket) throws IOException {
46 _hdr.writeData(socket, _hdr.getHdrLength() + getDataLength());
51 * Returns the number of bytes to be contained within the payload excluding the header
52 * @return - a positive value including the header size
54 protected abstract int getDataLength();
57 * Writes out the body data over a socket
58 * @param socket - the socket to which to write
60 protected abstract void writeBody(Socket socket) throws IOException;
63 * Write an object textual description in the output stream
64 * @param os an OutputStream
67 final public void dump(final OutputStream os) throws IOException {
73 * Creates a string representation of this object and sends it to an output stream
74 * @param os - the output stream
77 protected abstract void dumpBody(final OutputStream os) throws IOException;
80 public boolean equals(final Object o) {
84 if (!(o instanceof COPSMsg)) {
88 final COPSMsg copsMsg = (COPSMsg) o;
90 return _hdr.equals(copsMsg._hdr);
95 public int hashCode() {
96 return _hdr.hashCode();