package de.uka.ipd.consensus.foundation.ontology;

import de.uka.ipd.consensus.foundation.AbstractConsensusFoundationEvent;
import de.uka.ipd.consensus.foundation.ConsensusFoundationManager;
import de.uka.ipd.consensus.foundation.schema.Concept;
import de.uka.ipd.consensus.foundation.schema.Occurrence;
import de.uka.ipd.consensus.foundation.schema.Synonym;
import de.uka.ipd.consensus.foundation.schema.Topic;
import de.uka.ipd.consensus.foundation.schema.User;

/**
 * Event objects of this type are passed to OntologyListeners.
 * @author Thomas Much
 * @version 2006-06-14
 * @see OntologyListener
 */
public class OntologyEvent extends AbstractConsensusFoundationEvent {
	
	private User       user;
	private String     oldValue;
	private Topic      oldType;
	private Topic      topic;
	private Occurrence occurrence;
	private Synonym    synonym;


	public OntologyEvent(ConsensusFoundationManager cfm, Concept source, User user, String oldValue, Topic oldType, Topic topic, Occurrence occurrence, Synonym synonym) {
		super(cfm,source);
		this.user       = user;
		this.oldValue   = oldValue;
		this.oldType    = oldType;
		this.topic      = topic;
		this.occurrence = occurrence;
		this.synonym    = synonym;
	}


	public OntologyEvent(ConsensusFoundationManager cfm, Concept source, User user) {
		this(cfm,source,user,null,null,null,null,null);
	}

	
	/**
	 * All ontology events happen on a base concept that is returned by this method.
	 * @return the base concept that the event happened on
	 */
	public Concept getConcept() {
		return (Concept)getSource();
	}
	
	
	/**
	 * Returns the user who caused the event, i.e. the user who created or removed an element etc.
	 * @return the user who caused the event
	 */
	public User getUser() {
		return this.user;
	}


	/**
	 * If a string value (like a concept name or an occurrence value) was changed, this method returns the old value.
	 * @return the old string value
	 */
	public String getOldValue() {
		return this.oldValue;
	}
	

	/**
	 * If the type of a concept changes, this method returns the old type.
	 * <code>null</code> is returned if the concept did not have a type before.
	 * @return the old type topic
	 */
	public Topic getOldType() {
		return this.oldType;
	}


	/**
	 * If an event happens on a topic aditionally to the base concept (e.g. if a topic is added to a base association), this method returns the topic.
	 * @return the topic if the event includes a topic in addition to another base concept
	 * @see #getConcept()
	 */
	public Topic getTopic() {
		return this.topic;
	}
	

	/**
	 * Returns the occurrence for occurrence events (creating, changing, removing).
	 * @return an occurrence
	 */
	public Occurrence getOccurrence() {
		return this.occurrence;
	}


	/**
	 * If a synonym is added or removed, this method returns the Synonym object.
	 * @return the Synonym object
	 */
	public Synonym getSynonym() {
		return this.synonym;
	}
}
