| /******************************************************************************* |
| * Copyright (c) 2007, 2010 BMW Car IT, Technische Universitaet Muenchen, and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * BMW Car IT - Initial API and implementation |
| * Technische Universitaet Muenchen - Major refactoring and extension |
| *******************************************************************************/ |
| package org.eclipse.emf.edapt.spi.migration.impl; |
| |
| 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.EObject; |
| import org.eclipse.emf.ecore.InternalEObject; |
| import org.eclipse.emf.ecore.impl.ENotificationImpl; |
| import org.eclipse.emf.ecore.util.EObjectResolvingEList; |
| import org.eclipse.emf.ecore.util.EcoreUtil; |
| import org.eclipse.emf.edapt.spi.migration.Instance; |
| import org.eclipse.emf.edapt.spi.migration.MigrationPackage; |
| import org.eclipse.emf.edapt.spi.migration.Model; |
| import org.eclipse.emf.edapt.spi.migration.ModelResource; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * An implementation of the model object '<em><b>Model Resource</b></em>'. |
| * <!-- end-user-doc --> |
| * <p> |
| * The following features are implemented: |
| * <ul> |
| * <li>{@link org.eclipse.emf.edapt.spi.migration.impl.ModelResourceImpl#getRootInstances <em>Root Instances</em>}</li> |
| * <li>{@link org.eclipse.emf.edapt.spi.migration.impl.ModelResourceImpl#getModel <em>Model</em>}</li> |
| * </ul> |
| * </p> |
| * |
| * @generated |
| */ |
| public class ModelResourceImpl extends AbstractResourceImpl implements ModelResource { |
| /** |
| * The cached value of the '{@link #getRootInstances() <em>Root Instances</em>}' reference list. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @see #getRootInstances() |
| * @generated |
| * @ordered |
| */ |
| protected EList<Instance> rootInstances; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| protected ModelResourceImpl() { |
| super(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| protected EClass eStaticClass() { |
| return MigrationPackage.Literals.MODEL_RESOURCE; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public EList<Instance> getRootInstances() { |
| if (rootInstances == null) { |
| rootInstances = new EObjectResolvingEList<Instance>(Instance.class, this, |
| MigrationPackage.MODEL_RESOURCE__ROOT_INSTANCES); |
| } |
| return rootInstances; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public Model getModel() { |
| if (eContainerFeatureID() != MigrationPackage.MODEL_RESOURCE__MODEL) { |
| return null; |
| } |
| return (Model) eContainer(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| public NotificationChain basicSetModel(Model newModel, NotificationChain msgs) { |
| msgs = eBasicSetContainer((InternalEObject) newModel, MigrationPackage.MODEL_RESOURCE__MODEL, msgs); |
| return msgs; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public void setModel(Model newModel) { |
| if (newModel != eInternalContainer() |
| || eContainerFeatureID() != MigrationPackage.MODEL_RESOURCE__MODEL && newModel != null) { |
| if (EcoreUtil.isAncestor(this, (EObject) newModel)) { |
| throw new IllegalArgumentException("Recursive containment not allowed for " + toString()); //$NON-NLS-1$ |
| } |
| NotificationChain msgs = null; |
| if (eInternalContainer() != null) { |
| msgs = eBasicRemoveFromContainer(msgs); |
| } |
| if (newModel != null) { |
| msgs = ((InternalEObject) newModel).eInverseAdd(this, MigrationPackage.MODEL__RESOURCES, Model.class, |
| msgs); |
| } |
| msgs = basicSetModel(newModel, msgs); |
| if (msgs != null) { |
| msgs.dispatch(); |
| } |
| } |
| else if (eNotificationRequired()) { |
| eNotify(new ENotificationImpl(this, Notification.SET, MigrationPackage.MODEL_RESOURCE__MODEL, newModel, |
| newModel)); |
| } |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { |
| switch (featureID) { |
| case MigrationPackage.MODEL_RESOURCE__MODEL: |
| if (eInternalContainer() != null) { |
| msgs = eBasicRemoveFromContainer(msgs); |
| } |
| return basicSetModel((Model) otherEnd, msgs); |
| } |
| return super.eInverseAdd(otherEnd, featureID, msgs); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { |
| switch (featureID) { |
| case MigrationPackage.MODEL_RESOURCE__MODEL: |
| return basicSetModel(null, msgs); |
| } |
| return super.eInverseRemove(otherEnd, featureID, msgs); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) { |
| switch (eContainerFeatureID()) { |
| case MigrationPackage.MODEL_RESOURCE__MODEL: |
| return eInternalContainer().eInverseRemove(this, MigrationPackage.MODEL__RESOURCES, Model.class, msgs); |
| } |
| return super.eBasicRemoveFromContainerFeature(msgs); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public Object eGet(int featureID, boolean resolve, boolean coreType) { |
| switch (featureID) { |
| case MigrationPackage.MODEL_RESOURCE__ROOT_INSTANCES: |
| return getRootInstances(); |
| case MigrationPackage.MODEL_RESOURCE__MODEL: |
| return getModel(); |
| } |
| 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 MigrationPackage.MODEL_RESOURCE__ROOT_INSTANCES: |
| getRootInstances().clear(); |
| getRootInstances().addAll((Collection<? extends Instance>) newValue); |
| return; |
| case MigrationPackage.MODEL_RESOURCE__MODEL: |
| setModel((Model) newValue); |
| return; |
| } |
| super.eSet(featureID, newValue); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public void eUnset(int featureID) { |
| switch (featureID) { |
| case MigrationPackage.MODEL_RESOURCE__ROOT_INSTANCES: |
| getRootInstances().clear(); |
| return; |
| case MigrationPackage.MODEL_RESOURCE__MODEL: |
| setModel((Model) null); |
| return; |
| } |
| super.eUnset(featureID); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public boolean eIsSet(int featureID) { |
| switch (featureID) { |
| case MigrationPackage.MODEL_RESOURCE__ROOT_INSTANCES: |
| return rootInstances != null && !rootInstances.isEmpty(); |
| case MigrationPackage.MODEL_RESOURCE__MODEL: |
| return getModel() != null; |
| } |
| return super.eIsSet(featureID); |
| } |
| |
| } // ModelResourceImpl |