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