| 1 | /** |
| 2 | * Copyright 2005-2009 by SDQ, IPD, University of Karlsruhe, Germany |
| 3 | * |
| 4 | * $Id$ |
| 5 | */ |
| 6 | package de.uka.ipd.sdq.pcm.usagemodel.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.usagemodel.Branch; |
| 27 | import de.uka.ipd.sdq.pcm.usagemodel.BranchTransition; |
| 28 | import de.uka.ipd.sdq.pcm.usagemodel.UsagemodelPackage; |
| 29 | import de.uka.ipd.sdq.pcm.usagemodel.util.UsagemodelValidator; |
| 30 | |
| 31 | /** |
| 32 | * <!-- begin-user-doc --> |
| 33 | * An implementation of the model object '<em><b>Branch</b></em>'. |
| 34 | * <!-- end-user-doc --> |
| 35 | * <p> |
| 36 | * The following features are implemented: |
| 37 | * <ul> |
| 38 | * <li>{@link de.uka.ipd.sdq.pcm.usagemodel.impl.BranchImpl#getBranchTransitions_Branch <em>Branch Transitions Branch</em>}</li> |
| 39 | * </ul> |
| 40 | * </p> |
| 41 | * |
| 42 | * @generated |
| 43 | */ |
| 44 | public class BranchImpl extends AbstractUserActionImpl implements Branch { |
| 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 #getBranchTransitions_Branch() <em>Branch Transitions Branch</em>}' containment reference list. |
| 54 | * <!-- begin-user-doc --> |
| 55 | * <!-- end-user-doc --> |
| 56 | * @see #getBranchTransitions_Branch() |
| 57 | * @generated |
| 58 | * @ordered |
| 59 | */ |
| 60 | protected EList<BranchTransition> branchTransitions_Branch; |
| 61 | |
| 62 | /** |
| 63 | * <!-- begin-user-doc --> |
| 64 | * <!-- end-user-doc --> |
| 65 | * @generated |
| 66 | */ |
| 67 | protected BranchImpl() { |
| 68 | super(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * <!-- begin-user-doc --> |
| 73 | * <!-- end-user-doc --> |
| 74 | * @generated |
| 75 | */ |
| 76 | @Override |
| 77 | protected EClass eStaticClass() { |
| 78 | return UsagemodelPackage.Literals.BRANCH; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * <!-- begin-user-doc --> |
| 83 | * <!-- end-user-doc --> |
| 84 | * @generated |
| 85 | */ |
| 86 | public EList<BranchTransition> getBranchTransitions_Branch() { |
| 87 | if (branchTransitions_Branch == null) { |
| 88 | branchTransitions_Branch = new EObjectContainmentWithInverseEList<BranchTransition>(BranchTransition.class, this, UsagemodelPackage.BRANCH__BRANCH_TRANSITIONS_BRANCH, UsagemodelPackage.BRANCH_TRANSITION__BRANCH_BRANCH_TRANSITION); |
| 89 | } |
| 90 | return branchTransitions_Branch; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * The cached OCL expression body for the '{@link #AllBranchProbabilitiesMustSumUpTo1(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) <em>All Branch Probabilities Must Sum Up To1</em>}' operation. |
| 95 | * <!-- begin-user-doc --> |
| 96 | * <!-- end-user-doc --> |
| 97 | * @see #AllBranchProbabilitiesMustSumUpTo1(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) |
| 98 | * @generated |
| 99 | * @ordered |
| 100 | */ |
| 101 | protected static final String ALL_BRANCH_PROBABILITIES_MUST_SUM_UP_TO1__DIAGNOSTIC_CHAIN_MAP__EOCL_EXP = "self->collect(branchTransitions_Branch.branchProbability)->sum() > 0.999 and self->collect(branchTransitions_Branch.branchProbability)->sum() <1.001"; |
| 102 | |
| 103 | /** |
| 104 | * The cached OCL invariant for the '{@link #AllBranchProbabilitiesMustSumUpTo1(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) <em>All Branch Probabilities Must Sum Up To1</em>}' invariant operation. |
| 105 | * <!-- begin-user-doc --> |
| 106 | * <!-- end-user-doc --> |
| 107 | * @see #AllBranchProbabilitiesMustSumUpTo1(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) |
| 108 | * @generated |
| 109 | * @ordered |
| 110 | */ |
| 111 | protected static Constraint ALL_BRANCH_PROBABILITIES_MUST_SUM_UP_TO1__DIAGNOSTIC_CHAIN_MAP__EOCL_INV; |
| 112 | |
| 113 | /** |
| 114 | * <!-- begin-user-doc --> |
| 115 | * <!-- end-user-doc --> |
| 116 | * @generated |
| 117 | */ |
| 118 | public boolean AllBranchProbabilitiesMustSumUpTo1(DiagnosticChain diagnostics, Map<Object, Object> context) { |
| 119 | if (ALL_BRANCH_PROBABILITIES_MUST_SUM_UP_TO1__DIAGNOSTIC_CHAIN_MAP__EOCL_INV == null) { |
| 120 | OCL.Helper helper = EOCL_ENV.createOCLHelper(); |
| 121 | helper.setContext(UsagemodelPackage.Literals.BRANCH); |
| 122 | try { |
| 123 | ALL_BRANCH_PROBABILITIES_MUST_SUM_UP_TO1__DIAGNOSTIC_CHAIN_MAP__EOCL_INV = helper.createInvariant(ALL_BRANCH_PROBABILITIES_MUST_SUM_UP_TO1__DIAGNOSTIC_CHAIN_MAP__EOCL_EXP); |
| 124 | } |
| 125 | catch (ParserException pe) { |
| 126 | throw new UnsupportedOperationException(pe.getLocalizedMessage()); |
| 127 | } |
| 128 | } |
| 129 | if (!EOCL_ENV.createQuery(ALL_BRANCH_PROBABILITIES_MUST_SUM_UP_TO1__DIAGNOSTIC_CHAIN_MAP__EOCL_INV).check(this)) { |
| 130 | if (diagnostics != null) { |
| 131 | diagnostics.add |
| 132 | (new BasicDiagnostic |
| 133 | (Diagnostic.ERROR, |
| 134 | UsagemodelValidator.DIAGNOSTIC_SOURCE, |
| 135 | UsagemodelValidator.BRANCH__ALL_BRANCH_PROBABILITIES_MUST_SUM_UP_TO1, |
| 136 | EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "AllBranchProbabilitiesMustSumUpTo1", EObjectValidator.getObjectLabel(this, context) }), |
| 137 | new Object [] { this })); |
| 138 | } |
| 139 | return false; |
| 140 | } |
| 141 | return true; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * <!-- begin-user-doc --> |
| 146 | * <!-- end-user-doc --> |
| 147 | * @generated |
| 148 | */ |
| 149 | @SuppressWarnings("unchecked") |
| 150 | @Override |
| 151 | public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { |
| 152 | switch (featureID) { |
| 153 | case UsagemodelPackage.BRANCH__BRANCH_TRANSITIONS_BRANCH: |
| 154 | return ((InternalEList<InternalEObject>)(InternalEList<?>)getBranchTransitions_Branch()).basicAdd(otherEnd, msgs); |
| 155 | } |
| 156 | return super.eInverseAdd(otherEnd, featureID, msgs); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * <!-- begin-user-doc --> |
| 161 | * <!-- end-user-doc --> |
| 162 | * @generated |
| 163 | */ |
| 164 | @Override |
| 165 | public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { |
| 166 | switch (featureID) { |
| 167 | case UsagemodelPackage.BRANCH__BRANCH_TRANSITIONS_BRANCH: |
| 168 | return ((InternalEList<?>)getBranchTransitions_Branch()).basicRemove(otherEnd, msgs); |
| 169 | } |
| 170 | return super.eInverseRemove(otherEnd, featureID, msgs); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * <!-- begin-user-doc --> |
| 175 | * <!-- end-user-doc --> |
| 176 | * @generated |
| 177 | */ |
| 178 | @Override |
| 179 | public Object eGet(int featureID, boolean resolve, boolean coreType) { |
| 180 | switch (featureID) { |
| 181 | case UsagemodelPackage.BRANCH__BRANCH_TRANSITIONS_BRANCH: |
| 182 | return getBranchTransitions_Branch(); |
| 183 | } |
| 184 | return super.eGet(featureID, resolve, coreType); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * <!-- begin-user-doc --> |
| 189 | * <!-- end-user-doc --> |
| 190 | * @generated |
| 191 | */ |
| 192 | @SuppressWarnings("unchecked") |
| 193 | @Override |
| 194 | public void eSet(int featureID, Object newValue) { |
| 195 | switch (featureID) { |
| 196 | case UsagemodelPackage.BRANCH__BRANCH_TRANSITIONS_BRANCH: |
| 197 | getBranchTransitions_Branch().clear(); |
| 198 | getBranchTransitions_Branch().addAll((Collection<? extends BranchTransition>)newValue); |
| 199 | return; |
| 200 | } |
| 201 | super.eSet(featureID, newValue); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * <!-- begin-user-doc --> |
| 206 | * <!-- end-user-doc --> |
| 207 | * @generated |
| 208 | */ |
| 209 | @Override |
| 210 | public void eUnset(int featureID) { |
| 211 | switch (featureID) { |
| 212 | case UsagemodelPackage.BRANCH__BRANCH_TRANSITIONS_BRANCH: |
| 213 | getBranchTransitions_Branch().clear(); |
| 214 | return; |
| 215 | } |
| 216 | super.eUnset(featureID); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * <!-- begin-user-doc --> |
| 221 | * <!-- end-user-doc --> |
| 222 | * @generated |
| 223 | */ |
| 224 | @Override |
| 225 | public boolean eIsSet(int featureID) { |
| 226 | switch (featureID) { |
| 227 | case UsagemodelPackage.BRANCH__BRANCH_TRANSITIONS_BRANCH: |
| 228 | return branchTransitions_Branch != null && !branchTransitions_Branch.isEmpty(); |
| 229 | } |
| 230 | return super.eIsSet(featureID); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * The cached environment for evaluating OCL expressions. |
| 235 | * <!-- begin-user-doc --> |
| 236 | * <!-- end-user-doc --> |
| 237 | * @generated |
| 238 | * @ordered |
| 239 | */ |
| 240 | protected static final OCL EOCL_ENV = OCL.newInstance(); |
| 241 | |
| 242 | } //BranchImpl |