blob: 6b76590113739f885485b3ebed48c9151e4fc4d9 [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: TemplateableElementImpl.java,v 1.16 2006/05/24 20:54:28 khussey Exp $
*/
package org.eclipse.uml2.uml.internal.impl;
import java.util.Collection;
import java.util.Iterator;
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.resource.Resource;
import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.uml2.common.util.CacheAdapter;
import org.eclipse.uml2.common.util.DerivedUnionEObjectEList;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.TemplateBinding;
import org.eclipse.uml2.uml.TemplateSignature;
import org.eclipse.uml2.uml.TemplateableElement;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.internal.operations.TemplateableElementOperations;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Templateable Element</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link org.eclipse.uml2.uml.internal.impl.TemplateableElementImpl#getOwnedElements <em>Owned Element</em>}</li>
* <li>{@link org.eclipse.uml2.uml.internal.impl.TemplateableElementImpl#getTemplateBindings <em>Template Binding</em>}</li>
* <li>{@link org.eclipse.uml2.uml.internal.impl.TemplateableElementImpl#getOwnedTemplateSignature <em>Owned Template Signature</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public abstract class TemplateableElementImpl
extends ElementImpl
implements TemplateableElement {
/**
* The cached value of the '{@link #getTemplateBindings() <em>Template Binding</em>}' containment reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getTemplateBindings()
* @generated
* @ordered
*/
protected EList templateBindings = null;
/**
* The cached value of the '{@link #getOwnedTemplateSignature() <em>Owned Template Signature</em>}' containment reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getOwnedTemplateSignature()
* @generated
* @ordered
*/
protected TemplateSignature ownedTemplateSignature = null;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected TemplateableElementImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected EClass eStaticClass() {
return UMLPackage.Literals.TEMPLATEABLE_ELEMENT;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EList getOwnedElements() {
CacheAdapter cache = getCacheAdapter();
if (cache != null) {
Resource eResource = eResource();
EList ownedElements = (EList) cache.get(eResource, this,
UMLPackage.Literals.ELEMENT__OWNED_ELEMENT);
if (ownedElements == null) {
cache.put(eResource, this,
UMLPackage.Literals.ELEMENT__OWNED_ELEMENT,
ownedElements = new DerivedUnionEObjectEList(Element.class,
this, UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_ELEMENT,
OWNED_ELEMENT_ESUBSETS));
}
return ownedElements;
}
return new DerivedUnionEObjectEList(Element.class, this,
UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_ELEMENT,
OWNED_ELEMENT_ESUBSETS);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EList getTemplateBindings() {
if (templateBindings == null) {
templateBindings = new EObjectContainmentWithInverseEList.Resolving(
TemplateBinding.class, this,
UMLPackage.TEMPLATEABLE_ELEMENT__TEMPLATE_BINDING,
UMLPackage.TEMPLATE_BINDING__BOUND_ELEMENT);
}
return templateBindings;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TemplateBinding createTemplateBinding(TemplateSignature signature) {
TemplateBinding newTemplateBinding = (TemplateBinding) create(UMLPackage.Literals.TEMPLATE_BINDING);
getTemplateBindings().add(newTemplateBinding);
if (signature != null)
newTemplateBinding.setSignature(signature);
return newTemplateBinding;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TemplateBinding getTemplateBinding(TemplateSignature signature) {
return getTemplateBinding(signature, false);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TemplateBinding getTemplateBinding(TemplateSignature signature,
boolean createOnDemand) {
templateBindingLoop : for (Iterator i = getTemplateBindings()
.iterator(); i.hasNext();) {
TemplateBinding templateBinding = (TemplateBinding) i.next();
if (signature != null
&& !signature.equals(templateBinding.getSignature()))
continue templateBindingLoop;
return templateBinding;
}
return createOnDemand
? createTemplateBinding(signature)
: null;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TemplateSignature getOwnedTemplateSignature() {
if (ownedTemplateSignature != null && ownedTemplateSignature.eIsProxy()) {
InternalEObject oldOwnedTemplateSignature = (InternalEObject) ownedTemplateSignature;
ownedTemplateSignature = (TemplateSignature) eResolveProxy(oldOwnedTemplateSignature);
if (ownedTemplateSignature != oldOwnedTemplateSignature) {
InternalEObject newOwnedTemplateSignature = (InternalEObject) ownedTemplateSignature;
NotificationChain msgs = oldOwnedTemplateSignature
.eInverseRemove(this,
UMLPackage.TEMPLATE_SIGNATURE__TEMPLATE,
TemplateSignature.class, null);
if (newOwnedTemplateSignature.eInternalContainer() == null) {
msgs = newOwnedTemplateSignature.eInverseAdd(this,
UMLPackage.TEMPLATE_SIGNATURE__TEMPLATE,
TemplateSignature.class, msgs);
}
if (msgs != null)
msgs.dispatch();
if (eNotificationRequired())
eNotify(new ENotificationImpl(
this,
Notification.RESOLVE,
UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_TEMPLATE_SIGNATURE,
oldOwnedTemplateSignature, ownedTemplateSignature));
}
}
return ownedTemplateSignature;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TemplateSignature basicGetOwnedTemplateSignature() {
return ownedTemplateSignature;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetOwnedTemplateSignature(
TemplateSignature newOwnedTemplateSignature, NotificationChain msgs) {
TemplateSignature oldOwnedTemplateSignature = ownedTemplateSignature;
ownedTemplateSignature = newOwnedTemplateSignature;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this,
Notification.SET,
UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_TEMPLATE_SIGNATURE,
oldOwnedTemplateSignature, newOwnedTemplateSignature);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setOwnedTemplateSignature(
TemplateSignature newOwnedTemplateSignature) {
if (newOwnedTemplateSignature != ownedTemplateSignature) {
NotificationChain msgs = null;
if (ownedTemplateSignature != null)
msgs = ((InternalEObject) ownedTemplateSignature)
.eInverseRemove(this,
UMLPackage.TEMPLATE_SIGNATURE__TEMPLATE,
TemplateSignature.class, msgs);
if (newOwnedTemplateSignature != null)
msgs = ((InternalEObject) newOwnedTemplateSignature)
.eInverseAdd(this, UMLPackage.TEMPLATE_SIGNATURE__TEMPLATE,
TemplateSignature.class, msgs);
msgs = basicSetOwnedTemplateSignature(newOwnedTemplateSignature,
msgs);
if (msgs != null)
msgs.dispatch();
} else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_TEMPLATE_SIGNATURE,
newOwnedTemplateSignature, newOwnedTemplateSignature));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TemplateSignature createOwnedTemplateSignature(EClass eClass) {
TemplateSignature newOwnedTemplateSignature = (TemplateSignature) create(eClass);
setOwnedTemplateSignature(newOwnedTemplateSignature);
return newOwnedTemplateSignature;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TemplateSignature createOwnedTemplateSignature() {
return createOwnedTemplateSignature(UMLPackage.Literals.TEMPLATE_SIGNATURE);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EList parameterableElements() {
CacheAdapter cache = getCacheAdapter();
if (cache != null) {
EList result = (EList) cache.get(this,
UMLPackage.Literals.TEMPLATEABLE_ELEMENT.getEOperations()
.get(0));
if (result == null) {
cache.put(this, UMLPackage.Literals.TEMPLATEABLE_ELEMENT
.getEOperations().get(0),
result = TemplateableElementOperations
.parameterableElements(this));
}
return result;
}
return TemplateableElementOperations.parameterableElements(this);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean isTemplate() {
return TemplateableElementOperations.isTemplate(this);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain eInverseAdd(InternalEObject otherEnd,
int featureID, NotificationChain msgs) {
switch (featureID) {
case UMLPackage.TEMPLATEABLE_ELEMENT__EANNOTATIONS :
return ((InternalEList) getEAnnotations()).basicAdd(otherEnd,
msgs);
case UMLPackage.TEMPLATEABLE_ELEMENT__TEMPLATE_BINDING :
return ((InternalEList) getTemplateBindings()).basicAdd(
otherEnd, msgs);
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_TEMPLATE_SIGNATURE :
if (ownedTemplateSignature != null)
msgs = ((InternalEObject) ownedTemplateSignature)
.eInverseRemove(
this,
EOPPOSITE_FEATURE_BASE
- UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_TEMPLATE_SIGNATURE,
null, msgs);
return basicSetOwnedTemplateSignature(
(TemplateSignature) otherEnd, msgs);
}
return eDynamicInverseAdd(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain eInverseRemove(InternalEObject otherEnd,
int featureID, NotificationChain msgs) {
switch (featureID) {
case UMLPackage.TEMPLATEABLE_ELEMENT__EANNOTATIONS :
return ((InternalEList) getEAnnotations()).basicRemove(
otherEnd, msgs);
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_COMMENT :
return ((InternalEList) getOwnedComments()).basicRemove(
otherEnd, msgs);
case UMLPackage.TEMPLATEABLE_ELEMENT__TEMPLATE_BINDING :
return ((InternalEList) getTemplateBindings()).basicRemove(
otherEnd, msgs);
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_TEMPLATE_SIGNATURE :
return basicSetOwnedTemplateSignature(null, msgs);
}
return eDynamicInverseRemove(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case UMLPackage.TEMPLATEABLE_ELEMENT__EANNOTATIONS :
return getEAnnotations();
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_ELEMENT :
return getOwnedElements();
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNER :
if (resolve)
return getOwner();
return basicGetOwner();
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_COMMENT :
return getOwnedComments();
case UMLPackage.TEMPLATEABLE_ELEMENT__TEMPLATE_BINDING :
return getTemplateBindings();
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_TEMPLATE_SIGNATURE :
if (resolve)
return getOwnedTemplateSignature();
return basicGetOwnedTemplateSignature();
}
return eDynamicGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case UMLPackage.TEMPLATEABLE_ELEMENT__EANNOTATIONS :
getEAnnotations().clear();
getEAnnotations().addAll((Collection) newValue);
return;
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_COMMENT :
getOwnedComments().clear();
getOwnedComments().addAll((Collection) newValue);
return;
case UMLPackage.TEMPLATEABLE_ELEMENT__TEMPLATE_BINDING :
getTemplateBindings().clear();
getTemplateBindings().addAll((Collection) newValue);
return;
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_TEMPLATE_SIGNATURE :
setOwnedTemplateSignature((TemplateSignature) newValue);
return;
}
eDynamicSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void eUnset(int featureID) {
switch (featureID) {
case UMLPackage.TEMPLATEABLE_ELEMENT__EANNOTATIONS :
getEAnnotations().clear();
return;
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_COMMENT :
getOwnedComments().clear();
return;
case UMLPackage.TEMPLATEABLE_ELEMENT__TEMPLATE_BINDING :
getTemplateBindings().clear();
return;
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_TEMPLATE_SIGNATURE :
setOwnedTemplateSignature((TemplateSignature) null);
return;
}
eDynamicUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean eIsSet(int featureID) {
switch (featureID) {
case UMLPackage.TEMPLATEABLE_ELEMENT__EANNOTATIONS :
return eAnnotations != null && !eAnnotations.isEmpty();
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_ELEMENT :
return isSetOwnedElements();
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNER :
return isSetOwner();
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_COMMENT :
return ownedComments != null && !ownedComments.isEmpty();
case UMLPackage.TEMPLATEABLE_ELEMENT__TEMPLATE_BINDING :
return templateBindings != null && !templateBindings.isEmpty();
case UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_TEMPLATE_SIGNATURE :
return ownedTemplateSignature != null;
}
return eDynamicIsSet(featureID);
}
/**
* The array of subset feature identifiers for the '{@link #getOwnedElements() <em>Owned Element</em>}' reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getOwnedElements()
* @generated
* @ordered
*/
protected static final int[] OWNED_ELEMENT_ESUBSETS = new int[]{
UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_COMMENT,
UMLPackage.TEMPLATEABLE_ELEMENT__TEMPLATE_BINDING,
UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_TEMPLATE_SIGNATURE};
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean isSetOwnedElements() {
return super.isSetOwnedElements()
|| eIsSet(UMLPackage.TEMPLATEABLE_ELEMENT__TEMPLATE_BINDING)
|| eIsSet(UMLPackage.TEMPLATEABLE_ELEMENT__OWNED_TEMPLATE_SIGNATURE);
}
} //TemplateableElementImpl