/**
 */
package org.xtext.example.mydsl2.myDsl2.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

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

import org.xtext.example.mydsl2.myDsl2.MyDsl2Package;
import org.xtext.example.mydsl2.myDsl2.Principle;
import org.xtext.example.mydsl2.myDsl2.RoleAssignment;
import org.xtext.example.mydsl2.myDsl2.RoleDefinition;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Role Assignment</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.xtext.example.mydsl2.myDsl2.impl.RoleAssignmentImpl#getName <em>Name</em>}</li>
 *   <li>{@link org.xtext.example.mydsl2.myDsl2.impl.RoleAssignmentImpl#getMember <em>Member</em>}</li>
 *   <li>{@link org.xtext.example.mydsl2.myDsl2.impl.RoleAssignmentImpl#getRoleDefinitionBindings <em>Role Definition Bindings</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RoleAssignmentImpl extends MinimalEObjectImpl.Container implements RoleAssignment
{
  /**
   * 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 #getMember() <em>Member</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMember()
   * @generated
   * @ordered
   */
  protected Principle member;

  /**
   * The cached value of the '{@link #getRoleDefinitionBindings() <em>Role Definition Bindings</em>}' reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getRoleDefinitionBindings()
   * @generated
   * @ordered
   */
  protected EList<RoleDefinition> roleDefinitionBindings;

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

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

  /**
   * <!-- 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, MyDsl2Package.ROLE_ASSIGNMENT__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Principle getMember()
  {
    if (member != null && member.eIsProxy())
    {
      InternalEObject oldMember = (InternalEObject)member;
      member = (Principle)eResolveProxy(oldMember);
      if (member != oldMember)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, MyDsl2Package.ROLE_ASSIGNMENT__MEMBER, oldMember, member));
      }
    }
    return member;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Principle basicGetMember()
  {
    return member;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMember(Principle newMember)
  {
    Principle oldMember = member;
    member = newMember;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, MyDsl2Package.ROLE_ASSIGNMENT__MEMBER, oldMember, member));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<RoleDefinition> getRoleDefinitionBindings()
  {
    if (roleDefinitionBindings == null)
    {
      roleDefinitionBindings = new EObjectResolvingEList<RoleDefinition>(RoleDefinition.class, this, MyDsl2Package.ROLE_ASSIGNMENT__ROLE_DEFINITION_BINDINGS);
    }
    return roleDefinitionBindings;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case MyDsl2Package.ROLE_ASSIGNMENT__NAME:
        return getName();
      case MyDsl2Package.ROLE_ASSIGNMENT__MEMBER:
        if (resolve) return getMember();
        return basicGetMember();
      case MyDsl2Package.ROLE_ASSIGNMENT__ROLE_DEFINITION_BINDINGS:
        return getRoleDefinitionBindings();
    }
    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 MyDsl2Package.ROLE_ASSIGNMENT__NAME:
        setName((String)newValue);
        return;
      case MyDsl2Package.ROLE_ASSIGNMENT__MEMBER:
        setMember((Principle)newValue);
        return;
      case MyDsl2Package.ROLE_ASSIGNMENT__ROLE_DEFINITION_BINDINGS:
        getRoleDefinitionBindings().clear();
        getRoleDefinitionBindings().addAll((Collection<? extends RoleDefinition>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case MyDsl2Package.ROLE_ASSIGNMENT__NAME:
        setName(NAME_EDEFAULT);
        return;
      case MyDsl2Package.ROLE_ASSIGNMENT__MEMBER:
        setMember((Principle)null);
        return;
      case MyDsl2Package.ROLE_ASSIGNMENT__ROLE_DEFINITION_BINDINGS:
        getRoleDefinitionBindings().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case MyDsl2Package.ROLE_ASSIGNMENT__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case MyDsl2Package.ROLE_ASSIGNMENT__MEMBER:
        return member != null;
      case MyDsl2Package.ROLE_ASSIGNMENT__ROLE_DEFINITION_BINDINGS:
        return roleDefinitionBindings != null && !roleDefinitionBindings.isEmpty();
    }
    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();
  }

} //RoleAssignmentImpl
