/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package de.lmu.ifi.pst.mdd4soa.transform.impl.iom.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.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import de.lmu.ifi.pst.mdd4soa.transform.impl.iom.IOMPackage;
import de.lmu.ifi.pst.mdd4soa.transform.impl.iom.Participant;
import de.lmu.ifi.pst.mdd4soa.transform.impl.iom.PartnerPoint;
import de.lmu.ifi.pst.mdd4soa.transform.impl.iom.ServiceActivity;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Participant</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link de.lmu.ifi.pst.mdd4soa.transform.impl.iom.impl.ParticipantImpl#getPartners <em>Partners</em>}</li>
 *   <li>{@link de.lmu.ifi.pst.mdd4soa.transform.impl.iom.impl.ParticipantImpl#getBehaviours <em>Behaviours</em>}</li>
 *   <li>{@link de.lmu.ifi.pst.mdd4soa.transform.impl.iom.impl.ParticipantImpl#getName <em>Name</em>}</li>
 *   <li>{@link de.lmu.ifi.pst.mdd4soa.transform.impl.iom.impl.ParticipantImpl#getRootPackage <em>Root Package</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ParticipantImpl extends EObjectImpl implements Participant {
	/**
	 * The cached value of the '{@link #getPartners() <em>Partners</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPartners()
	 * @generated
	 * @ordered
	 */
	protected EList<PartnerPoint> partners;

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

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

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getRootPackage() <em>Root Package</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRootPackage()
	 * @generated
	 * @ordered
	 */
	protected de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package rootPackage;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PartnerPoint> getPartners() {
		if (partners == null) {
			partners = new EObjectContainmentEList<PartnerPoint>(PartnerPoint.class, this, IOMPackage.PARTICIPANT__PARTNERS);
		}
		return partners;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ServiceActivity> getBehaviours() {
		if (behaviours == null) {
			behaviours = new EObjectContainmentEList<ServiceActivity>(ServiceActivity.class, this, IOMPackage.PARTICIPANT__BEHAVIOURS);
		}
		return behaviours;
	}

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, IOMPackage.PARTICIPANT__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package getRootPackage() {
		return rootPackage;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetRootPackage(de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package newRootPackage, NotificationChain msgs) {
		de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package oldRootPackage = rootPackage;
		rootPackage = newRootPackage;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, IOMPackage.PARTICIPANT__ROOT_PACKAGE, oldRootPackage, newRootPackage);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRootPackage(de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package newRootPackage) {
		if (newRootPackage != rootPackage) {
			NotificationChain msgs = null;
			if (rootPackage != null)
				msgs = ((InternalEObject)rootPackage).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - IOMPackage.PARTICIPANT__ROOT_PACKAGE, null, msgs);
			if (newRootPackage != null)
				msgs = ((InternalEObject)newRootPackage).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - IOMPackage.PARTICIPANT__ROOT_PACKAGE, null, msgs);
			msgs = basicSetRootPackage(newRootPackage, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, IOMPackage.PARTICIPANT__ROOT_PACKAGE, newRootPackage, newRootPackage));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case IOMPackage.PARTICIPANT__PARTNERS:
				return ((InternalEList<?>)getPartners()).basicRemove(otherEnd, msgs);
			case IOMPackage.PARTICIPANT__BEHAVIOURS:
				return ((InternalEList<?>)getBehaviours()).basicRemove(otherEnd, msgs);
			case IOMPackage.PARTICIPANT__ROOT_PACKAGE:
				return basicSetRootPackage(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 IOMPackage.PARTICIPANT__PARTNERS:
				return getPartners();
			case IOMPackage.PARTICIPANT__BEHAVIOURS:
				return getBehaviours();
			case IOMPackage.PARTICIPANT__NAME:
				return getName();
			case IOMPackage.PARTICIPANT__ROOT_PACKAGE:
				return getRootPackage();
		}
		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 IOMPackage.PARTICIPANT__PARTNERS:
				getPartners().clear();
				getPartners().addAll((Collection<? extends PartnerPoint>)newValue);
				return;
			case IOMPackage.PARTICIPANT__BEHAVIOURS:
				getBehaviours().clear();
				getBehaviours().addAll((Collection<? extends ServiceActivity>)newValue);
				return;
			case IOMPackage.PARTICIPANT__NAME:
				setName((String)newValue);
				return;
			case IOMPackage.PARTICIPANT__ROOT_PACKAGE:
				setRootPackage((de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case IOMPackage.PARTICIPANT__PARTNERS:
				getPartners().clear();
				return;
			case IOMPackage.PARTICIPANT__BEHAVIOURS:
				getBehaviours().clear();
				return;
			case IOMPackage.PARTICIPANT__NAME:
				setName(NAME_EDEFAULT);
				return;
			case IOMPackage.PARTICIPANT__ROOT_PACKAGE:
				setRootPackage((de.lmu.ifi.pst.mdd4soa.transform.impl.iom.type.Package)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case IOMPackage.PARTICIPANT__PARTNERS:
				return partners != null && !partners.isEmpty();
			case IOMPackage.PARTICIPANT__BEHAVIOURS:
				return behaviours != null && !behaviours.isEmpty();
			case IOMPackage.PARTICIPANT__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case IOMPackage.PARTICIPANT__ROOT_PACKAGE:
				return rootPackage != null;
		}
		return super.eIsSet(featureID);
	}

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

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //ParticipantImpl
