/**
 */
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.DataInstance;
import org.etsi.mts.tdl.DataInstanceUse;
import org.etsi.mts.tdl.DataType;
import org.etsi.mts.tdl.DataUse;
import org.etsi.mts.tdl.UnassignedMemberTreatment;
import org.etsi.mts.tdl.tdlPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Data Instance Use</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link org.etsi.mts.tdl.impl.DataInstanceUseImpl#getDataInstance <em>Data Instance</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.impl.DataInstanceUseImpl#getUnassignedMember <em>Unassigned Member</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.impl.DataInstanceUseImpl#getDataType <em>Data Type</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.impl.DataInstanceUseImpl#getItem <em>Item</em>}</li>
 * </ul>
 *
 * @generated
 */
public class DataInstanceUseImpl extends StaticDataUseImpl implements DataInstanceUse
{
	/**
	 * The cached value of the '{@link #getDataInstance() <em>Data Instance</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataInstance()
	 * @generated
	 * @ordered
	 */
	protected DataInstance dataInstance;

	/**
	 * The default value of the '{@link #getUnassignedMember() <em>Unassigned Member</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUnassignedMember()
	 * @generated
	 * @ordered
	 */
	protected static final UnassignedMemberTreatment UNASSIGNED_MEMBER_EDEFAULT = UnassignedMemberTreatment.UNDEFINED;

	/**
	 * The cached value of the '{@link #getUnassignedMember() <em>Unassigned Member</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUnassignedMember()
	 * @generated
	 * @ordered
	 */
	protected UnassignedMemberTreatment unassignedMember = UNASSIGNED_MEMBER_EDEFAULT;

	/**
	 * The cached value of the '{@link #getDataType() <em>Data Type</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataType()
	 * @generated
	 * @ordered
	 */
	protected DataType dataType;

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public DataInstance getDataInstance()
	{
		if (dataInstance != null && dataInstance.eIsProxy()) {
			InternalEObject oldDataInstance = (InternalEObject)dataInstance;
			dataInstance = (DataInstance)eResolveProxy(oldDataInstance);
			if (dataInstance != oldDataInstance) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, tdlPackage.DATA_INSTANCE_USE__DATA_INSTANCE, oldDataInstance, dataInstance));
			}
		}
		return dataInstance;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DataInstance basicGetDataInstance()
	{
		return dataInstance;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setDataInstance(DataInstance newDataInstance)
	{
		DataInstance oldDataInstance = dataInstance;
		dataInstance = newDataInstance;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, tdlPackage.DATA_INSTANCE_USE__DATA_INSTANCE, oldDataInstance, dataInstance));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public UnassignedMemberTreatment getUnassignedMember()
	{
		return unassignedMember;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setUnassignedMember(UnassignedMemberTreatment newUnassignedMember)
	{
		UnassignedMemberTreatment oldUnassignedMember = unassignedMember;
		unassignedMember = newUnassignedMember == null ? UNASSIGNED_MEMBER_EDEFAULT : newUnassignedMember;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, tdlPackage.DATA_INSTANCE_USE__UNASSIGNED_MEMBER, oldUnassignedMember, unassignedMember));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public DataType getDataType()
	{
		if (dataType != null && dataType.eIsProxy()) {
			InternalEObject oldDataType = (InternalEObject)dataType;
			dataType = (DataType)eResolveProxy(oldDataType);
			if (dataType != oldDataType) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, tdlPackage.DATA_INSTANCE_USE__DATA_TYPE, oldDataType, dataType));
			}
		}
		return dataType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DataType basicGetDataType()
	{
		return dataType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setDataType(DataType newDataType)
	{
		DataType oldDataType = dataType;
		dataType = newDataType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, tdlPackage.DATA_INSTANCE_USE__DATA_TYPE, oldDataType, dataType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EList<DataUse> getItem()
	{
		if (item == null) {
			item = new EObjectContainmentEList<DataUse>(DataUse.class, this, tdlPackage.DATA_INSTANCE_USE__ITEM);
		}
		return item;
	}

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public DataType resolveDataType()
	{
		try {
			return (DataType)RESOLVE_DATA_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.DATA_INSTANCE_USE__ITEM:
				return ((InternalEList<?>)getItem()).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.DATA_INSTANCE_USE__DATA_INSTANCE:
				if (resolve) return getDataInstance();
				return basicGetDataInstance();
			case tdlPackage.DATA_INSTANCE_USE__UNASSIGNED_MEMBER:
				return getUnassignedMember();
			case tdlPackage.DATA_INSTANCE_USE__DATA_TYPE:
				if (resolve) return getDataType();
				return basicGetDataType();
			case tdlPackage.DATA_INSTANCE_USE__ITEM:
				return getItem();
		}
		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.DATA_INSTANCE_USE__DATA_INSTANCE:
				setDataInstance((DataInstance)newValue);
				return;
			case tdlPackage.DATA_INSTANCE_USE__UNASSIGNED_MEMBER:
				setUnassignedMember((UnassignedMemberTreatment)newValue);
				return;
			case tdlPackage.DATA_INSTANCE_USE__DATA_TYPE:
				setDataType((DataType)newValue);
				return;
			case tdlPackage.DATA_INSTANCE_USE__ITEM:
				getItem().clear();
				getItem().addAll((Collection<? extends DataUse>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID)
	{
		switch (featureID) {
			case tdlPackage.DATA_INSTANCE_USE__DATA_INSTANCE:
				setDataInstance((DataInstance)null);
				return;
			case tdlPackage.DATA_INSTANCE_USE__UNASSIGNED_MEMBER:
				setUnassignedMember(UNASSIGNED_MEMBER_EDEFAULT);
				return;
			case tdlPackage.DATA_INSTANCE_USE__DATA_TYPE:
				setDataType((DataType)null);
				return;
			case tdlPackage.DATA_INSTANCE_USE__ITEM:
				getItem().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID)
	{
		switch (featureID) {
			case tdlPackage.DATA_INSTANCE_USE__DATA_INSTANCE:
				return dataInstance != null;
			case tdlPackage.DATA_INSTANCE_USE__UNASSIGNED_MEMBER:
				return unassignedMember != UNASSIGNED_MEMBER_EDEFAULT;
			case tdlPackage.DATA_INSTANCE_USE__DATA_TYPE:
				return dataType != null;
			case tdlPackage.DATA_INSTANCE_USE__ITEM:
				return item != null && !item.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eDerivedOperationID(int baseOperationID, Class<?> baseClass)
	{
		if (baseClass == DataUse.class) {
			switch (baseOperationID) {
				case tdlPackage.DATA_USE___RESOLVE_DATA_TYPE: return tdlPackage.DATA_INSTANCE_USE___RESOLVE_DATA_TYPE;
				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.DATA_INSTANCE_USE___RESOLVE_DATA_TYPE:
				return resolveDataType();
		}
		return super.eInvoke(operationID, arguments);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString()
	{
		if (eIsProxy()) return super.toString();

		StringBuilder result = new StringBuilder(super.toString());
		result.append(" (unassignedMember: ");
		result.append(unassignedMember);
		result.append(')');
		return result.toString();
	}

} //DataInstanceUseImpl
