/**
 */
package ua.ansymo.hintco.impl;

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

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

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

import ua.ansymo.hintco.HintcoPackage;
import ua.ansymo.hintco.InputPortDeclaration;
import ua.ansymo.hintco.InputPortInstance;
import ua.ansymo.hintco.OutputPortInstance;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Input Port Instance</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link ua.ansymo.hintco.impl.InputPortInstanceImpl#getDeclaration <em>Declaration</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.InputPortInstanceImpl#getValueFrom <em>Value From</em>}</li>
 * </ul>
 *
 * @generated
 */
public class InputPortInstanceImpl extends PortInstanceImpl implements InputPortInstance {
	/**
	 * The cached value of the '{@link #getDeclaration() <em>Declaration</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDeclaration()
	 * @generated
	 * @ordered
	 */
	protected InputPortDeclaration declaration;

	/**
	 * The cached value of the '{@link #getValueFrom() <em>Value From</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getValueFrom()
	 * @generated
	 * @ordered
	 */
	protected OutputPortInstance valueFrom;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public InputPortDeclaration getDeclaration() {
		if (declaration != null && declaration.eIsProxy()) {
			InternalEObject oldDeclaration = (InternalEObject)declaration;
			declaration = (InputPortDeclaration)eResolveProxy(oldDeclaration);
			if (declaration != oldDeclaration) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, HintcoPackage.INPUT_PORT_INSTANCE__DECLARATION, oldDeclaration, declaration));
			}
		}
		return declaration;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public InputPortDeclaration basicGetDeclaration() {
		return declaration;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDeclaration(InputPortDeclaration newDeclaration) {
		InputPortDeclaration oldDeclaration = declaration;
		declaration = newDeclaration;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.INPUT_PORT_INSTANCE__DECLARATION, oldDeclaration, declaration));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public OutputPortInstance getValueFrom() {
		if (valueFrom != null && valueFrom.eIsProxy()) {
			InternalEObject oldValueFrom = (InternalEObject)valueFrom;
			valueFrom = (OutputPortInstance)eResolveProxy(oldValueFrom);
			if (valueFrom != oldValueFrom) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, HintcoPackage.INPUT_PORT_INSTANCE__VALUE_FROM, oldValueFrom, valueFrom));
			}
		}
		return valueFrom;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public OutputPortInstance basicGetValueFrom() {
		return valueFrom;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetValueFrom(OutputPortInstance newValueFrom, NotificationChain msgs) {
		OutputPortInstance oldValueFrom = valueFrom;
		valueFrom = newValueFrom;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, HintcoPackage.INPUT_PORT_INSTANCE__VALUE_FROM, oldValueFrom, newValueFrom);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setValueFrom(OutputPortInstance newValueFrom) {
		if (newValueFrom != valueFrom) {
			NotificationChain msgs = null;
			if (valueFrom != null)
				msgs = ((InternalEObject)valueFrom).eInverseRemove(this, HintcoPackage.OUTPUT_PORT_INSTANCE__VALUE_TO, OutputPortInstance.class, msgs);
			if (newValueFrom != null)
				msgs = ((InternalEObject)newValueFrom).eInverseAdd(this, HintcoPackage.OUTPUT_PORT_INSTANCE__VALUE_TO, OutputPortInstance.class, msgs);
			msgs = basicSetValueFrom(newValueFrom, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.INPUT_PORT_INSTANCE__VALUE_FROM, newValueFrom, newValueFrom));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case HintcoPackage.INPUT_PORT_INSTANCE__VALUE_FROM:
				if (valueFrom != null)
					msgs = ((InternalEObject)valueFrom).eInverseRemove(this, HintcoPackage.OUTPUT_PORT_INSTANCE__VALUE_TO, OutputPortInstance.class, msgs);
				return basicSetValueFrom((OutputPortInstance)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case HintcoPackage.INPUT_PORT_INSTANCE__VALUE_FROM:
				return basicSetValueFrom(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 HintcoPackage.INPUT_PORT_INSTANCE__DECLARATION:
				if (resolve) return getDeclaration();
				return basicGetDeclaration();
			case HintcoPackage.INPUT_PORT_INSTANCE__VALUE_FROM:
				if (resolve) return getValueFrom();
				return basicGetValueFrom();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case HintcoPackage.INPUT_PORT_INSTANCE__DECLARATION:
				setDeclaration((InputPortDeclaration)newValue);
				return;
			case HintcoPackage.INPUT_PORT_INSTANCE__VALUE_FROM:
				setValueFrom((OutputPortInstance)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case HintcoPackage.INPUT_PORT_INSTANCE__DECLARATION:
				setDeclaration((InputPortDeclaration)null);
				return;
			case HintcoPackage.INPUT_PORT_INSTANCE__VALUE_FROM:
				setValueFrom((OutputPortInstance)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case HintcoPackage.INPUT_PORT_INSTANCE__DECLARATION:
				return declaration != null;
			case HintcoPackage.INPUT_PORT_INSTANCE__VALUE_FROM:
				return valueFrom != null;
		}
		return super.eIsSet(featureID);
	}

} //InputPortInstanceImpl
