/**
 */
package org.etsi.mts.tdl.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.DataElementMapping;
import org.etsi.mts.tdl.DataResourceMapping;
import org.etsi.mts.tdl.MappableDataElement;
import org.etsi.mts.tdl.ParameterMapping;
import org.etsi.mts.tdl.tdlPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Data Element Mapping</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link org.etsi.mts.tdl.impl.DataElementMappingImpl#getMappableDataElement <em>Mappable Data Element</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.impl.DataElementMappingImpl#getElementURI <em>Element URI</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.impl.DataElementMappingImpl#getDataResourceMapping <em>Data Resource Mapping</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.impl.DataElementMappingImpl#getParameterMapping <em>Parameter Mapping</em>}</li>
 * </ul>
 *
 * @generated
 */
public class DataElementMappingImpl extends PackageableElementImpl implements DataElementMapping
{
	/**
	 * The cached value of the '{@link #getMappableDataElement() <em>Mappable Data Element</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMappableDataElement()
	 * @generated
	 * @ordered
	 */
	protected MappableDataElement mappableDataElement;

	/**
	 * The default value of the '{@link #getElementURI() <em>Element URI</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getElementURI()
	 * @generated
	 * @ordered
	 */
	protected static final String ELEMENT_URI_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getElementURI() <em>Element URI</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getElementURI()
	 * @generated
	 * @ordered
	 */
	protected String elementURI = ELEMENT_URI_EDEFAULT;

	/**
	 * The cached value of the '{@link #getDataResourceMapping() <em>Data Resource Mapping</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataResourceMapping()
	 * @generated
	 * @ordered
	 */
	protected DataResourceMapping dataResourceMapping;

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public MappableDataElement getMappableDataElement()
	{
		if (mappableDataElement != null && mappableDataElement.eIsProxy()) {
			InternalEObject oldMappableDataElement = (InternalEObject)mappableDataElement;
			mappableDataElement = (MappableDataElement)eResolveProxy(oldMappableDataElement);
			if (mappableDataElement != oldMappableDataElement) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, tdlPackage.DATA_ELEMENT_MAPPING__MAPPABLE_DATA_ELEMENT, oldMappableDataElement, mappableDataElement));
			}
		}
		return mappableDataElement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public MappableDataElement basicGetMappableDataElement()
	{
		return mappableDataElement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setMappableDataElement(MappableDataElement newMappableDataElement)
	{
		MappableDataElement oldMappableDataElement = mappableDataElement;
		mappableDataElement = newMappableDataElement;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, tdlPackage.DATA_ELEMENT_MAPPING__MAPPABLE_DATA_ELEMENT, oldMappableDataElement, mappableDataElement));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String getElementURI()
	{
		return elementURI;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setElementURI(String newElementURI)
	{
		String oldElementURI = elementURI;
		elementURI = newElementURI;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, tdlPackage.DATA_ELEMENT_MAPPING__ELEMENT_URI, oldElementURI, elementURI));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public DataResourceMapping getDataResourceMapping()
	{
		if (dataResourceMapping != null && dataResourceMapping.eIsProxy()) {
			InternalEObject oldDataResourceMapping = (InternalEObject)dataResourceMapping;
			dataResourceMapping = (DataResourceMapping)eResolveProxy(oldDataResourceMapping);
			if (dataResourceMapping != oldDataResourceMapping) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, tdlPackage.DATA_ELEMENT_MAPPING__DATA_RESOURCE_MAPPING, oldDataResourceMapping, dataResourceMapping));
			}
		}
		return dataResourceMapping;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DataResourceMapping basicGetDataResourceMapping()
	{
		return dataResourceMapping;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setDataResourceMapping(DataResourceMapping newDataResourceMapping)
	{
		DataResourceMapping oldDataResourceMapping = dataResourceMapping;
		dataResourceMapping = newDataResourceMapping;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, tdlPackage.DATA_ELEMENT_MAPPING__DATA_RESOURCE_MAPPING, oldDataResourceMapping, dataResourceMapping));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EList<ParameterMapping> getParameterMapping()
	{
		if (parameterMapping == null) {
			parameterMapping = new EObjectContainmentEList<ParameterMapping>(ParameterMapping.class, this, tdlPackage.DATA_ELEMENT_MAPPING__PARAMETER_MAPPING);
		}
		return parameterMapping;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
	{
		switch (featureID) {
			case tdlPackage.DATA_ELEMENT_MAPPING__PARAMETER_MAPPING:
				return ((InternalEList<?>)getParameterMapping()).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_ELEMENT_MAPPING__MAPPABLE_DATA_ELEMENT:
				if (resolve) return getMappableDataElement();
				return basicGetMappableDataElement();
			case tdlPackage.DATA_ELEMENT_MAPPING__ELEMENT_URI:
				return getElementURI();
			case tdlPackage.DATA_ELEMENT_MAPPING__DATA_RESOURCE_MAPPING:
				if (resolve) return getDataResourceMapping();
				return basicGetDataResourceMapping();
			case tdlPackage.DATA_ELEMENT_MAPPING__PARAMETER_MAPPING:
				return getParameterMapping();
		}
		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_ELEMENT_MAPPING__MAPPABLE_DATA_ELEMENT:
				setMappableDataElement((MappableDataElement)newValue);
				return;
			case tdlPackage.DATA_ELEMENT_MAPPING__ELEMENT_URI:
				setElementURI((String)newValue);
				return;
			case tdlPackage.DATA_ELEMENT_MAPPING__DATA_RESOURCE_MAPPING:
				setDataResourceMapping((DataResourceMapping)newValue);
				return;
			case tdlPackage.DATA_ELEMENT_MAPPING__PARAMETER_MAPPING:
				getParameterMapping().clear();
				getParameterMapping().addAll((Collection<? extends ParameterMapping>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID)
	{
		switch (featureID) {
			case tdlPackage.DATA_ELEMENT_MAPPING__MAPPABLE_DATA_ELEMENT:
				setMappableDataElement((MappableDataElement)null);
				return;
			case tdlPackage.DATA_ELEMENT_MAPPING__ELEMENT_URI:
				setElementURI(ELEMENT_URI_EDEFAULT);
				return;
			case tdlPackage.DATA_ELEMENT_MAPPING__DATA_RESOURCE_MAPPING:
				setDataResourceMapping((DataResourceMapping)null);
				return;
			case tdlPackage.DATA_ELEMENT_MAPPING__PARAMETER_MAPPING:
				getParameterMapping().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID)
	{
		switch (featureID) {
			case tdlPackage.DATA_ELEMENT_MAPPING__MAPPABLE_DATA_ELEMENT:
				return mappableDataElement != null;
			case tdlPackage.DATA_ELEMENT_MAPPING__ELEMENT_URI:
				return ELEMENT_URI_EDEFAULT == null ? elementURI != null : !ELEMENT_URI_EDEFAULT.equals(elementURI);
			case tdlPackage.DATA_ELEMENT_MAPPING__DATA_RESOURCE_MAPPING:
				return dataResourceMapping != null;
			case tdlPackage.DATA_ELEMENT_MAPPING__PARAMETER_MAPPING:
				return parameterMapping != null && !parameterMapping.isEmpty();
		}
		return super.eIsSet(featureID);
	}

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

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

} //DataElementMappingImpl
