blob: b1526c298bab28fd4f90984eb37128d37232348d [file] [log] [blame]
/*
* Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - initial API and implementation
*
* $Id: ParameterableElementImpl.java,v 1.13 2006/12/14 15:49:29 khussey Exp $
*/
package org.eclipse.uml2.uml.internal.impl;
import java.util.Collection;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ParameterableElement;
import org.eclipse.uml2.uml.TemplateParameter;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.internal.operations.ParameterableElementOperations;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Parameterable Element</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link org.eclipse.uml2.uml.internal.impl.ParameterableElementImpl#getOwner <em>Owner</em>}</li>
* <li>{@link org.eclipse.uml2.uml.internal.impl.ParameterableElementImpl#getTemplateParameter <em>Template Parameter</em>}</li>
* <li>{@link org.eclipse.uml2.uml.internal.impl.ParameterableElementImpl#getOwningTemplateParameter <em>Owning Template Parameter</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public abstract class ParameterableElementImpl
extends ElementImpl
implements ParameterableElement {
/**
* The cached value of the '{@link #getTemplateParameter() <em>Template Parameter</em>}' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getTemplateParameter()
* @generated
* @ordered
*/
protected TemplateParameter templateParameter = null;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected ParameterableElementImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return UMLPackage.Literals.PARAMETERABLE_ELEMENT;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Element getOwner() {
Element owner = basicGetOwner();
return owner != null && owner.eIsProxy()
? (Element) eResolveProxy((InternalEObject) owner)
: owner;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TemplateParameter getTemplateParameter() {
if (templateParameter != null && templateParameter.eIsProxy()) {
InternalEObject oldTemplateParameter = (InternalEObject) templateParameter;
templateParameter = (TemplateParameter) eResolveProxy(oldTemplateParameter);
if (templateParameter != oldTemplateParameter) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE,
UMLPackage.PARAMETERABLE_ELEMENT__TEMPLATE_PARAMETER,
oldTemplateParameter, templateParameter));
}
}
return templateParameter;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TemplateParameter basicGetTemplateParameter() {
return templateParameter;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetTemplateParameter(
TemplateParameter newTemplateParameter, NotificationChain msgs) {
TemplateParameter oldTemplateParameter = templateParameter;
templateParameter = newTemplateParameter;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this,
Notification.SET,
UMLPackage.PARAMETERABLE_ELEMENT__TEMPLATE_PARAMETER,
oldTemplateParameter, newTemplateParameter);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
Resource.Internal eInternalResource = eInternalResource();
if (eInternalResource == null || !eInternalResource.isLoading()) {
TemplateParameter owningTemplateParameter = basicGetOwningTemplateParameter();
if (owningTemplateParameter != null
&& owningTemplateParameter != newTemplateParameter) {
setOwningTemplateParameter(null);
}
}
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setTemplateParameter(TemplateParameter newTemplateParameter) {
if (newTemplateParameter != templateParameter) {
NotificationChain msgs = null;
if (templateParameter != null)
msgs = ((InternalEObject) templateParameter).eInverseRemove(
this, UMLPackage.TEMPLATE_PARAMETER__PARAMETERED_ELEMENT,
TemplateParameter.class, msgs);
if (newTemplateParameter != null)
msgs = ((InternalEObject) newTemplateParameter).eInverseAdd(
this, UMLPackage.TEMPLATE_PARAMETER__PARAMETERED_ELEMENT,
TemplateParameter.class, msgs);
msgs = basicSetTemplateParameter(newTemplateParameter, msgs);
if (msgs != null)
msgs.dispatch();
} else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
UMLPackage.PARAMETERABLE_ELEMENT__TEMPLATE_PARAMETER,
newTemplateParameter, newTemplateParameter));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TemplateParameter getOwningTemplateParameter() {
if (eContainerFeatureID != UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER)
return null;
return (TemplateParameter) eContainer();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TemplateParameter basicGetOwningTemplateParameter() {
if (eContainerFeatureID != UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER)
return null;
return (TemplateParameter) eInternalContainer();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetOwningTemplateParameter(
TemplateParameter newOwningTemplateParameter, NotificationChain msgs) {
msgs = eBasicSetContainer((InternalEObject) newOwningTemplateParameter,
UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER, msgs);
Resource.Internal eInternalResource = eInternalResource();
if (eInternalResource == null || !eInternalResource.isLoading()) {
if (newOwningTemplateParameter != null) {
if (newOwningTemplateParameter != templateParameter) {
setTemplateParameter(newOwningTemplateParameter);
}
}
}
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setOwningTemplateParameter(
TemplateParameter newOwningTemplateParameter) {
if (newOwningTemplateParameter != eInternalContainer()
|| (eContainerFeatureID != UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER && newOwningTemplateParameter != null)) {
if (EcoreUtil.isAncestor(this, newOwningTemplateParameter))
throw new IllegalArgumentException(
"Recursive containment not allowed for " + toString()); //$NON-NLS-1$
NotificationChain msgs = null;
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
if (newOwningTemplateParameter != null)
msgs = ((InternalEObject) newOwningTemplateParameter)
.eInverseAdd(
this,
UMLPackage.TEMPLATE_PARAMETER__OWNED_PARAMETERED_ELEMENT,
TemplateParameter.class, msgs);
msgs = basicSetOwningTemplateParameter(newOwningTemplateParameter,
msgs);
if (msgs != null)
msgs.dispatch();
} else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER,
newOwningTemplateParameter, newOwningTemplateParameter));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean isCompatibleWith(ParameterableElement p) {
return ParameterableElementOperations.isCompatibleWith(this, p);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean isTemplateParameter() {
return ParameterableElementOperations.isTemplateParameter(this);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@SuppressWarnings("unchecked")
@Override
public NotificationChain eInverseAdd(InternalEObject otherEnd,
int featureID, NotificationChain msgs) {
switch (featureID) {
case UMLPackage.PARAMETERABLE_ELEMENT__EANNOTATIONS :
return ((InternalEList<InternalEObject>) (InternalEList<?>) getEAnnotations())
.basicAdd(otherEnd, msgs);
case UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER :
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
return basicSetOwningTemplateParameter(
(TemplateParameter) otherEnd, msgs);
case UMLPackage.PARAMETERABLE_ELEMENT__TEMPLATE_PARAMETER :
if (templateParameter != null)
msgs = ((InternalEObject) templateParameter)
.eInverseRemove(this,
UMLPackage.TEMPLATE_PARAMETER__PARAMETERED_ELEMENT,
TemplateParameter.class, msgs);
return basicSetTemplateParameter((TemplateParameter) otherEnd,
msgs);
}
return eDynamicInverseAdd(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eInverseRemove(InternalEObject otherEnd,
int featureID, NotificationChain msgs) {
switch (featureID) {
case UMLPackage.PARAMETERABLE_ELEMENT__EANNOTATIONS :
return ((InternalEList<?>) getEAnnotations()).basicRemove(
otherEnd, msgs);
case UMLPackage.PARAMETERABLE_ELEMENT__OWNED_COMMENT :
return ((InternalEList<?>) getOwnedComments()).basicRemove(
otherEnd, msgs);
case UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER :
return basicSetOwningTemplateParameter(null, msgs);
case UMLPackage.PARAMETERABLE_ELEMENT__TEMPLATE_PARAMETER :
return basicSetTemplateParameter(null, msgs);
}
return eDynamicInverseRemove(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eBasicRemoveFromContainerFeature(
NotificationChain msgs) {
switch (eContainerFeatureID) {
case UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER :
return eInternalContainer().eInverseRemove(this,
UMLPackage.TEMPLATE_PARAMETER__OWNED_PARAMETERED_ELEMENT,
TemplateParameter.class, msgs);
}
return eDynamicBasicRemoveFromContainer(msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case UMLPackage.PARAMETERABLE_ELEMENT__EANNOTATIONS :
return getEAnnotations();
case UMLPackage.PARAMETERABLE_ELEMENT__OWNED_ELEMENT :
return getOwnedElements();
case UMLPackage.PARAMETERABLE_ELEMENT__OWNER :
if (resolve)
return getOwner();
return basicGetOwner();
case UMLPackage.PARAMETERABLE_ELEMENT__OWNED_COMMENT :
return getOwnedComments();
case UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER :
if (resolve)
return getOwningTemplateParameter();
return basicGetOwningTemplateParameter();
case UMLPackage.PARAMETERABLE_ELEMENT__TEMPLATE_PARAMETER :
if (resolve)
return getTemplateParameter();
return basicGetTemplateParameter();
}
return eDynamicGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case UMLPackage.PARAMETERABLE_ELEMENT__EANNOTATIONS :
getEAnnotations().clear();
getEAnnotations().addAll(
(Collection<? extends EAnnotation>) newValue);
return;
case UMLPackage.PARAMETERABLE_ELEMENT__OWNED_COMMENT :
getOwnedComments().clear();
getOwnedComments().addAll(
(Collection<? extends Comment>) newValue);
return;
case UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER :
setOwningTemplateParameter((TemplateParameter) newValue);
return;
case UMLPackage.PARAMETERABLE_ELEMENT__TEMPLATE_PARAMETER :
setTemplateParameter((TemplateParameter) newValue);
return;
}
eDynamicSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case UMLPackage.PARAMETERABLE_ELEMENT__EANNOTATIONS :
getEAnnotations().clear();
return;
case UMLPackage.PARAMETERABLE_ELEMENT__OWNED_COMMENT :
getOwnedComments().clear();
return;
case UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER :
setOwningTemplateParameter((TemplateParameter) null);
return;
case UMLPackage.PARAMETERABLE_ELEMENT__TEMPLATE_PARAMETER :
setTemplateParameter((TemplateParameter) null);
return;
}
eDynamicUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case UMLPackage.PARAMETERABLE_ELEMENT__EANNOTATIONS :
return eAnnotations != null && !eAnnotations.isEmpty();
case UMLPackage.PARAMETERABLE_ELEMENT__OWNED_ELEMENT :
return isSetOwnedElements();
case UMLPackage.PARAMETERABLE_ELEMENT__OWNER :
return isSetOwner();
case UMLPackage.PARAMETERABLE_ELEMENT__OWNED_COMMENT :
return ownedComments != null && !ownedComments.isEmpty();
case UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER :
return basicGetOwningTemplateParameter() != null;
case UMLPackage.PARAMETERABLE_ELEMENT__TEMPLATE_PARAMETER :
return templateParameter != null;
}
return eDynamicIsSet(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Element basicGetOwner() {
TemplateParameter owningTemplateParameter = basicGetOwningTemplateParameter();
if (owningTemplateParameter != null) {
return owningTemplateParameter;
}
return super.basicGetOwner();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean isSetOwner() {
return super.isSetOwner()
|| eIsSet(UMLPackage.PARAMETERABLE_ELEMENT__OWNING_TEMPLATE_PARAMETER);
}
} //ParameterableElementImpl