FileDocCategorySizeDatePackage
MessageLog.javaAPI DocphoneME MR2 API (J2ME)8503Wed May 02 18:00:42 BST 2007gov.nist.siplite.stack

MessageLog

public class MessageLog extends Object
This class stores a message along with some other informations Used to log messages.
version
JAIN-SIP-1.1 This code is in the public domain.

Fields Summary
private String
message
Message to be logged.
private String
source
Originator of this mesage.
private String
destination
Target recipient for the message.
private long
timeStamp
Time of the logging event.
private boolean
isSender
Flag indicating if we are the message sender.
private String
firstLine
First line from the message.
private String
statusMessage
Status line from the transaction.
private String
tid
Transaction identifier.
private String
callId
Caller identification.
Constructors Summary
public MessageLog(String message, String source, String destination, String timeStamp, boolean isSender, String firstLine, String statusMessage, String tid, String callId)
Constructor with initial parameters.

param
message the message to be logged
param
source the originator of the message
param
destination the target recipient
param
timeStamp the logging event timestamp
param
isSender true is we are the sender
param
firstLine the first line from the message
param
statusMessage the status line from the transaction
param
tid the transaction identifier
param
callId the caller identification
exception
IllegalArgumentException if the message is null, or the timeStamp is not valid

        if (message == null
                || message.equals(""))
            throw new IllegalArgumentException("null msg");
        this.message = message;
        this.source = source;
        this.destination = destination;
        try {
            long ts = Long.parseLong(timeStamp);
            if (ts < 0)
                throw new IllegalArgumentException("Bad time stamp ");
            this.timeStamp = ts;
        } catch (NumberFormatException ex) {
            throw new IllegalArgumentException("Bad number format "
                    + timeStamp);
        }
        this.isSender = isSender;
        this.firstLine = firstLine;
        this.statusMessage = statusMessage;
        this.tid = tid;
        this.callId = callId;
    
public MessageLog(String message, String source, String destination, long timeStamp, boolean isSender, String firstLine, String statusMessage, String tid, String callId)
Constructor with initial parameters.

param
message the message to be logged
param
source the originator of the message
param
destination the target recipient
param
timeStamp the logging event timestamp
param
isSender true is we are the sender
param
firstLine the first line from the message
param
statusMessage the status line from the transaction
param
tid the transaction identifier
param
callId the caller identification
exception
IllegalArgumentException if the message is null, or the timeStamp is not valid

        if (message == null
                || message.equals(""))
            throw new IllegalArgumentException("null msg");
        this.message = message;
        this.source = source;
        this.destination = destination;
        if (timeStamp < 0)
            throw new IllegalArgumentException("negative ts");
        this.timeStamp = timeStamp;
        this.isSender = isSender;
        this.firstLine = firstLine;
        this.statusMessage = statusMessage;
        this.tid = tid;
        this.callId = callId;
    
Methods Summary
public booleanequals(java.lang.Object other)
Compares object for equivalence.

param
other object to be compared
return
true if the object matches

        if (! (other instanceof MessageLog)) {
            return false;
        } else {
            MessageLog otherLog = (MessageLog) other;
            return otherLog.message.equals(message) &&
                    otherLog.timeStamp == timeStamp;
        }
    
public java.lang.Stringflush(long startTime)
Constructs an XML formatted log message.

param
startTime time of message output
return
the encode log message

        String log;
        
        if (statusMessage != null) {
            log = " <message\nfrom = \"" + source +
                    "\" \nto = \"" + destination +
                    "\" \ntime = \"" + (timeStamp - startTime) +
                    "\" \nisSender = \"" + isSender +
                    "\" \nstatusMessage = \"" + statusMessage +
                    "\" \ntransactionId = \"" + tid +
                    "\" \ncallId = \"" + callId +
                    "\" \nfirstLine = \"" + firstLine.trim() +
                    "\" > \n";
            log += "<![CDATA[";
            log += message;
            log += "]]>\n";
            log += "</message>\n";
        } else {
            log = " <message\nfrom = \"" + source +
                    "\" \nto = \"" + destination +
                    "\" \ntime = \"" + (timeStamp - startTime) +
                    "\" \nisSender = \"" + isSender +
                    "\" \ntransactionId = \"" + tid +
                    "\" \ncallId = \"" + callId +
                    "\" \nfirstLine = \"" + firstLine.trim() +
                    "\" > \n";
            log += "<![CDATA[";
            log += message;
            log += "]]>\n";
            log += "</message>\n";
        }
        return log;
    
public java.lang.Stringflush()
Constructs an XML formatted log message.

return
the encode log message

        String log;
        
        if (statusMessage != null) {
            log = " < message\nfrom = \"" + source +
                    "\" \nto = \"" + destination +
                    "\" \ntime = \"" + timeStamp  +
                    "\" \nisSender = \"" + isSender  +
                    "\" \nstatusMessage = \"" + statusMessage +
                    "\" \ntransactionId = \"" + tid +
                    "\" \nfirstLine = \"" + firstLine.trim() +
                    "\" \ncallId = \"" + callId +
                    "\" \n > \n";
            log += "<![CDATA[";
            log += message;
            log += "]]>\n";
            log += "</message>\n";
        } else {
            log = " < message\nfrom = \"" + source +
                    "\" \nto = \"" + destination +
                    "\" \ntime = \"" + timeStamp  +
                    "\" \nisSender = \"" + isSender  +
                    "\" \ntransactionId = \"" + tid +
                    "\" \ncallId = \"" + callId +
                    "\" \nfirstLine = \"" + firstLine.trim() +
                    "\" \n > \n";
            log += "<![CDATA[";
            log += message;
            log += "]]>\n";
            log += "</message>\n";
        }
        return log;
    
protected longgetTimeStamp()
Gets the logged timestamp.

return
the timestamp

        return this.timeStamp;