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