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

import java.lang.reflect.InvocationTargetException;

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.common.util.WrappedException;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EOperation;
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.AtomicBehaviour;
import org.etsi.mts.tdl.Behaviour;
import org.etsi.mts.tdl.ComponentInstance;
import org.etsi.mts.tdl.GateReference;
import org.etsi.mts.tdl.Interaction;
import org.etsi.mts.tdl.Target;
import org.etsi.mts.tdl.tdlPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Interaction</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link org.etsi.mts.tdl.impl.InteractionImpl#getSourceGate <em>Source Gate</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.impl.InteractionImpl#getTarget <em>Target</em>}</li>
 * </ul>
 *
 * @generated
 */
public class InteractionImpl extends AtomicBehaviourImpl implements Interaction
{
	/**
	 * The cached value of the '{@link #getSourceGate() <em>Source Gate</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSourceGate()
	 * @generated
	 * @ordered
	 */
	protected GateReference sourceGate;

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public GateReference getSourceGate()
	{
		if (sourceGate != null && sourceGate.eIsProxy())
		{
			InternalEObject oldSourceGate = (InternalEObject)sourceGate;
			sourceGate = (GateReference)eResolveProxy(oldSourceGate);
			if (sourceGate != oldSourceGate)
			{
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, tdlPackage.INTERACTION__SOURCE_GATE, oldSourceGate, sourceGate));
			}
		}
		return sourceGate;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public GateReference basicGetSourceGate()
	{
		return sourceGate;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setSourceGate(GateReference newSourceGate)
	{
		GateReference oldSourceGate = sourceGate;
		sourceGate = newSourceGate;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, tdlPackage.INTERACTION__SOURCE_GATE, oldSourceGate, sourceGate));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EList<Target> getTarget()
	{
		if (target == null)
		{
			target = new EObjectContainmentEList<Target>(Target.class, this, tdlPackage.INTERACTION__TARGET);
		}
		return target;
	}

	/**
	 * The cached invocation delegate for the '{@link #getParticipatingComponents() <em>Get Participating Components</em>}' operation.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParticipatingComponents()
	 * @generated
	 * @ordered
	 */
	protected static final EOperation.Internal.InvocationDelegate GET_PARTICIPATING_COMPONENTS__EINVOCATION_DELEGATE = ((EOperation.Internal)tdlPackage.Literals.INTERACTION___GET_PARTICIPATING_COMPONENTS).getInvocationDelegate();

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public EList<ComponentInstance> getParticipatingComponents()
	{
		try
		{
			return (EList<ComponentInstance>)GET_PARTICIPATING_COMPONENTS__EINVOCATION_DELEGATE.dynamicInvoke(this, null);
		}
		catch (InvocationTargetException ite)
		{
			throw new WrappedException(ite);
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
	{
		switch (featureID)
		{
			case tdlPackage.INTERACTION__TARGET:
				return ((InternalEList<?>)getTarget()).basicRemove(otherEnd, 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 tdlPackage.INTERACTION__SOURCE_GATE:
				if (resolve) return getSourceGate();
				return basicGetSourceGate();
			case tdlPackage.INTERACTION__TARGET:
				return getTarget();
		}
		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 tdlPackage.INTERACTION__SOURCE_GATE:
				setSourceGate((GateReference)newValue);
				return;
			case tdlPackage.INTERACTION__TARGET:
				getTarget().clear();
				getTarget().addAll((Collection<? extends Target>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID)
	{
		switch (featureID)
		{
			case tdlPackage.INTERACTION__SOURCE_GATE:
				setSourceGate((GateReference)null);
				return;
			case tdlPackage.INTERACTION__TARGET:
				getTarget().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID)
	{
		switch (featureID)
		{
			case tdlPackage.INTERACTION__SOURCE_GATE:
				return sourceGate != null;
			case tdlPackage.INTERACTION__TARGET:
				return target != null && !target.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eDerivedOperationID(int baseOperationID, Class<?> baseClass)
	{
		if (baseClass == Behaviour.class)
		{
			switch (baseOperationID)
			{
				case tdlPackage.BEHAVIOUR___GET_PARTICIPATING_COMPONENTS: return tdlPackage.INTERACTION___GET_PARTICIPATING_COMPONENTS;
				default: return super.eDerivedOperationID(baseOperationID, baseClass);
			}
		}
		if (baseClass == AtomicBehaviour.class)
		{
			switch (baseOperationID)
			{
				case tdlPackage.ATOMIC_BEHAVIOUR___GET_PARTICIPATING_COMPONENTS: return tdlPackage.INTERACTION___GET_PARTICIPATING_COMPONENTS;
				default: return super.eDerivedOperationID(baseOperationID, baseClass);
			}
		}
		return super.eDerivedOperationID(baseOperationID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException
	{
		switch (operationID)
		{
			case tdlPackage.INTERACTION___GET_PARTICIPATING_COMPONENTS:
				return getParticipatingComponents();
		}
		return super.eInvoke(operationID, arguments);
	}

} //InteractionImpl
