/**
 * AbstractMessage.java
 * Created Apr 26, 2006
 * Copyright (C) Tandberg Television 2006
 */
package com.tandbergtv.workflow.message;


/**
 * Base implementation of the IMessage interface for providing common functionality for
 * various message derived classes.
 * 
 * @author Sahil Verma
 */
public abstract class AbstractMessage implements IMessage {

	private IPayload payload;
	
	private IMessageAttachment attachment;

	/**
	 * Creates an AbstractMessage
	 */
	protected AbstractMessage() {
		super();
	}

	/**
	 * Creates an AbstractMessage with the specified parameters
	 * @param payload The message body
	 */
	protected AbstractMessage(IPayload payload) {
		this(payload, null);
	}

	/**
	 * Creates an AbstractMessage with the specified parameters
	 * @param payload The message body
	 * @param attachment An attachment
	 */
	protected AbstractMessage(IPayload payload, IMessageAttachment attachment) {
		this.payload = payload;
		this.attachment = attachment;
	}

	/**
	 * @see com.tandbergtv.workflow.message.IMessage#getAttachment()
	 */
	public IMessageAttachment getAttachment() {
		return this.attachment;
	}

	/**
	 * @param attachment the attachment to set
	 */
	protected void setAttachment(IMessageAttachment attachment) {
		this.attachment = attachment;
	}
	
	/**
	 * @see com.tandbergtv.workflow.message.IMessage#getPayload()
	 */
	public IPayload getPayload() {
		return this.payload;
	}

	/**
	 * @param payload the payload to set
	 */
	protected void setPayload(IPayload payload)	{
		this.payload = payload;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder buf = new StringBuilder();
		
		buf.append("Message payload=").append(this.payload);
		if (this.attachment != null)
			buf.append(", attachment=").append(this.attachment);

		return buf.toString();
	}
}
