/**
 * generated by Xtext 2.12.0
 */
package com.minres.rdl.rdl.impl;

import com.minres.rdl.rdl.ComponentDefinition;
import com.minres.rdl.rdl.ComponentInstance;
import com.minres.rdl.rdl.NamedInstantiation;
import com.minres.rdl.rdl.RdlPackage;

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>Named Instantiation</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link com.minres.rdl.rdl.impl.NamedInstantiationImpl#isExternal <em>External</em>}</li>
 *   <li>{@link com.minres.rdl.rdl.impl.NamedInstantiationImpl#isInternal <em>Internal</em>}</li>
 *   <li>{@link com.minres.rdl.rdl.impl.NamedInstantiationImpl#getAlias <em>Alias</em>}</li>
 *   <li>{@link com.minres.rdl.rdl.impl.NamedInstantiationImpl#getComponent <em>Component</em>}</li>
 *   <li>{@link com.minres.rdl.rdl.impl.NamedInstantiationImpl#getComponentInstances <em>Component Instances</em>}</li>
 * </ul>
 *
 * @generated
 */
public class NamedInstantiationImpl extends MinimalEObjectImpl.Container implements NamedInstantiation
{
  /**
   * The default value of the '{@link #isExternal() <em>External</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isExternal()
   * @generated
   * @ordered
   */
  protected static final boolean EXTERNAL_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isExternal() <em>External</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isExternal()
   * @generated
   * @ordered
   */
  protected boolean external = EXTERNAL_EDEFAULT;

  /**
   * The default value of the '{@link #isInternal() <em>Internal</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isInternal()
   * @generated
   * @ordered
   */
  protected static final boolean INTERNAL_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isInternal() <em>Internal</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isInternal()
   * @generated
   * @ordered
   */
  protected boolean internal = INTERNAL_EDEFAULT;

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

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

  /**
   * The cached value of the '{@link #getComponent() <em>Component</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getComponent()
   * @generated
   * @ordered
   */
  protected ComponentDefinition component;

  /**
   * The cached value of the '{@link #getComponentInstances() <em>Component Instances</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getComponentInstances()
   * @generated
   * @ordered
   */
  protected EList<ComponentInstance> componentInstances;

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

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

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isExternal()
  {
    return external;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setExternal(boolean newExternal)
  {
    boolean oldExternal = external;
    external = newExternal;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, RdlPackage.NAMED_INSTANTIATION__EXTERNAL, oldExternal, external));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isInternal()
  {
    return internal;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setInternal(boolean newInternal)
  {
    boolean oldInternal = internal;
    internal = newInternal;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, RdlPackage.NAMED_INSTANTIATION__INTERNAL, oldInternal, internal));
  }

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

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setAlias(String newAlias)
  {
    String oldAlias = alias;
    alias = newAlias;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, RdlPackage.NAMED_INSTANTIATION__ALIAS, oldAlias, alias));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ComponentDefinition getComponent()
  {
    if (component != null && component.eIsProxy())
    {
      InternalEObject oldComponent = (InternalEObject)component;
      component = (ComponentDefinition)eResolveProxy(oldComponent);
      if (component != oldComponent)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, RdlPackage.NAMED_INSTANTIATION__COMPONENT, oldComponent, component));
      }
    }
    return component;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ComponentDefinition basicGetComponent()
  {
    return component;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setComponent(ComponentDefinition newComponent)
  {
    ComponentDefinition oldComponent = component;
    component = newComponent;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, RdlPackage.NAMED_INSTANTIATION__COMPONENT, oldComponent, component));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<ComponentInstance> getComponentInstances()
  {
    if (componentInstances == null)
    {
      componentInstances = new EObjectContainmentEList<ComponentInstance>(ComponentInstance.class, this, RdlPackage.NAMED_INSTANTIATION__COMPONENT_INSTANCES);
    }
    return componentInstances;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case RdlPackage.NAMED_INSTANTIATION__COMPONENT_INSTANCES:
        return ((InternalEList<?>)getComponentInstances()).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 RdlPackage.NAMED_INSTANTIATION__EXTERNAL:
        return isExternal();
      case RdlPackage.NAMED_INSTANTIATION__INTERNAL:
        return isInternal();
      case RdlPackage.NAMED_INSTANTIATION__ALIAS:
        return getAlias();
      case RdlPackage.NAMED_INSTANTIATION__COMPONENT:
        if (resolve) return getComponent();
        return basicGetComponent();
      case RdlPackage.NAMED_INSTANTIATION__COMPONENT_INSTANCES:
        return getComponentInstances();
    }
    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 RdlPackage.NAMED_INSTANTIATION__EXTERNAL:
        setExternal((Boolean)newValue);
        return;
      case RdlPackage.NAMED_INSTANTIATION__INTERNAL:
        setInternal((Boolean)newValue);
        return;
      case RdlPackage.NAMED_INSTANTIATION__ALIAS:
        setAlias((String)newValue);
        return;
      case RdlPackage.NAMED_INSTANTIATION__COMPONENT:
        setComponent((ComponentDefinition)newValue);
        return;
      case RdlPackage.NAMED_INSTANTIATION__COMPONENT_INSTANCES:
        getComponentInstances().clear();
        getComponentInstances().addAll((Collection<? extends ComponentInstance>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case RdlPackage.NAMED_INSTANTIATION__EXTERNAL:
        setExternal(EXTERNAL_EDEFAULT);
        return;
      case RdlPackage.NAMED_INSTANTIATION__INTERNAL:
        setInternal(INTERNAL_EDEFAULT);
        return;
      case RdlPackage.NAMED_INSTANTIATION__ALIAS:
        setAlias(ALIAS_EDEFAULT);
        return;
      case RdlPackage.NAMED_INSTANTIATION__COMPONENT:
        setComponent((ComponentDefinition)null);
        return;
      case RdlPackage.NAMED_INSTANTIATION__COMPONENT_INSTANCES:
        getComponentInstances().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case RdlPackage.NAMED_INSTANTIATION__EXTERNAL:
        return external != EXTERNAL_EDEFAULT;
      case RdlPackage.NAMED_INSTANTIATION__INTERNAL:
        return internal != INTERNAL_EDEFAULT;
      case RdlPackage.NAMED_INSTANTIATION__ALIAS:
        return ALIAS_EDEFAULT == null ? alias != null : !ALIAS_EDEFAULT.equals(alias);
      case RdlPackage.NAMED_INSTANTIATION__COMPONENT:
        return component != null;
      case RdlPackage.NAMED_INSTANTIATION__COMPONENT_INSTANCES:
        return componentInstances != null && !componentInstances.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(" (external: ");
    result.append(external);
    result.append(", internal: ");
    result.append(internal);
    result.append(", alias: ");
    result.append(alias);
    result.append(')');
    return result.toString();
  }

} //NamedInstantiationImpl
