/**
 */
package org.etsi.mts.tdl.structuredobjectives.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.etsi.mts.tdl.structuredobjectives.EntityBinding;
import org.etsi.mts.tdl.structuredobjectives.EventSpecificationTemplate;
import org.etsi.mts.tdl.structuredobjectives.EventTemplateOccurrence;
import org.etsi.mts.tdl.structuredobjectives.StructuredObjectivesPackage;
import org.etsi.mts.tdl.structuredobjectives.Value;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Event Template Occurrence</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link org.etsi.mts.tdl.structuredobjectives.impl.EventTemplateOccurrenceImpl#getEventTemplate <em>Event Template</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.structuredobjectives.impl.EventTemplateOccurrenceImpl#getEntityBinding <em>Entity Binding</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.structuredobjectives.impl.EventTemplateOccurrenceImpl#getOccurrenceArgument <em>Occurrence Argument</em>}</li>
 * </ul>
 *
 * @generated
 */
public class EventTemplateOccurrenceImpl extends EventOccurrenceImpl implements EventTemplateOccurrence
{
	/**
	 * The cached value of the '{@link #getEventTemplate() <em>Event Template</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEventTemplate()
	 * @generated
	 * @ordered
	 */
	protected EventSpecificationTemplate eventTemplate;

	/**
	 * The cached value of the '{@link #getEntityBinding() <em>Entity Binding</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEntityBinding()
	 * @generated
	 * @ordered
	 */
	protected EList<EntityBinding> entityBinding;

	/**
	 * The cached value of the '{@link #getOccurrenceArgument() <em>Occurrence Argument</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOccurrenceArgument()
	 * @generated
	 * @ordered
	 */
	protected Value occurrenceArgument;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EventTemplateOccurrenceImpl()
	{
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass()
	{
		return StructuredObjectivesPackage.Literals.EVENT_TEMPLATE_OCCURRENCE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EventSpecificationTemplate getEventTemplate()
	{
		if (eventTemplate != null && eventTemplate.eIsProxy())
		{
			InternalEObject oldEventTemplate = (InternalEObject)eventTemplate;
			eventTemplate = (EventSpecificationTemplate)eResolveProxy(oldEventTemplate);
			if (eventTemplate != oldEventTemplate)
			{
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__EVENT_TEMPLATE, oldEventTemplate, eventTemplate));
			}
		}
		return eventTemplate;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EventSpecificationTemplate basicGetEventTemplate()
	{
		return eventTemplate;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setEventTemplate(EventSpecificationTemplate newEventTemplate)
	{
		EventSpecificationTemplate oldEventTemplate = eventTemplate;
		eventTemplate = newEventTemplate;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__EVENT_TEMPLATE, oldEventTemplate, eventTemplate));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EList<EntityBinding> getEntityBinding()
	{
		if (entityBinding == null)
		{
			entityBinding = new EObjectContainmentEList<EntityBinding>(EntityBinding.class, this, StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__ENTITY_BINDING);
		}
		return entityBinding;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Value getOccurrenceArgument()
	{
		return occurrenceArgument;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetOccurrenceArgument(Value newOccurrenceArgument, NotificationChain msgs)
	{
		Value oldOccurrenceArgument = occurrenceArgument;
		occurrenceArgument = newOccurrenceArgument;
		if (eNotificationRequired())
		{
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__OCCURRENCE_ARGUMENT, oldOccurrenceArgument, newOccurrenceArgument);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setOccurrenceArgument(Value newOccurrenceArgument)
	{
		if (newOccurrenceArgument != occurrenceArgument)
		{
			NotificationChain msgs = null;
			if (occurrenceArgument != null)
				msgs = ((InternalEObject)occurrenceArgument).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__OCCURRENCE_ARGUMENT, null, msgs);
			if (newOccurrenceArgument != null)
				msgs = ((InternalEObject)newOccurrenceArgument).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__OCCURRENCE_ARGUMENT, null, msgs);
			msgs = basicSetOccurrenceArgument(newOccurrenceArgument, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__OCCURRENCE_ARGUMENT, newOccurrenceArgument, newOccurrenceArgument));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
	{
		switch (featureID)
		{
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__ENTITY_BINDING:
				return ((InternalEList<?>)getEntityBinding()).basicRemove(otherEnd, msgs);
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__OCCURRENCE_ARGUMENT:
				return basicSetOccurrenceArgument(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType)
	{
		switch (featureID)
		{
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__EVENT_TEMPLATE:
				if (resolve) return getEventTemplate();
				return basicGetEventTemplate();
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__ENTITY_BINDING:
				return getEntityBinding();
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__OCCURRENCE_ARGUMENT:
				return getOccurrenceArgument();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue)
	{
		switch (featureID)
		{
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__EVENT_TEMPLATE:
				setEventTemplate((EventSpecificationTemplate)newValue);
				return;
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__ENTITY_BINDING:
				getEntityBinding().clear();
				getEntityBinding().addAll((Collection<? extends EntityBinding>)newValue);
				return;
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__OCCURRENCE_ARGUMENT:
				setOccurrenceArgument((Value)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID)
	{
		switch (featureID)
		{
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__EVENT_TEMPLATE:
				setEventTemplate((EventSpecificationTemplate)null);
				return;
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__ENTITY_BINDING:
				getEntityBinding().clear();
				return;
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__OCCURRENCE_ARGUMENT:
				setOccurrenceArgument((Value)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID)
	{
		switch (featureID)
		{
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__EVENT_TEMPLATE:
				return eventTemplate != null;
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__ENTITY_BINDING:
				return entityBinding != null && !entityBinding.isEmpty();
			case StructuredObjectivesPackage.EVENT_TEMPLATE_OCCURRENCE__OCCURRENCE_ARGUMENT:
				return occurrenceArgument != null;
		}
		return super.eIsSet(featureID);
	}

} //EventTemplateOccurrenceImpl
