/**
 */
package cz.cuni.mff.d3s.deeco.model.runtime.impl;

import cz.cuni.mff.d3s.deeco.model.runtime.api.SecurityRole;
import cz.cuni.mff.d3s.deeco.model.runtime.api.SecurityRoleArgument;
import cz.cuni.mff.d3s.deeco.model.runtime.meta.RuntimeMetadataPackage;
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.MinimalEObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Security Role</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.SecurityRoleImpl#getConsistsOf <em>Consists Of</em>}</li>
 *   <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.SecurityRoleImpl#getRoleName <em>Role Name</em>}</li>
 *   <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.SecurityRoleImpl#getArguments <em>Arguments</em>}</li>
 *   <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.SecurityRoleImpl#getAliasRole <em>Alias Role</em>}</li>
 * </ul>
 *
 * @generated
 */
public class SecurityRoleImpl extends MinimalEObjectImpl.Container implements SecurityRole {
	/**
	 * The cached value of the '{@link #getConsistsOf() <em>Consists Of</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getConsistsOf()
	 * @generated
	 * @ordered
	 */
	protected EList<SecurityRole> consistsOf;

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

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

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

	/**
	 * The cached value of the '{@link #getAliasRole() <em>Alias Role</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAliasRole()
	 * @generated
	 * @ordered
	 */
	protected SecurityRole aliasRole;

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRoleName(String newRoleName) {
		String oldRoleName = roleName;
		roleName = newRoleName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, RuntimeMetadataPackage.SECURITY_ROLE__ROLE_NAME, oldRoleName, roleName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<SecurityRoleArgument> getArguments() {
		if (arguments == null) {
			arguments = new EObjectContainmentEList<SecurityRoleArgument>(SecurityRoleArgument.class, this, RuntimeMetadataPackage.SECURITY_ROLE__ARGUMENTS);
		}
		return arguments;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public SecurityRole getAliasRole() {
		return aliasRole;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetAliasRole(SecurityRole newAliasRole, NotificationChain msgs) {
		SecurityRole oldAliasRole = aliasRole;
		aliasRole = newAliasRole;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, RuntimeMetadataPackage.SECURITY_ROLE__ALIAS_ROLE, oldAliasRole, newAliasRole);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAliasRole(SecurityRole newAliasRole) {
		if (newAliasRole != aliasRole) {
			NotificationChain msgs = null;
			if (aliasRole != null)
				msgs = ((InternalEObject)aliasRole).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - RuntimeMetadataPackage.SECURITY_ROLE__ALIAS_ROLE, null, msgs);
			if (newAliasRole != null)
				msgs = ((InternalEObject)newAliasRole).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - RuntimeMetadataPackage.SECURITY_ROLE__ALIAS_ROLE, null, msgs);
			msgs = basicSetAliasRole(newAliasRole, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, RuntimeMetadataPackage.SECURITY_ROLE__ALIAS_ROLE, newAliasRole, newAliasRole));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<SecurityRole> getConsistsOf() {
		if (consistsOf == null) {
			consistsOf = new EObjectContainmentEList<SecurityRole>(SecurityRole.class, this, RuntimeMetadataPackage.SECURITY_ROLE__CONSISTS_OF);
		}
		return consistsOf;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case RuntimeMetadataPackage.SECURITY_ROLE__CONSISTS_OF:
				return ((InternalEList<?>)getConsistsOf()).basicRemove(otherEnd, msgs);
			case RuntimeMetadataPackage.SECURITY_ROLE__ARGUMENTS:
				return ((InternalEList<?>)getArguments()).basicRemove(otherEnd, msgs);
			case RuntimeMetadataPackage.SECURITY_ROLE__ALIAS_ROLE:
				return basicSetAliasRole(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 RuntimeMetadataPackage.SECURITY_ROLE__CONSISTS_OF:
				return getConsistsOf();
			case RuntimeMetadataPackage.SECURITY_ROLE__ROLE_NAME:
				return getRoleName();
			case RuntimeMetadataPackage.SECURITY_ROLE__ARGUMENTS:
				return getArguments();
			case RuntimeMetadataPackage.SECURITY_ROLE__ALIAS_ROLE:
				return getAliasRole();
		}
		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 RuntimeMetadataPackage.SECURITY_ROLE__CONSISTS_OF:
				getConsistsOf().clear();
				getConsistsOf().addAll((Collection<? extends SecurityRole>)newValue);
				return;
			case RuntimeMetadataPackage.SECURITY_ROLE__ROLE_NAME:
				setRoleName((String)newValue);
				return;
			case RuntimeMetadataPackage.SECURITY_ROLE__ARGUMENTS:
				getArguments().clear();
				getArguments().addAll((Collection<? extends SecurityRoleArgument>)newValue);
				return;
			case RuntimeMetadataPackage.SECURITY_ROLE__ALIAS_ROLE:
				setAliasRole((SecurityRole)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case RuntimeMetadataPackage.SECURITY_ROLE__CONSISTS_OF:
				getConsistsOf().clear();
				return;
			case RuntimeMetadataPackage.SECURITY_ROLE__ROLE_NAME:
				setRoleName(ROLE_NAME_EDEFAULT);
				return;
			case RuntimeMetadataPackage.SECURITY_ROLE__ARGUMENTS:
				getArguments().clear();
				return;
			case RuntimeMetadataPackage.SECURITY_ROLE__ALIAS_ROLE:
				setAliasRole((SecurityRole)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case RuntimeMetadataPackage.SECURITY_ROLE__CONSISTS_OF:
				return consistsOf != null && !consistsOf.isEmpty();
			case RuntimeMetadataPackage.SECURITY_ROLE__ROLE_NAME:
				return ROLE_NAME_EDEFAULT == null ? roleName != null : !ROLE_NAME_EDEFAULT.equals(roleName);
			case RuntimeMetadataPackage.SECURITY_ROLE__ARGUMENTS:
				return arguments != null && !arguments.isEmpty();
			case RuntimeMetadataPackage.SECURITY_ROLE__ALIAS_ROLE:
				return aliasRole != 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(" (roleName: ");
		result.append(roleName);
		result.append(')');
		return result.toString();
	}

} //SecurityRoleImpl
