/*******************************************************************************
 * Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the LGPL 3.0
 * which accompanies this distribution, and is available at
 * https://www.gnu.org/licenses/lgpl-3.0-standalone.html
 *
 * Contributors:
 *     Faiez Zalila - initial API and implementation and/or initial documentation
 *******************************************************************************/
/**
 */
package com.irtsaintexupery.fiacre.instance.fiacreinstance.impl;

import fr.irit.fiacre.xtext.fiacre.ProcessDeclaration;
import fr.irit.fiacre.xtext.fiacre.StateDeclaration;

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.InternalEList;

import com.irtsaintexupery.fiacre.instance.fiacreinstance.FiacreinstancePackage;
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceStatementBlock;
import com.irtsaintexupery.fiacre.instance.fiacreinstance.ProcessDeclarationInstance;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Process Declaration Instance</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.ProcessDeclarationInstanceImpl#getCurrentState <em>Current State</em>}</li>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.ProcessDeclarationInstanceImpl#getProcess <em>Process</em>}</li>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.ProcessDeclarationInstanceImpl#getInstanceStatementBlocks <em>Instance Statement Blocks</em>}</li>
 * </ul>
 *
 * @generated
 */
public class ProcessDeclarationInstanceImpl extends DeclarationInstanceImpl implements ProcessDeclarationInstance {
	/**
	 * The cached value of the '{@link #getCurrentState() <em>Current State</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCurrentState()
	 * @generated
	 * @ordered
	 */
	protected StateDeclaration currentState;

	/**
	 * The cached value of the '{@link #getProcess() <em>Process</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProcess()
	 * @generated
	 * @ordered
	 */
	protected ProcessDeclaration process;

	/**
	 * The cached value of the '{@link #getInstanceStatementBlocks() <em>Instance Statement Blocks</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInstanceStatementBlocks()
	 * @generated
	 * @ordered
	 */
	protected EList<InstanceStatementBlock> instanceStatementBlocks;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public StateDeclaration getCurrentState() {
		if (currentState != null && currentState.eIsProxy()) {
			InternalEObject oldCurrentState = (InternalEObject)currentState;
			currentState = (StateDeclaration)eResolveProxy(oldCurrentState);
			if (currentState != oldCurrentState) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__CURRENT_STATE, oldCurrentState, currentState));
			}
		}
		return currentState;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public StateDeclaration basicGetCurrentState() {
		return currentState;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCurrentState(StateDeclaration newCurrentState) {
		StateDeclaration oldCurrentState = currentState;
		currentState = newCurrentState;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__CURRENT_STATE, oldCurrentState, currentState));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ProcessDeclaration getProcess() {
		if (process != null && process.eIsProxy()) {
			InternalEObject oldProcess = (InternalEObject)process;
			process = (ProcessDeclaration)eResolveProxy(oldProcess);
			if (process != oldProcess) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__PROCESS, oldProcess, process));
			}
		}
		return process;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ProcessDeclaration basicGetProcess() {
		return process;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setProcess(ProcessDeclaration newProcess) {
		ProcessDeclaration oldProcess = process;
		process = newProcess;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__PROCESS, oldProcess, process));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<InstanceStatementBlock> getInstanceStatementBlocks() {
		if (instanceStatementBlocks == null) {
			instanceStatementBlocks = new EObjectContainmentEList<InstanceStatementBlock>(InstanceStatementBlock.class, this, FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__INSTANCE_STATEMENT_BLOCKS);
		}
		return instanceStatementBlocks;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__INSTANCE_STATEMENT_BLOCKS:
				return ((InternalEList<?>)getInstanceStatementBlocks()).basicRemove(otherEnd, 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 FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__CURRENT_STATE:
				if (resolve) return getCurrentState();
				return basicGetCurrentState();
			case FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__PROCESS:
				if (resolve) return getProcess();
				return basicGetProcess();
			case FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__INSTANCE_STATEMENT_BLOCKS:
				return getInstanceStatementBlocks();
		}
		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 FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__CURRENT_STATE:
				setCurrentState((StateDeclaration)newValue);
				return;
			case FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__PROCESS:
				setProcess((ProcessDeclaration)newValue);
				return;
			case FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__INSTANCE_STATEMENT_BLOCKS:
				getInstanceStatementBlocks().clear();
				getInstanceStatementBlocks().addAll((Collection<? extends InstanceStatementBlock>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__CURRENT_STATE:
				setCurrentState((StateDeclaration)null);
				return;
			case FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__PROCESS:
				setProcess((ProcessDeclaration)null);
				return;
			case FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__INSTANCE_STATEMENT_BLOCKS:
				getInstanceStatementBlocks().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__CURRENT_STATE:
				return currentState != null;
			case FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__PROCESS:
				return process != null;
			case FiacreinstancePackage.PROCESS_DECLARATION_INSTANCE__INSTANCE_STATEMENT_BLOCKS:
				return instanceStatementBlocks != null && !instanceStatementBlocks.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //ProcessDeclarationInstanceImpl
