/*
 * This file has been developed at the University of Munich, Chair for Programming & Software Engineering.
 * 
 * This file is licensed under the Eclipse Public License (EPL) 1.0
 * 
 */
package eu.mdd4soa.smm.behaviour.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 eu.mdd4soa.smm.behaviour.ISMBehaviourPackage;
import eu.mdd4soa.smm.behaviour.Loop;
import eu.mdd4soa.smm.data.Expression;

/**
 * <!-- begin-user-doc --> An implementation of the model object '
 * <em><b>Loop</b></em>'. <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 * <li>{@link eu.mdd4soa.smm.behaviour.impl.LoopImpl#getLeaveCondition <em>Leave
 * Condition</em>}</li>
 * </ul>
 * </p>
 * 
 * @generated
 */
public class LoopImpl extends PathBasedPartitionImpl implements Loop {
	/**
	 * The cached value of the '{@link #getLeaveCondition()
	 * <em>Leave Condition</em>}' containment reference. <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * 
	 * @see #getLeaveCondition()
	 * @generated
	 * @ordered
	 */
	protected Expression leaveCondition;

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

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

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public Expression getLeaveCondition() {
		return leaveCondition;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public NotificationChain basicSetLeaveCondition(Expression newLeaveCondition, NotificationChain msgs) {
		Expression oldLeaveCondition= leaveCondition;
		leaveCondition= newLeaveCondition;
		if (eNotificationRequired()) {
			ENotificationImpl notification= new ENotificationImpl(this, Notification.SET, ISMBehaviourPackage.LOOP__LEAVE_CONDITION,
					oldLeaveCondition, newLeaveCondition);
			if (msgs == null)
				msgs= notification;
			else
				msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public void setLeaveCondition(Expression newLeaveCondition) {
		if (newLeaveCondition != leaveCondition) {
			NotificationChain msgs= null;
			if (leaveCondition != null)
				msgs= ((InternalEObject) leaveCondition).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ISMBehaviourPackage.LOOP__LEAVE_CONDITION,
						null, msgs);
			if (newLeaveCondition != null)
				msgs= ((InternalEObject) newLeaveCondition).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ISMBehaviourPackage.LOOP__LEAVE_CONDITION,
						null, msgs);
			msgs= basicSetLeaveCondition(newLeaveCondition, msgs);
			if (msgs != null)
				msgs.dispatch();
		} else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ISMBehaviourPackage.LOOP__LEAVE_CONDITION, newLeaveCondition, newLeaveCondition));
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ISMBehaviourPackage.LOOP__LEAVE_CONDITION:
				return basicSetLeaveCondition(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 ISMBehaviourPackage.LOOP__LEAVE_CONDITION:
				return getLeaveCondition();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ISMBehaviourPackage.LOOP__LEAVE_CONDITION:
				setLeaveCondition((Expression) newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ISMBehaviourPackage.LOOP__LEAVE_CONDITION:
				setLeaveCondition((Expression) null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ISMBehaviourPackage.LOOP__LEAVE_CONDITION:
				return leaveCondition != null;
		}
		return super.eIsSet(featureID);
	}

} // LoopImpl
