blob: 8885f244813138e73c4a9d08a5fbb82d327332e8 [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: ConstraintImpl.java,v 1.19 2006/11/14 18:02:19 khussey Exp $
*/
package org.eclipse.uml2.uml.internal.impl;
import java.util.Collection;
import java.util.Map;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.DiagnosticChain;
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.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
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.Constraint;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.StringExpression;
import org.eclipse.uml2.uml.TemplateParameter;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.ValueSpecification;
import org.eclipse.uml2.uml.VisibilityKind;
import org.eclipse.uml2.uml.internal.operations.ConstraintOperations;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Constraint</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link org.eclipse.uml2.uml.internal.impl.ConstraintImpl#getOwnedElements <em>Owned Element</em>}</li>
* <li>{@link org.eclipse.uml2.uml.internal.impl.ConstraintImpl#getNamespace <em>Namespace</em>}</li>
* <li>{@link org.eclipse.uml2.uml.internal.impl.ConstraintImpl#getConstrainedElements <em>Constrained Element</em>}</li>
* <li>{@link org.eclipse.uml2.uml.internal.impl.ConstraintImpl#getSpecification <em>Specification</em>}</li>
* <li>{@link org.eclipse.uml2.uml.internal.impl.ConstraintImpl#getContext <em>Context</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class ConstraintImpl
extends PackageableElementImpl
implements Constraint {
/**
* The cached value of the '{@link #getConstrainedElements() <em>Constrained Element</em>}' reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getConstrainedElements()
* @generated
* @ordered
*/
protected EList constrainedElements = null;
/**
* The cached value of the '{@link #getSpecification() <em>Specification</em>}' containment reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getSpecification()
* @generated
* @ordered
*/
protected ValueSpecification specification = null;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected ConstraintImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected EClass eStaticClass() {
return UMLPackage.Literals.CONSTRAINT;
}
/**
* <!-- 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.CONSTRAINT__OWNED_ELEMENT,
OWNED_ELEMENT_ESUBSETS));
}
return ownedElements;
}
return new DerivedUnionEObjectEList(Element.class, this,
UMLPackage.CONSTRAINT__OWNED_ELEMENT, OWNED_ELEMENT_ESUBSETS);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EList getConstrainedElements() {
if (constrainedElements == null) {
constrainedElements = new EObjectResolvingEList(Element.class,
this, UMLPackage.CONSTRAINT__CONSTRAINED_ELEMENT);
}
return constrainedElements;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public ValueSpecification getSpecification() {
if (specification != null && specification.eIsProxy()) {
InternalEObject oldSpecification = (InternalEObject) specification;
specification = (ValueSpecification) eResolveProxy(oldSpecification);
if (specification != oldSpecification) {
InternalEObject newSpecification = (InternalEObject) specification;
NotificationChain msgs = oldSpecification.eInverseRemove(this,
EOPPOSITE_FEATURE_BASE
- UMLPackage.CONSTRAINT__SPECIFICATION, null, null);
if (newSpecification.eInternalContainer() == null) {
msgs = newSpecification.eInverseAdd(this,
EOPPOSITE_FEATURE_BASE
- UMLPackage.CONSTRAINT__SPECIFICATION, null, msgs);
}
if (msgs != null)
msgs.dispatch();
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE,
UMLPackage.CONSTRAINT__SPECIFICATION, oldSpecification,
specification));
}
}
return specification;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public ValueSpecification basicGetSpecification() {
return specification;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetSpecification(
ValueSpecification newSpecification, NotificationChain msgs) {
ValueSpecification oldSpecification = specification;
specification = newSpecification;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this,
Notification.SET, UMLPackage.CONSTRAINT__SPECIFICATION,
oldSpecification, newSpecification);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setSpecification(ValueSpecification newSpecification) {
if (newSpecification != specification) {
NotificationChain msgs = null;
if (specification != null)
msgs = ((InternalEObject) specification).eInverseRemove(this,
EOPPOSITE_FEATURE_BASE
- UMLPackage.CONSTRAINT__SPECIFICATION, null, msgs);
if (newSpecification != null)
msgs = ((InternalEObject) newSpecification).eInverseAdd(this,
EOPPOSITE_FEATURE_BASE
- UMLPackage.CONSTRAINT__SPECIFICATION, null, msgs);
msgs = basicSetSpecification(newSpecification, msgs);
if (msgs != null)
msgs.dispatch();
} else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
UMLPackage.CONSTRAINT__SPECIFICATION, newSpecification,
newSpecification));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public ValueSpecification createSpecification(String name, Type type,
EClass eClass) {
ValueSpecification newSpecification = (ValueSpecification) create(eClass);
setSpecification(newSpecification);
if (name != null)
newSpecification.setName(name);
if (type != null)
newSpecification.setType(type);
return newSpecification;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Namespace getContext() {
if (eContainerFeatureID != UMLPackage.CONSTRAINT__CONTEXT)
return null;
return (Namespace) eContainer();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Namespace basicGetContext() {
if (eContainerFeatureID != UMLPackage.CONSTRAINT__CONTEXT)
return null;
return (Namespace) eInternalContainer();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetContext(Namespace newContext,
NotificationChain msgs) {
msgs = eBasicSetContainer((InternalEObject) newContext,
UMLPackage.CONSTRAINT__CONTEXT, msgs);
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setContext(Namespace newContext) {
if (newContext != eInternalContainer()
|| (eContainerFeatureID != UMLPackage.CONSTRAINT__CONTEXT && newContext != null)) {
if (EcoreUtil.isAncestor(this, newContext))
throw new IllegalArgumentException(
"Recursive containment not allowed for " + toString()); //$NON-NLS-1$
NotificationChain msgs = null;
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
if (newContext != null)
msgs = ((InternalEObject) newContext).eInverseAdd(this,
UMLPackage.NAMESPACE__OWNED_RULE, Namespace.class, msgs);
msgs = basicSetContext(newContext, msgs);
if (msgs != null)
msgs.dispatch();
} else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
UMLPackage.CONSTRAINT__CONTEXT, newContext, newContext));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean validateNotApplyToSelf(DiagnosticChain diagnostics,
Map context) {
return ConstraintOperations.validateNotApplyToSelf(this, diagnostics,
context);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean validateValueSpecificationBoolean(
DiagnosticChain diagnostics, Map context) {
return ConstraintOperations.validateValueSpecificationBoolean(this,
diagnostics, context);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean validateBooleanValue(DiagnosticChain diagnostics, Map context) {
return ConstraintOperations.validateBooleanValue(this, diagnostics,
context);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean validateNoSideEffects(DiagnosticChain diagnostics,
Map context) {
return ConstraintOperations.validateNoSideEffects(this, diagnostics,
context);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean validateNotAppliedToSelf(DiagnosticChain diagnostics,
Map context) {
return ConstraintOperations.validateNotAppliedToSelf(this, diagnostics,
context);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain eInverseAdd(InternalEObject otherEnd,
int featureID, NotificationChain msgs) {
switch (featureID) {
case UMLPackage.CONSTRAINT__EANNOTATIONS :
return ((InternalEList) getEAnnotations()).basicAdd(otherEnd,
msgs);
case UMLPackage.CONSTRAINT__CLIENT_DEPENDENCY :
return ((InternalEList) getClientDependencies()).basicAdd(
otherEnd, msgs);
case UMLPackage.CONSTRAINT__OWNING_TEMPLATE_PARAMETER :
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
return basicSetOwningTemplateParameter(
(TemplateParameter) otherEnd, msgs);
case UMLPackage.CONSTRAINT__TEMPLATE_PARAMETER :
if (templateParameter != null)
msgs = ((InternalEObject) templateParameter)
.eInverseRemove(this,
UMLPackage.TEMPLATE_PARAMETER__PARAMETERED_ELEMENT,
TemplateParameter.class, msgs);
return basicSetTemplateParameter((TemplateParameter) otherEnd,
msgs);
case UMLPackage.CONSTRAINT__CONTEXT :
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
return basicSetContext((Namespace) 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.CONSTRAINT__EANNOTATIONS :
return ((InternalEList) getEAnnotations()).basicRemove(
otherEnd, msgs);
case UMLPackage.CONSTRAINT__OWNED_COMMENT :
return ((InternalEList) getOwnedComments()).basicRemove(
otherEnd, msgs);
case UMLPackage.CONSTRAINT__CLIENT_DEPENDENCY :
return ((InternalEList) getClientDependencies()).basicRemove(
otherEnd, msgs);
case UMLPackage.CONSTRAINT__NAME_EXPRESSION :
return basicSetNameExpression(null, msgs);
case UMLPackage.CONSTRAINT__OWNING_TEMPLATE_PARAMETER :
return basicSetOwningTemplateParameter(null, msgs);
case UMLPackage.CONSTRAINT__TEMPLATE_PARAMETER :
return basicSetTemplateParameter(null, msgs);
case UMLPackage.CONSTRAINT__SPECIFICATION :
return basicSetSpecification(null, msgs);
case UMLPackage.CONSTRAINT__CONTEXT :
return basicSetContext(null, msgs);
}
return eDynamicInverseRemove(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain eBasicRemoveFromContainerFeature(
NotificationChain msgs) {
switch (eContainerFeatureID) {
case UMLPackage.CONSTRAINT__OWNING_TEMPLATE_PARAMETER :
return eInternalContainer().eInverseRemove(this,
UMLPackage.TEMPLATE_PARAMETER__OWNED_PARAMETERED_ELEMENT,
TemplateParameter.class, msgs);
case UMLPackage.CONSTRAINT__CONTEXT :
return eInternalContainer().eInverseRemove(this,
UMLPackage.NAMESPACE__OWNED_RULE, Namespace.class, msgs);
}
return eDynamicBasicRemoveFromContainer(msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case UMLPackage.CONSTRAINT__EANNOTATIONS :
return getEAnnotations();
case UMLPackage.CONSTRAINT__OWNED_ELEMENT :
return getOwnedElements();
case UMLPackage.CONSTRAINT__OWNER :
if (resolve)
return getOwner();
return basicGetOwner();
case UMLPackage.CONSTRAINT__OWNED_COMMENT :
return getOwnedComments();
case UMLPackage.CONSTRAINT__NAME :
return getName();
case UMLPackage.CONSTRAINT__VISIBILITY :
return getVisibility();
case UMLPackage.CONSTRAINT__QUALIFIED_NAME :
return getQualifiedName();
case UMLPackage.CONSTRAINT__CLIENT_DEPENDENCY :
return getClientDependencies();
case UMLPackage.CONSTRAINT__NAMESPACE :
if (resolve)
return getNamespace();
return basicGetNamespace();
case UMLPackage.CONSTRAINT__NAME_EXPRESSION :
if (resolve)
return getNameExpression();
return basicGetNameExpression();
case UMLPackage.CONSTRAINT__OWNING_TEMPLATE_PARAMETER :
if (resolve)
return getOwningTemplateParameter();
return basicGetOwningTemplateParameter();
case UMLPackage.CONSTRAINT__TEMPLATE_PARAMETER :
if (resolve)
return getTemplateParameter();
return basicGetTemplateParameter();
case UMLPackage.CONSTRAINT__CONSTRAINED_ELEMENT :
return getConstrainedElements();
case UMLPackage.CONSTRAINT__SPECIFICATION :
if (resolve)
return getSpecification();
return basicGetSpecification();
case UMLPackage.CONSTRAINT__CONTEXT :
if (resolve)
return getContext();
return basicGetContext();
}
return eDynamicGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case UMLPackage.CONSTRAINT__EANNOTATIONS :
getEAnnotations().clear();
getEAnnotations().addAll((Collection) newValue);
return;
case UMLPackage.CONSTRAINT__OWNED_COMMENT :
getOwnedComments().clear();
getOwnedComments().addAll((Collection) newValue);
return;
case UMLPackage.CONSTRAINT__NAME :
setName((String) newValue);
return;
case UMLPackage.CONSTRAINT__VISIBILITY :
setVisibility((VisibilityKind) newValue);
return;
case UMLPackage.CONSTRAINT__CLIENT_DEPENDENCY :
getClientDependencies().clear();
getClientDependencies().addAll((Collection) newValue);
return;
case UMLPackage.CONSTRAINT__NAME_EXPRESSION :
setNameExpression((StringExpression) newValue);
return;
case UMLPackage.CONSTRAINT__OWNING_TEMPLATE_PARAMETER :
setOwningTemplateParameter((TemplateParameter) newValue);
return;
case UMLPackage.CONSTRAINT__TEMPLATE_PARAMETER :
setTemplateParameter((TemplateParameter) newValue);
return;
case UMLPackage.CONSTRAINT__CONSTRAINED_ELEMENT :
getConstrainedElements().clear();
getConstrainedElements().addAll((Collection) newValue);
return;
case UMLPackage.CONSTRAINT__SPECIFICATION :
setSpecification((ValueSpecification) newValue);
return;
case UMLPackage.CONSTRAINT__CONTEXT :
setContext((Namespace) newValue);
return;
}
eDynamicSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void eUnset(int featureID) {
switch (featureID) {
case UMLPackage.CONSTRAINT__EANNOTATIONS :
getEAnnotations().clear();
return;
case UMLPackage.CONSTRAINT__OWNED_COMMENT :
getOwnedComments().clear();
return;
case UMLPackage.CONSTRAINT__NAME :
unsetName();
return;
case UMLPackage.CONSTRAINT__VISIBILITY :
unsetVisibility();
return;
case UMLPackage.CONSTRAINT__CLIENT_DEPENDENCY :
getClientDependencies().clear();
return;
case UMLPackage.CONSTRAINT__NAME_EXPRESSION :
setNameExpression((StringExpression) null);
return;
case UMLPackage.CONSTRAINT__OWNING_TEMPLATE_PARAMETER :
setOwningTemplateParameter((TemplateParameter) null);
return;
case UMLPackage.CONSTRAINT__TEMPLATE_PARAMETER :
setTemplateParameter((TemplateParameter) null);
return;
case UMLPackage.CONSTRAINT__CONSTRAINED_ELEMENT :
getConstrainedElements().clear();
return;
case UMLPackage.CONSTRAINT__SPECIFICATION :
setSpecification((ValueSpecification) null);
return;
case UMLPackage.CONSTRAINT__CONTEXT :
setContext((Namespace) null);
return;
}
eDynamicUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean eIsSet(int featureID) {
switch (featureID) {
case UMLPackage.CONSTRAINT__EANNOTATIONS :
return eAnnotations != null && !eAnnotations.isEmpty();
case UMLPackage.CONSTRAINT__OWNED_ELEMENT :
return isSetOwnedElements();
case UMLPackage.CONSTRAINT__OWNER :
return isSetOwner();
case UMLPackage.CONSTRAINT__OWNED_COMMENT :
return ownedComments != null && !ownedComments.isEmpty();
case UMLPackage.CONSTRAINT__NAME :
return isSetName();
case UMLPackage.CONSTRAINT__VISIBILITY :
return isSetVisibility();
case UMLPackage.CONSTRAINT__QUALIFIED_NAME :
return QUALIFIED_NAME_EDEFAULT == null
? getQualifiedName() != null
: !QUALIFIED_NAME_EDEFAULT.equals(getQualifiedName());
case UMLPackage.CONSTRAINT__CLIENT_DEPENDENCY :
return clientDependencies != null
&& !clientDependencies.isEmpty();
case UMLPackage.CONSTRAINT__NAMESPACE :
return isSetNamespace();
case UMLPackage.CONSTRAINT__NAME_EXPRESSION :
return nameExpression != null;
case UMLPackage.CONSTRAINT__OWNING_TEMPLATE_PARAMETER :
return basicGetOwningTemplateParameter() != null;
case UMLPackage.CONSTRAINT__TEMPLATE_PARAMETER :
return templateParameter != null;
case UMLPackage.CONSTRAINT__CONSTRAINED_ELEMENT :
return constrainedElements != null
&& !constrainedElements.isEmpty();
case UMLPackage.CONSTRAINT__SPECIFICATION :
return specification != null;
case UMLPackage.CONSTRAINT__CONTEXT :
return basicGetContext() != 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.CONSTRAINT__OWNED_COMMENT,
UMLPackage.CONSTRAINT__NAME_EXPRESSION,
UMLPackage.CONSTRAINT__SPECIFICATION};
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Namespace getNamespace() {
Namespace namespace = basicGetNamespace();
return namespace != null && namespace.eIsProxy()
? (Namespace) eResolveProxy((InternalEObject) namespace)
: namespace;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean isSetOwnedElements() {
return super.isSetOwnedElements()
|| eIsSet(UMLPackage.CONSTRAINT__SPECIFICATION);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Namespace basicGetNamespace() {
Namespace context = basicGetContext();
if (context != null) {
return context;
}
return super.basicGetNamespace();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean isSetNamespace() {
return super.isSetNamespace() || eIsSet(UMLPackage.CONSTRAINT__CONTEXT);
}
} //ConstraintImpl