/**
 */
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.DataType;
import org.etsi.mts.tdl.DataUse;
import org.etsi.mts.tdl.MemberReference;
import org.etsi.mts.tdl.Parameter;
import org.etsi.mts.tdl.ParameterBinding;
import org.etsi.mts.tdl.tdlPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Parameter Binding</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link org.etsi.mts.tdl.impl.ParameterBindingImpl#getDataUse <em>Data Use</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.impl.ParameterBindingImpl#getParameter <em>Parameter</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.impl.ParameterBindingImpl#getReduction <em>Reduction</em>}</li>
 * </ul>
 *
 * @generated
 */
public class ParameterBindingImpl extends ElementImpl implements ParameterBinding
{
	/**
	 * The cached value of the '{@link #getDataUse() <em>Data Use</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataUse()
	 * @generated
	 * @ordered
	 */
	protected DataUse dataUse;

	/**
	 * The cached value of the '{@link #getParameter() <em>Parameter</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParameter()
	 * @generated
	 * @ordered
	 */
	protected Parameter parameter;

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public DataUse getDataUse()
	{
		return dataUse;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetDataUse(DataUse newDataUse, NotificationChain msgs)
	{
		DataUse oldDataUse = dataUse;
		dataUse = newDataUse;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, tdlPackage.PARAMETER_BINDING__DATA_USE, oldDataUse, newDataUse);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setDataUse(DataUse newDataUse)
	{
		if (newDataUse != dataUse) {
			NotificationChain msgs = null;
			if (dataUse != null)
				msgs = ((InternalEObject)dataUse).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - tdlPackage.PARAMETER_BINDING__DATA_USE, null, msgs);
			if (newDataUse != null)
				msgs = ((InternalEObject)newDataUse).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - tdlPackage.PARAMETER_BINDING__DATA_USE, null, msgs);
			msgs = basicSetDataUse(newDataUse, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, tdlPackage.PARAMETER_BINDING__DATA_USE, newDataUse, newDataUse));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Parameter getParameter()
	{
		if (parameter != null && parameter.eIsProxy()) {
			InternalEObject oldParameter = (InternalEObject)parameter;
			parameter = (Parameter)eResolveProxy(oldParameter);
			if (parameter != oldParameter) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, tdlPackage.PARAMETER_BINDING__PARAMETER, oldParameter, parameter));
			}
		}
		return parameter;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Parameter basicGetParameter()
	{
		return parameter;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setParameter(Parameter newParameter)
	{
		Parameter oldParameter = parameter;
		parameter = newParameter;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, tdlPackage.PARAMETER_BINDING__PARAMETER, oldParameter, parameter));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EList<MemberReference> getReduction()
	{
		if (reduction == null) {
			reduction = new EObjectContainmentEList<MemberReference>(MemberReference.class, this, tdlPackage.PARAMETER_BINDING__REDUCTION);
		}
		return reduction;
	}

	/**
	 * The cached invocation delegate for the '{@link #resolveParameterType() <em>Resolve Parameter Type</em>}' operation.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #resolveParameterType()
	 * @generated
	 * @ordered
	 */
	protected static final EOperation.Internal.InvocationDelegate RESOLVE_PARAMETER_TYPE__EINVOCATION_DELEGATE = ((EOperation.Internal)tdlPackage.Literals.PARAMETER_BINDING___RESOLVE_PARAMETER_TYPE).getInvocationDelegate();

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public DataType resolveParameterType() {
		try {
			return (DataType)RESOLVE_PARAMETER_TYPE__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.PARAMETER_BINDING__DATA_USE:
				return basicSetDataUse(null, msgs);
			case tdlPackage.PARAMETER_BINDING__REDUCTION:
				return ((InternalEList<?>)getReduction()).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.PARAMETER_BINDING__DATA_USE:
				return getDataUse();
			case tdlPackage.PARAMETER_BINDING__PARAMETER:
				if (resolve) return getParameter();
				return basicGetParameter();
			case tdlPackage.PARAMETER_BINDING__REDUCTION:
				return getReduction();
		}
		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.PARAMETER_BINDING__DATA_USE:
				setDataUse((DataUse)newValue);
				return;
			case tdlPackage.PARAMETER_BINDING__PARAMETER:
				setParameter((Parameter)newValue);
				return;
			case tdlPackage.PARAMETER_BINDING__REDUCTION:
				getReduction().clear();
				getReduction().addAll((Collection<? extends MemberReference>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID)
	{
		switch (featureID) {
			case tdlPackage.PARAMETER_BINDING__DATA_USE:
				setDataUse((DataUse)null);
				return;
			case tdlPackage.PARAMETER_BINDING__PARAMETER:
				setParameter((Parameter)null);
				return;
			case tdlPackage.PARAMETER_BINDING__REDUCTION:
				getReduction().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID)
	{
		switch (featureID) {
			case tdlPackage.PARAMETER_BINDING__DATA_USE:
				return dataUse != null;
			case tdlPackage.PARAMETER_BINDING__PARAMETER:
				return parameter != null;
			case tdlPackage.PARAMETER_BINDING__REDUCTION:
				return reduction != null && !reduction.isEmpty();
		}
		return super.eIsSet(featureID);
	}

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

} //ParameterBindingImpl
