/*
 *
 * This source file belongs to the MDD4SOA suite developed at the Institute of 
 * Computer Science, Programming and Software Engineering, of the Ludwig-Maximilians-
 * Universität München, Germany. 
 * 
 * http://www.pst.ifi.lmu.de/
 * http://www.mdd4soa.eu/
 *
 * See the enclosed LICENSE file for licensing information.
 *
 */
package de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.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.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

import de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Type;
import de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.TypePackage;

/**
 * <!-- 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 de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.impl.PackageImpl#getReferencedTypes <em>Referenced Types</em>}</li>
 *   <li>{@link de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.impl.PackageImpl#getParent <em>Parent</em>}</li>
 *   <li>{@link de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.impl.PackageImpl#getChildren <em>Children</em>}</li>
 *   <li>{@link de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.impl.PackageImpl#getTypes <em>Types</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class PackageImpl extends NamedElementImpl implements de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package {
	/**
	 * The cached value of the '{@link #getReferencedTypes() <em>Referenced Types</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReferencedTypes()
	 * @generated
	 * @ordered
	 */
	protected EList<Type> referencedTypes;
	/**
	 * The cached value of the '{@link #getChildren() <em>Children</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getChildren()
	 * @generated
	 * @ordered
	 */
	protected EList<de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package> children;
	/**
	 * The cached value of the '{@link #getTypes() <em>Types</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypes()
	 * @generated
	 * @ordered
	 */
	protected EList<Type> types;
	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @generated
	 */
	protected PackageImpl() {
		super();
	}

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Type> getReferencedTypes() {
		if (referencedTypes == null) {
			referencedTypes = new EObjectContainmentEList<Type>(Type.class, this, TypePackage.PACKAGE__REFERENCED_TYPES);
		}
		return referencedTypes;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @generated
	 */
	public de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package getParent() {
		if (eContainerFeatureID() != TypePackage.PACKAGE__PARENT) return null;
		return (de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetParent(de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package newParent, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newParent, TypePackage.PACKAGE__PARENT, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @generated
	 */
	public void setParent(de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package newParent) {
		if (newParent != eInternalContainer() || (eContainerFeatureID() != TypePackage.PACKAGE__PARENT && newParent != null)) {
			if (EcoreUtil.isAncestor(this, newParent))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newParent != null)
				msgs = ((InternalEObject)newParent).eInverseAdd(this, TypePackage.PACKAGE__CHILDREN, de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package.class, msgs);
			msgs = basicSetParent(newParent, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TypePackage.PACKAGE__PARENT, newParent, newParent));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package> getChildren() {
		if (children == null) {
			children = new EObjectContainmentWithInverseEList<de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package>(de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package.class, this, TypePackage.PACKAGE__CHILDREN, TypePackage.PACKAGE__PARENT);
		}
		return children;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Type> getTypes() {
		if (types == null) {
			types = new EObjectContainmentWithInverseEList<Type>(Type.class, this, TypePackage.PACKAGE__TYPES, TypePackage.TYPE__PACKAGE);
		}
		return types;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case TypePackage.PACKAGE__PARENT:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetParent((de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package)otherEnd, msgs);
			case TypePackage.PACKAGE__CHILDREN:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getChildren()).basicAdd(otherEnd, msgs);
			case TypePackage.PACKAGE__TYPES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getTypes()).basicAdd(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 TypePackage.PACKAGE__REFERENCED_TYPES:
				return ((InternalEList<?>)getReferencedTypes()).basicRemove(otherEnd, msgs);
			case TypePackage.PACKAGE__PARENT:
				return basicSetParent(null, msgs);
			case TypePackage.PACKAGE__CHILDREN:
				return ((InternalEList<?>)getChildren()).basicRemove(otherEnd, msgs);
			case TypePackage.PACKAGE__TYPES:
				return ((InternalEList<?>)getTypes()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case TypePackage.PACKAGE__PARENT:
				return eInternalContainer().eInverseRemove(this, TypePackage.PACKAGE__CHILDREN, de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package.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 TypePackage.PACKAGE__REFERENCED_TYPES:
				return getReferencedTypes();
			case TypePackage.PACKAGE__PARENT:
				return getParent();
			case TypePackage.PACKAGE__CHILDREN:
				return getChildren();
			case TypePackage.PACKAGE__TYPES:
				return getTypes();
		}
		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 TypePackage.PACKAGE__REFERENCED_TYPES:
				getReferencedTypes().clear();
				getReferencedTypes().addAll((Collection<? extends Type>)newValue);
				return;
			case TypePackage.PACKAGE__PARENT:
				setParent((de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package)newValue);
				return;
			case TypePackage.PACKAGE__CHILDREN:
				getChildren().clear();
				getChildren().addAll((Collection<? extends de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package>)newValue);
				return;
			case TypePackage.PACKAGE__TYPES:
				getTypes().clear();
				getTypes().addAll((Collection<? extends Type>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case TypePackage.PACKAGE__REFERENCED_TYPES:
				getReferencedTypes().clear();
				return;
			case TypePackage.PACKAGE__PARENT:
				setParent((de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package)null);
				return;
			case TypePackage.PACKAGE__CHILDREN:
				getChildren().clear();
				return;
			case TypePackage.PACKAGE__TYPES:
				getTypes().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case TypePackage.PACKAGE__REFERENCED_TYPES:
				return referencedTypes != null && !referencedTypes.isEmpty();
			case TypePackage.PACKAGE__PARENT:
				return getParent() != null;
			case TypePackage.PACKAGE__CHILDREN:
				return children != null && !children.isEmpty();
			case TypePackage.PACKAGE__TYPES:
				return types != null && !types.isEmpty();
		}
		return super.eIsSet(featureID);
	}


} // PackageImpl
