/**
 * HTTPMessage.java
 * Created Apr 27, 2006
 * Copyright (C) Tandberg Television 2006
 */
package com.tandbergtv.workflow.message;


/**
 * Represents a message encapsulating an HTTP request
 * 
 * @author Sahil Verma
 */
public class HTTPMessage extends AbstractMessage implements IProtocolDependentMessage {

	private static final String PROTOCOL_NAME = "HTTP";

	private HTTPMethod method;

	/**
	 * Default Constructor. Creates a HTTPMessage with empty HTTPPayload. 
	 */
	public HTTPMessage() {
		this(new HTTPPayload(), null);
	}
	
	/**
	 * Creates an HTTPMessage
	 * 
	 * @param payload
	 */
	public HTTPMessage(HTTPPayload payload) {
		this(payload, null);
	}

	/**
	 * Creates a HTTPMessage
	 * 
	 * @param payload
	 * @param attachment
	 */
	public HTTPMessage(HTTPPayload payload, HTTPAttachment attachment) {
		super(payload, attachment);
		
		if (this.getPayload() == null)
			this.setPayload(new HTTPPayload());
	}

	/**
	 * Creates an HTTPMessage
	 * 
	 * @param attachment
	 * @param payload
	 * @param method
	 */
	public HTTPMessage(HTTPPayload payload, HTTPAttachment attachment, HTTPMethod method) {
		super(payload, attachment);
		this.method = method;
	}

	/**
	 * Sets the attachment associated with this message. Allows only one attachment.
	 * 
	 * @param attachment
	 *            The Attachment to send with the message.
	 */
	public void addAttachment(HTTPAttachment attachment) {
		super.setAttachment(attachment);
	}

	/**
	 * @see com.tandbergtv.workflow.message.IProtocolDependentMessage#getProtocolName()
	 */
	public String getProtocolName() {
		return PROTOCOL_NAME;
	}

	/**
	 * Accessor to the HTTP method type
	 * @return Returns the method.
	 */
	public HTTPMethod getMethod() {
		return this.method;
	}

	/**
	 * Sets the HTTP method type
	 * @param method The method to set.
	 */
	public void setMethod(HTTPMethod method) {
		this.method = method;
	}
}
