/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.impl;

import fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.DesignUnit;
import fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.VAModel;
import fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.VhdlamsPackage;

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.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Package</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.impl.PackageImpl#getDesignUnit <em>Design Unit</em>}</li>
 *   <li>{@link fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.impl.PackageImpl#getOwnerModel <em>Owner Model</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class PackageImpl extends DesignUnitImpl implements fr.femtost.disc.eclipse.vhdlamsmetamodel.vhdlams.Package {
	/**
	 * The cached value of the '{@link #getDesignUnit() <em>Design Unit</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDesignUnit()
	 * @generated
	 * @ordered
	 */
	protected EList<DesignUnit> designUnit;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DesignUnit> getDesignUnit() {
		if (designUnit == null) {
			designUnit = new EObjectContainmentWithInverseEList<DesignUnit>(DesignUnit.class, this, VhdlamsPackage.PACKAGE__DESIGN_UNIT, VhdlamsPackage.DESIGN_UNIT__OWNER);
		}
		return designUnit;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public VAModel getOwnerModel() {
		if (eContainerFeatureID() != VhdlamsPackage.PACKAGE__OWNER_MODEL) return null;
		return (VAModel)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetOwnerModel(VAModel newOwnerModel, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newOwnerModel, VhdlamsPackage.PACKAGE__OWNER_MODEL, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setOwnerModel(VAModel newOwnerModel) {
		if (newOwnerModel != eInternalContainer() || (eContainerFeatureID() != VhdlamsPackage.PACKAGE__OWNER_MODEL && newOwnerModel != null)) {
			if (EcoreUtil.isAncestor(this, newOwnerModel))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newOwnerModel != null)
				msgs = ((InternalEObject)newOwnerModel).eInverseAdd(this, VhdlamsPackage.VA_MODEL__PACKAGE, VAModel.class, msgs);
			msgs = basicSetOwnerModel(newOwnerModel, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, VhdlamsPackage.PACKAGE__OWNER_MODEL, newOwnerModel, newOwnerModel));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case VhdlamsPackage.PACKAGE__DESIGN_UNIT:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getDesignUnit()).basicAdd(otherEnd, msgs);
			case VhdlamsPackage.PACKAGE__OWNER_MODEL:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetOwnerModel((VAModel)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 VhdlamsPackage.PACKAGE__DESIGN_UNIT:
				return ((InternalEList<?>)getDesignUnit()).basicRemove(otherEnd, msgs);
			case VhdlamsPackage.PACKAGE__OWNER_MODEL:
				return basicSetOwnerModel(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case VhdlamsPackage.PACKAGE__OWNER_MODEL:
				return eInternalContainer().eInverseRemove(this, VhdlamsPackage.VA_MODEL__PACKAGE, VAModel.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case VhdlamsPackage.PACKAGE__DESIGN_UNIT:
				return getDesignUnit();
			case VhdlamsPackage.PACKAGE__OWNER_MODEL:
				return getOwnerModel();
		}
		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 VhdlamsPackage.PACKAGE__DESIGN_UNIT:
				getDesignUnit().clear();
				getDesignUnit().addAll((Collection<? extends DesignUnit>)newValue);
				return;
			case VhdlamsPackage.PACKAGE__OWNER_MODEL:
				setOwnerModel((VAModel)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case VhdlamsPackage.PACKAGE__DESIGN_UNIT:
				getDesignUnit().clear();
				return;
			case VhdlamsPackage.PACKAGE__OWNER_MODEL:
				setOwnerModel((VAModel)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case VhdlamsPackage.PACKAGE__DESIGN_UNIT:
				return designUnit != null && !designUnit.isEmpty();
			case VhdlamsPackage.PACKAGE__OWNER_MODEL:
				return getOwnerModel() != null;
		}
		return super.eIsSet(featureID);
	}

} //PackageImpl
