/*
 *  Copyright (C) 2006  Takashi Kasuya <kasuya@sfc.keio.ac.jp>
 *
 * This library is free software; you can redistribute it and/or
 *　modify it under the terms of the GNU Lesser General Public
 *　License as published by the Free Software Foundation; either
 *　version 2.1 of the License, or (at your option) any later version.
 *　This library is distributed in the hope that it will be useful,
 *　but WITHOUT ANY WARRANTY; without even the implied warranty of
 *　MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *　Lesser General Public License for more details.
 *
 *　You should have received a copy of the GNU Lesser General Public
 *　License along with this library; if not, write to the Free Software
 *　Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

package jp.ac.naka.ec.entity;

import java.util.EventObject;

import javax.sip.message.Request;

/**
 * 
 * @author 粕谷
 *
 */
public class EntityEvent extends EventObject {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5024101656766992758L;
	private EntityListener target;
	private String message;

	private net.sourceforge.jsdp.SessionDescription sdp;
	private Request request;
	private EventType type;

	
	private boolean broadcast = false;
	
	/**
	 * 親ノードに対してREGISTERメソッドでリクエストを送る際に用いられる。
	 * @param source
	 */
	public EntityEvent(EntityContainer source) {
		super(source);
		this.type = EventType.REGISTER;
	}
	
	/**
	 * PIDFによる更新情報の伝播に用いられる。
	 * @param entities
	 */
	public EntityEvent(Entity[] entities) {
		super(entities);
		this.type = EventType.NOTIFY;
	}
	
	/**
	 * 
	 * @param target
	 * @param source
	 * @param type
	 */
	public EntityEvent(EntityListener target, Entity source, EventType type) {
		this("", target, source, type);
	}
	
	/**
	 * 
	 * @param message
	 * @param target
	 * @param source
	 * @param type
	 */
	public EntityEvent(String message, EntityListener target, Entity source, EventType type) {
		super(source);
		this.message = message;
		this.target = target;
		this.type = type;
	}

	/**
	 * イベントタイプはMESSAGE
	 * @param message
	 * @param target
	 * @param source
	 */
	public EntityEvent(String message, EntityListener target, Entity source) {
		super(source);
		this.message = message;
		this.target = target;
		this.type = EventType.MESSAGE;
	}

	
	/**
	 * Offer送信の際に用いられる
	 * @param sdp
	 * @param target
	 * @param source
	 */
	public EntityEvent(net.sourceforge.jsdp.SessionDescription sdp, EntityListener target, Entity source) {
		this("", target, source);
		this.type = EventType.OFFER;
		this.sdp = sdp;
	}

	/**
	 * 
	 * @return
	 */
	public EntityListener getTarget() {
		return this.target;
	}

	/**
	 * 
	 * @return
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * 
	 * @param message
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * 
	 * @return
	 */
	public net.sourceforge.jsdp.SessionDescription getSessionDescription() {
		return sdp;
	}

	
	/**
	 * 
	 * @return
	 */
	public EventType getEventType() {
		return type;
	}

	/**
	 * 
	 * @param type
	 */
	public void setEventType(EventType type) {
		this.type = type;
	}

	/**
	 * 
	 * @author 粕谷
	 *
	 */
	public enum EventType {
		MESSAGE, LOCATION, INIT,REGISTER,OFFER, ADD, ANSWER, IMAGE, BYE, SUBSCRIBE, NOTIFY, ACK;
	}

	/**
	 * 
	 * @return
	 */
	public Request getRequest() {
		return request;
	}

	/**
	 * 
	 * @param req
	 */
	public void setRequest(Request req) {
		this.request = req;
	}

	

	/**
	 * 
	 * @return
	 */
	public boolean isBroadcast() {
		return broadcast;
	}

	/**
	 * 
	 * @param broadcast
	 */
	public void setBroadcast(boolean broadcast) {
		this.broadcast = broadcast;
	}
	
	/*
	 * (non-Javadoc)
	 * @see java.util.EventObject#toString()
	 */
	public String toString() {
		return "Target :" + target + ", Type :" + type.toString();
	}
	
}
