/*
* Software Name : ATK
*
* Copyright (C) 2007 - 2012 France Télécom
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ------------------------------------------------------------------
* File Name : Message.java
*
* Created : 02/03/2009
* Author(s) : Yvain Leyral
*/
package com.orange.atk.results.logger.log;
/**
* This class represents a message which could represents an error, a warning or
* an info generated by a script.
*/
public class Message {
/**
* Indicate an message of kind error
*/
public final static int ERROR_MSG = 0;
/**
* Indicate an message of kind warning
*/
public final static int WARN_MSG = 1;
/**
* Indicate an message of kind info
*/
public final static int INFO_MSG = 2;
/**
* Create a new message of type Error
*
* @param msg
* description of the message
* @param timestamp
* time when the message occurred
* @param line
* line in the script which generates this message
* @param scriptName
* name of the script
* @return a new message of type Error (getType == LogMessage.Error)
*/
public static Message createErrorMessage(String msg, long timestamp,
int line, String scriptName) {
return new Message(ERROR_MSG, msg, timestamp, line, scriptName);
}
/**
* Create a new message of type Info
*
* @param msg
* description of the message
* @param timestamp
* time when the message occurred
* @param line
* line in the script which generates this message
* @param scriptName
* name of the script
* @return a new message of type Info (getType == LogMessage.Info)
*/
public static Message createInfoMessage(String msg, long timestamp,
int line, String scriptName) {
return new Message(INFO_MSG, msg, timestamp, line, scriptName);
}
/**
* Create a new message of type Warning
*
* @param msg
* description of the message
* @param timestamp
* time when the message occurred
* @param line
* line in the script which generates this message
* @param scriptName
* name of the script
* @return a new message of type Warning (getType == LogMessage.Warning)
*/
public static Message createWarningMessage(String msg, long timestamp,
int line, String scriptName) {
return new Message(WARN_MSG, msg, timestamp, line, scriptName);
}
// type of message =(ERROR_MSG|WARN_MSG|INFO_MSG)
private int type;
// message
private String msg;
// time when message has been saved
private long timestamp;
// line
private int line;
private String scriptName;
private Message(int type, String value, long timestamp, int line,
String scriptName) {
setType(type);
setMessage(value);
setTimestamp(timestamp);
setLine(line);
setScriptName(scriptName);
}
/**
* Return the line of the file which generates this message
*
* @return the line number, could be equal to -1
*/
public int getLine() {
return line;
}
/**
* Return the name of the script where this message has been generated
*
* @return the name of the script, should not be null.
*/
public String getScriptName() {
return scriptName;
}
/**
* get the instant when this message has been generated. The value is the
* time elapsed between epoch and the generation of the message in
* millisecond.
*
* @return instant of message generation
*/
public long getTimestamp() {
return timestamp;
}
/**
* Return the type of the message. Possibles values are ERROR_MSG (for a
* message of type error), WARN_MSG (for a message of type warning) and
* INFO_MSG (for a message of type info)
*
* @return the type of message
*/
public int getType() {
return type;
}
/**
* Return the content of the message. It should explain why this message
* has been generated.
* @return the content of the message
*/
public String getMessage() {
return msg;
}
private void setLine(int line) {
this.line = line;
}
private final void setScriptName(String scriptName) {
this.scriptName = scriptName;
}
private void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
private void setType(int type) {
this.type = type;
}
private void setMessage(String msg) {
this.msg = msg;
}
}