| 1 | /** |
| 2 | * <copyright> |
| 3 | * </copyright> |
| 4 | * |
| 5 | * $Id$ |
| 6 | */ |
| 7 | package de.uka.ipd.sdq.featuremodel.impl; |
| 8 | |
| 9 | import java.util.Collection; |
| 10 | import java.util.Map; |
| 11 | |
| 12 | import org.eclipse.emf.common.notify.NotificationChain; |
| 13 | import org.eclipse.emf.common.util.BasicDiagnostic; |
| 14 | import org.eclipse.emf.common.util.Diagnostic; |
| 15 | import org.eclipse.emf.common.util.DiagnosticChain; |
| 16 | import org.eclipse.emf.common.util.EList; |
| 17 | import org.eclipse.emf.ecore.EClass; |
| 18 | import org.eclipse.emf.ecore.InternalEObject; |
| 19 | import org.eclipse.emf.ecore.plugin.EcorePlugin; |
| 20 | import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList; |
| 21 | import org.eclipse.emf.ecore.util.EObjectValidator; |
| 22 | import org.eclipse.emf.ecore.util.InternalEList; |
| 23 | import org.eclipse.ocl.ParserException; |
| 24 | import org.eclipse.ocl.ecore.Constraint; |
| 25 | import org.eclipse.ocl.ecore.OCL; |
| 26 | |
| 27 | import de.uka.ipd.sdq.featuremodel.Feature; |
| 28 | import de.uka.ipd.sdq.featuremodel.Simple; |
| 29 | import de.uka.ipd.sdq.featuremodel.featuremodelPackage; |
| 30 | import de.uka.ipd.sdq.featuremodel.util.featuremodelValidator; |
| 31 | |
| 32 | /** |
| 33 | * <!-- begin-user-doc --> |
| 34 | * An implementation of the model object '<em><b>Simple</b></em>'. |
| 35 | * <!-- end-user-doc --> |
| 36 | * <p> |
| 37 | * The following features are implemented: |
| 38 | * <ul> |
| 39 | * <li>{@link de.uka.ipd.sdq.featuremodel.impl.SimpleImpl#getOptionalChildren <em>Optional Children</em>}</li> |
| 40 | * <li>{@link de.uka.ipd.sdq.featuremodel.impl.SimpleImpl#getMandatoryChildren <em>Mandatory Children</em>}</li> |
| 41 | * </ul> |
| 42 | * </p> |
| 43 | * |
| 44 | * @generated |
| 45 | */ |
| 46 | public class SimpleImpl extends ChildRelationImpl implements Simple { |
| 47 | /** |
| 48 | * The cached value of the '{@link #getOptionalChildren() <em>Optional Children</em>}' containment reference list. |
| 49 | * <!-- begin-user-doc --> |
| 50 | * <!-- end-user-doc --> |
| 51 | * @see #getOptionalChildren() |
| 52 | * @generated |
| 53 | * @ordered |
| 54 | */ |
| 55 | protected EList<Feature> optionalChildren; |
| 56 | /** |
| 57 | * The cached value of the '{@link #getMandatoryChildren() <em>Mandatory Children</em>}' containment reference list. |
| 58 | * <!-- begin-user-doc --> |
| 59 | * <!-- end-user-doc --> |
| 60 | * @see #getMandatoryChildren() |
| 61 | * @generated |
| 62 | * @ordered |
| 63 | */ |
| 64 | protected EList<Feature> mandatoryChildren; |
| 65 | |
| 66 | /** |
| 67 | * <!-- begin-user-doc --> |
| 68 | * <!-- end-user-doc --> |
| 69 | * @generated |
| 70 | */ |
| 71 | protected SimpleImpl() { |
| 72 | super(); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * <!-- begin-user-doc --> |
| 77 | * <!-- end-user-doc --> |
| 78 | * @generated |
| 79 | */ |
| 80 | @Override |
| 81 | protected EClass eStaticClass() { |
| 82 | return featuremodelPackage.Literals.SIMPLE; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * <!-- begin-user-doc --> |
| 87 | * <!-- end-user-doc --> |
| 88 | * @generated |
| 89 | */ |
| 90 | public EList<Feature> getMandatoryChildren() { |
| 91 | if (mandatoryChildren == null) { |
| 92 | mandatoryChildren = new EObjectContainmentWithInverseEList<Feature>(Feature.class, this, featuremodelPackage.SIMPLE__MANDATORY_CHILDREN, featuremodelPackage.FEATURE__SIMPLE_MANDATORY); |
| 93 | } |
| 94 | return mandatoryChildren; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * The cached OCL expression body for the '{@link #atLeastOneChild(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) <em>At Least One Child</em>}' operation. |
| 99 | * <!-- begin-user-doc --> |
| 100 | * <!-- end-user-doc --> |
| 101 | * @see #atLeastOneChild(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) |
| 102 | * @generated |
| 103 | * @ordered |
| 104 | */ |
| 105 | protected static final String AT_LEAST_ONE_CHILD__DIAGNOSTIC_CHAIN_MAP__EOCL_EXP = "self.optionalChildren->size()+self.mandatoryChildren->size()>=1"; |
| 106 | /** |
| 107 | * The cached OCL invariant for the '{@link #atLeastOneChild(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) <em>At Least One Child</em>}' invariant operation. |
| 108 | * <!-- begin-user-doc --> |
| 109 | * <!-- end-user-doc --> |
| 110 | * @see #atLeastOneChild(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) |
| 111 | * @generated |
| 112 | * @ordered |
| 113 | */ |
| 114 | protected static Constraint AT_LEAST_ONE_CHILD__DIAGNOSTIC_CHAIN_MAP__EOCL_INV; |
| 115 | |
| 116 | /** |
| 117 | * <!-- begin-user-doc --> |
| 118 | * <!-- end-user-doc --> |
| 119 | * @generated |
| 120 | */ |
| 121 | public EList<Feature> getOptionalChildren() { |
| 122 | if (optionalChildren == null) { |
| 123 | optionalChildren = new EObjectContainmentWithInverseEList<Feature>(Feature.class, this, featuremodelPackage.SIMPLE__OPTIONAL_CHILDREN, featuremodelPackage.FEATURE__SIMPLE_OPTIONAL); |
| 124 | } |
| 125 | return optionalChildren; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * <!-- begin-user-doc --> |
| 130 | * <!-- end-user-doc --> |
| 131 | * @generated |
| 132 | */ |
| 133 | public boolean atLeastOneChild(DiagnosticChain diagnostics, Map<Object, Object> context) { |
| 134 | if (AT_LEAST_ONE_CHILD__DIAGNOSTIC_CHAIN_MAP__EOCL_INV == null) { |
| 135 | OCL.Helper helper = EOCL_ENV.createOCLHelper(); |
| 136 | helper.setContext(featuremodelPackage.Literals.SIMPLE); |
| 137 | try { |
| 138 | AT_LEAST_ONE_CHILD__DIAGNOSTIC_CHAIN_MAP__EOCL_INV = helper.createInvariant(AT_LEAST_ONE_CHILD__DIAGNOSTIC_CHAIN_MAP__EOCL_EXP); |
| 139 | } |
| 140 | catch (ParserException pe) { |
| 141 | throw new UnsupportedOperationException(pe.getLocalizedMessage()); |
| 142 | } |
| 143 | } |
| 144 | if (!EOCL_ENV.createQuery(AT_LEAST_ONE_CHILD__DIAGNOSTIC_CHAIN_MAP__EOCL_INV).check(this)) { |
| 145 | if (diagnostics != null) { |
| 146 | diagnostics.add |
| 147 | (new BasicDiagnostic |
| 148 | (Diagnostic.ERROR, |
| 149 | featuremodelValidator.DIAGNOSTIC_SOURCE, |
| 150 | featuremodelValidator.SIMPLE__AT_LEAST_ONE_CHILD, |
| 151 | EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "atLeastOneChild", EObjectValidator.getObjectLabel(this, context) }), |
| 152 | new Object [] { this })); |
| 153 | } |
| 154 | return false; |
| 155 | } |
| 156 | return true; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * <!-- begin-user-doc --> |
| 161 | * <!-- end-user-doc --> |
| 162 | * @generated |
| 163 | */ |
| 164 | @SuppressWarnings("unchecked") |
| 165 | @Override |
| 166 | public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { |
| 167 | switch (featureID) { |
| 168 | case featuremodelPackage.SIMPLE__OPTIONAL_CHILDREN: |
| 169 | return ((InternalEList<InternalEObject>)(InternalEList<?>)getOptionalChildren()).basicAdd(otherEnd, msgs); |
| 170 | case featuremodelPackage.SIMPLE__MANDATORY_CHILDREN: |
| 171 | return ((InternalEList<InternalEObject>)(InternalEList<?>)getMandatoryChildren()).basicAdd(otherEnd, msgs); |
| 172 | } |
| 173 | return super.eInverseAdd(otherEnd, featureID, msgs); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * <!-- begin-user-doc --> |
| 178 | * <!-- end-user-doc --> |
| 179 | * @generated |
| 180 | */ |
| 181 | @Override |
| 182 | public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { |
| 183 | switch (featureID) { |
| 184 | case featuremodelPackage.SIMPLE__OPTIONAL_CHILDREN: |
| 185 | return ((InternalEList<?>)getOptionalChildren()).basicRemove(otherEnd, msgs); |
| 186 | case featuremodelPackage.SIMPLE__MANDATORY_CHILDREN: |
| 187 | return ((InternalEList<?>)getMandatoryChildren()).basicRemove(otherEnd, msgs); |
| 188 | } |
| 189 | return super.eInverseRemove(otherEnd, featureID, msgs); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * <!-- begin-user-doc --> |
| 194 | * <!-- end-user-doc --> |
| 195 | * @generated |
| 196 | */ |
| 197 | @Override |
| 198 | public Object eGet(int featureID, boolean resolve, boolean coreType) { |
| 199 | switch (featureID) { |
| 200 | case featuremodelPackage.SIMPLE__OPTIONAL_CHILDREN: |
| 201 | return getOptionalChildren(); |
| 202 | case featuremodelPackage.SIMPLE__MANDATORY_CHILDREN: |
| 203 | return getMandatoryChildren(); |
| 204 | } |
| 205 | return super.eGet(featureID, resolve, coreType); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * <!-- begin-user-doc --> |
| 210 | * <!-- end-user-doc --> |
| 211 | * @generated |
| 212 | */ |
| 213 | @SuppressWarnings("unchecked") |
| 214 | @Override |
| 215 | public void eSet(int featureID, Object newValue) { |
| 216 | switch (featureID) { |
| 217 | case featuremodelPackage.SIMPLE__OPTIONAL_CHILDREN: |
| 218 | getOptionalChildren().clear(); |
| 219 | getOptionalChildren().addAll((Collection<? extends Feature>)newValue); |
| 220 | return; |
| 221 | case featuremodelPackage.SIMPLE__MANDATORY_CHILDREN: |
| 222 | getMandatoryChildren().clear(); |
| 223 | getMandatoryChildren().addAll((Collection<? extends Feature>)newValue); |
| 224 | return; |
| 225 | } |
| 226 | super.eSet(featureID, newValue); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * <!-- begin-user-doc --> |
| 231 | * <!-- end-user-doc --> |
| 232 | * @generated |
| 233 | */ |
| 234 | @Override |
| 235 | public void eUnset(int featureID) { |
| 236 | switch (featureID) { |
| 237 | case featuremodelPackage.SIMPLE__OPTIONAL_CHILDREN: |
| 238 | getOptionalChildren().clear(); |
| 239 | return; |
| 240 | case featuremodelPackage.SIMPLE__MANDATORY_CHILDREN: |
| 241 | getMandatoryChildren().clear(); |
| 242 | return; |
| 243 | } |
| 244 | super.eUnset(featureID); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * <!-- begin-user-doc --> |
| 249 | * <!-- end-user-doc --> |
| 250 | * @generated |
| 251 | */ |
| 252 | @Override |
| 253 | public boolean eIsSet(int featureID) { |
| 254 | switch (featureID) { |
| 255 | case featuremodelPackage.SIMPLE__OPTIONAL_CHILDREN: |
| 256 | return optionalChildren != null && !optionalChildren.isEmpty(); |
| 257 | case featuremodelPackage.SIMPLE__MANDATORY_CHILDREN: |
| 258 | return mandatoryChildren != null && !mandatoryChildren.isEmpty(); |
| 259 | } |
| 260 | return super.eIsSet(featureID); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * The cached environment for evaluating OCL expressions. |
| 265 | * <!-- begin-user-doc --> |
| 266 | * <!-- end-user-doc --> |
| 267 | * @generated |
| 268 | * @ordered |
| 269 | */ |
| 270 | protected static final OCL EOCL_ENV = OCL.newInstance(); |
| 271 | |
| 272 | } //SimpleImpl |