/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*/
package org.sintef.thingml.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.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.sintef.thingml.Message;
import org.sintef.thingml.Port;
import org.sintef.thingml.Thing;
import org.sintef.thingml.ThingmlPackage;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Port</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* </p>
* <ul>
* <li>{@link org.sintef.thingml.impl.PortImpl#getOwner <em>Owner</em>}</li>
* <li>{@link org.sintef.thingml.impl.PortImpl#getReceives <em>Receives</em>}</li>
* <li>{@link org.sintef.thingml.impl.PortImpl#getSends <em>Sends</em>}</li>
* </ul>
*
* @generated
*/
public abstract class PortImpl extends AnnotatedElementImpl implements Port {
/**
* The cached value of the '{@link #getReceives() <em>Receives</em>}' reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getReceives()
* @generated
* @ordered
*/
protected EList<Message> receives;
/**
* The cached value of the '{@link #getSends() <em>Sends</em>}' reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getSends()
* @generated
* @ordered
*/
protected EList<Message> sends;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected PortImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return ThingmlPackage.Literals.PORT;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Thing getOwner() {
if (eContainerFeatureID() != ThingmlPackage.PORT__OWNER) return null;
return (Thing)eInternalContainer();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetOwner(Thing newOwner, NotificationChain msgs) {
msgs = eBasicSetContainer((InternalEObject)newOwner, ThingmlPackage.PORT__OWNER, msgs);
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setOwner(Thing newOwner) {
if (newOwner != eInternalContainer() || (eContainerFeatureID() != ThingmlPackage.PORT__OWNER && newOwner != null)) {
if (EcoreUtil.isAncestor(this, newOwner))
throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
NotificationChain msgs = null;
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
if (newOwner != null)
msgs = ((InternalEObject)newOwner).eInverseAdd(this, ThingmlPackage.THING__PORTS, Thing.class, msgs);
msgs = basicSetOwner(newOwner, msgs);
if (msgs != null) msgs.dispatch();
}
else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ThingmlPackage.PORT__OWNER, newOwner, newOwner));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EList<Message> getReceives() {
if (receives == null) {
receives = new EObjectResolvingEList<Message>(Message.class, this, ThingmlPackage.PORT__RECEIVES);
}
return receives;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EList<Message> getSends() {
if (sends == null) {
sends = new EObjectResolvingEList<Message>(Message.class, this, ThingmlPackage.PORT__SENDS);
}
return sends;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
switch (featureID) {
case ThingmlPackage.PORT__OWNER:
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
return basicSetOwner((Thing)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 ThingmlPackage.PORT__OWNER:
return basicSetOwner(null, msgs);
}
return super.eInverseRemove(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
switch (eContainerFeatureID()) {
case ThingmlPackage.PORT__OWNER:
return eInternalContainer().eInverseRemove(this, ThingmlPackage.THING__PORTS, Thing.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 ThingmlPackage.PORT__OWNER:
return getOwner();
case ThingmlPackage.PORT__RECEIVES:
return getReceives();
case ThingmlPackage.PORT__SENDS:
return getSends();
}
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 ThingmlPackage.PORT__OWNER:
setOwner((Thing)newValue);
return;
case ThingmlPackage.PORT__RECEIVES:
getReceives().clear();
getReceives().addAll((Collection<? extends Message>)newValue);
return;
case ThingmlPackage.PORT__SENDS:
getSends().clear();
getSends().addAll((Collection<? extends Message>)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case ThingmlPackage.PORT__OWNER:
setOwner((Thing)null);
return;
case ThingmlPackage.PORT__RECEIVES:
getReceives().clear();
return;
case ThingmlPackage.PORT__SENDS:
getSends().clear();
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case ThingmlPackage.PORT__OWNER:
return getOwner() != null;
case ThingmlPackage.PORT__RECEIVES:
return receives != null && !receives.isEmpty();
case ThingmlPackage.PORT__SENDS:
return sends != null && !sends.isEmpty();
}
return super.eIsSet(featureID);
}
} //PortImpl