| 1 | /** |
| 2 | * <copyright> |
| 3 | * </copyright> |
| 4 | * |
| 5 | * $Id$ |
| 6 | */ |
| 7 | package de.uka.ipd.sdq.featureconfig.impl; |
| 8 | |
| 9 | import org.eclipse.emf.common.notify.Notification; |
| 10 | import org.eclipse.emf.common.notify.NotificationChain; |
| 11 | import org.eclipse.emf.ecore.EClass; |
| 12 | import org.eclipse.emf.ecore.InternalEObject; |
| 13 | import org.eclipse.emf.ecore.impl.ENotificationImpl; |
| 14 | import org.eclipse.emf.ecore.util.EcoreUtil; |
| 15 | |
| 16 | import de.uka.ipd.sdq.featureconfig.AttributeValue; |
| 17 | import de.uka.ipd.sdq.featureconfig.ConfigNode; |
| 18 | import de.uka.ipd.sdq.featureconfig.ConfigState; |
| 19 | import de.uka.ipd.sdq.featureconfig.featureconfigPackage; |
| 20 | import de.uka.ipd.sdq.featuremodel.Attribute; |
| 21 | import de.uka.ipd.sdq.featuremodel.DoubleAttribute; |
| 22 | import de.uka.ipd.sdq.featuremodel.IntegerAttribute; |
| 23 | import de.uka.ipd.sdq.featuremodel.impl.DoubleAttributeImpl; |
| 24 | import de.uka.ipd.sdq.featuremodel.impl.IntegerAttributeImpl; |
| 25 | import de.uka.ipd.sdq.featuremodel.impl.NamedElementImpl; |
| 26 | |
| 27 | /** |
| 28 | * <!-- begin-user-doc --> |
| 29 | * An implementation of the model object '<em><b>Attribute Value</b></em>'. |
| 30 | * <!-- end-user-doc --> |
| 31 | * <p> |
| 32 | * The following features are implemented: |
| 33 | * <ul> |
| 34 | * <li>{@link de.uka.ipd.sdq.featureconfig.impl.AttributeValueImpl#getValue <em>Value</em>}</li> |
| 35 | * <li>{@link de.uka.ipd.sdq.featureconfig.impl.AttributeValueImpl#getConfignode <em>Confignode</em>}</li> |
| 36 | * </ul> |
| 37 | * </p> |
| 38 | * |
| 39 | * @generated |
| 40 | */ |
| 41 | public abstract class AttributeValueImpl extends NamedElementImpl implements AttributeValue { |
| 42 | /** |
| 43 | * The default value of the '{@link #getValue() <em>Value</em>}' attribute. |
| 44 | * <!-- begin-user-doc --> |
| 45 | * <!-- end-user-doc --> |
| 46 | * @see #getValue() |
| 47 | * @generated |
| 48 | * @ordered |
| 49 | */ |
| 50 | protected static final String VALUE_EDEFAULT = null; |
| 51 | |
| 52 | /** |
| 53 | * The cached value of the '{@link #getValue() <em>Value</em>}' attribute. |
| 54 | * <!-- begin-user-doc --> |
| 55 | * <!-- end-user-doc --> |
| 56 | * @see #getValue() |
| 57 | * @generated |
| 58 | * @ordered |
| 59 | */ |
| 60 | protected String value = VALUE_EDEFAULT; |
| 61 | |
| 62 | /** |
| 63 | * <!-- begin-user-doc --> |
| 64 | * <!-- end-user-doc --> |
| 65 | * @generated |
| 66 | */ |
| 67 | protected AttributeValueImpl() { |
| 68 | super(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * <!-- begin-user-doc --> |
| 73 | * <!-- end-user-doc --> |
| 74 | * @generated |
| 75 | */ |
| 76 | @Override |
| 77 | protected EClass eStaticClass() { |
| 78 | return featureconfigPackage.Literals.ATTRIBUTE_VALUE; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * <!-- begin-user-doc --> |
| 83 | * Code added, although value is not marked as derived. |
| 84 | * Return the features default attribute value if ConfigState of ConfigNode equals "DEFAULT" |
| 85 | * The default attribute value is not returned, if its type does not match the attributeValues type |
| 86 | * <!-- end-user-doc --> |
| 87 | * @generated NOT |
| 88 | */ |
| 89 | public String getValue() { |
| 90 | //begin user defined |
| 91 | if ((this.getConfignode() != null) && (this.getConfignode().getConfigState() != null)) { |
| 92 | if (this.getConfignode().getConfigState().equals(ConfigState.DEFAULT) |
| 93 | && this.getClass().equals(IntegerAttributeValueImpl.class)){ |
| 94 | if ((this.getConfignode() != null) && (this.getConfignode().getOrigin() != null)) { |
| 95 | for (Attribute a: this.getConfignode().getOrigin().getAttributes()){ |
| 96 | if (a.getClass().equals(IntegerAttributeImpl.class)){ |
| 97 | IntegerAttribute ia = IntegerAttribute.class.cast(a); |
| 98 | if (ia.getName().equals(this.getName())){ |
| 99 | return String.valueOf(ia.getDefaultValue()); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | if ((this.getConfignode() != null) && (this.getConfignode().getConfigState() != null)) { |
| 107 | if (this.getConfignode().getConfigState().equals(ConfigState.DEFAULT) |
| 108 | && this.getClass().equals(DoubleAttributeValueImpl.class)){ |
| 109 | if ((this.getConfignode() != null) && (this.getConfignode().getOrigin() != null)) { |
| 110 | for (Attribute a: this.getConfignode().getOrigin().getAttributes()){ |
| 111 | if (a.getClass().equals(DoubleAttributeImpl.class)){ |
| 112 | DoubleAttribute da = DoubleAttribute.class.cast(a); |
| 113 | if (da.getName().equals(this.getName())){ |
| 114 | return String.valueOf(da.getDefaultValue()); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | //end user defined |
| 122 | return value; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * <!-- begin-user-doc --> |
| 127 | * <!-- end-user-doc --> |
| 128 | * @generated |
| 129 | */ |
| 130 | public void setValue(String newValue) { |
| 131 | String oldValue = value; |
| 132 | value = newValue; |
| 133 | if (eNotificationRequired()) |
| 134 | eNotify(new ENotificationImpl(this, Notification.SET, featureconfigPackage.ATTRIBUTE_VALUE__VALUE, oldValue, value)); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * <!-- begin-user-doc --> |
| 139 | * <!-- end-user-doc --> |
| 140 | * @generated |
| 141 | */ |
| 142 | public ConfigNode getConfignode() { |
| 143 | if (eContainerFeatureID() != featureconfigPackage.ATTRIBUTE_VALUE__CONFIGNODE) return null; |
| 144 | return (ConfigNode)eContainer(); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * <!-- begin-user-doc --> |
| 149 | * <!-- end-user-doc --> |
| 150 | * @generated |
| 151 | */ |
| 152 | public NotificationChain basicSetConfignode(ConfigNode newConfignode, NotificationChain msgs) { |
| 153 | msgs = eBasicSetContainer((InternalEObject)newConfignode, featureconfigPackage.ATTRIBUTE_VALUE__CONFIGNODE, msgs); |
| 154 | return msgs; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * <!-- begin-user-doc --> |
| 159 | * <!-- end-user-doc --> |
| 160 | * @generated |
| 161 | */ |
| 162 | public void setConfignode(ConfigNode newConfignode) { |
| 163 | if (newConfignode != eInternalContainer() || (eContainerFeatureID() != featureconfigPackage.ATTRIBUTE_VALUE__CONFIGNODE && newConfignode != null)) { |
| 164 | if (EcoreUtil.isAncestor(this, newConfignode)) |
| 165 | throw new IllegalArgumentException("Recursive containment not allowed for " + toString()); |
| 166 | NotificationChain msgs = null; |
| 167 | if (eInternalContainer() != null) |
| 168 | msgs = eBasicRemoveFromContainer(msgs); |
| 169 | if (newConfignode != null) |
| 170 | msgs = ((InternalEObject)newConfignode).eInverseAdd(this, featureconfigPackage.CONFIG_NODE__ATTRIBUTEVALUE, ConfigNode.class, msgs); |
| 171 | msgs = basicSetConfignode(newConfignode, msgs); |
| 172 | if (msgs != null) msgs.dispatch(); |
| 173 | } |
| 174 | else if (eNotificationRequired()) |
| 175 | eNotify(new ENotificationImpl(this, Notification.SET, featureconfigPackage.ATTRIBUTE_VALUE__CONFIGNODE, newConfignode, newConfignode)); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * <!-- begin-user-doc --> |
| 180 | * <!-- end-user-doc --> |
| 181 | * @generated |
| 182 | */ |
| 183 | @Override |
| 184 | public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { |
| 185 | switch (featureID) { |
| 186 | case featureconfigPackage.ATTRIBUTE_VALUE__CONFIGNODE: |
| 187 | if (eInternalContainer() != null) |
| 188 | msgs = eBasicRemoveFromContainer(msgs); |
| 189 | return basicSetConfignode((ConfigNode)otherEnd, msgs); |
| 190 | } |
| 191 | return super.eInverseAdd(otherEnd, featureID, msgs); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * <!-- begin-user-doc --> |
| 196 | * <!-- end-user-doc --> |
| 197 | * @generated |
| 198 | */ |
| 199 | @Override |
| 200 | public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { |
| 201 | switch (featureID) { |
| 202 | case featureconfigPackage.ATTRIBUTE_VALUE__CONFIGNODE: |
| 203 | return basicSetConfignode(null, msgs); |
| 204 | } |
| 205 | return super.eInverseRemove(otherEnd, featureID, msgs); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * <!-- begin-user-doc --> |
| 210 | * <!-- end-user-doc --> |
| 211 | * @generated |
| 212 | */ |
| 213 | @Override |
| 214 | public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) { |
| 215 | switch (eContainerFeatureID()) { |
| 216 | case featureconfigPackage.ATTRIBUTE_VALUE__CONFIGNODE: |
| 217 | return eInternalContainer().eInverseRemove(this, featureconfigPackage.CONFIG_NODE__ATTRIBUTEVALUE, ConfigNode.class, msgs); |
| 218 | } |
| 219 | return super.eBasicRemoveFromContainerFeature(msgs); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * <!-- begin-user-doc --> |
| 224 | * <!-- end-user-doc --> |
| 225 | * @generated |
| 226 | */ |
| 227 | @Override |
| 228 | public Object eGet(int featureID, boolean resolve, boolean coreType) { |
| 229 | switch (featureID) { |
| 230 | case featureconfigPackage.ATTRIBUTE_VALUE__VALUE: |
| 231 | return getValue(); |
| 232 | case featureconfigPackage.ATTRIBUTE_VALUE__CONFIGNODE: |
| 233 | return getConfignode(); |
| 234 | } |
| 235 | return super.eGet(featureID, resolve, coreType); |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * <!-- begin-user-doc --> |
| 240 | * <!-- end-user-doc --> |
| 241 | * @generated |
| 242 | */ |
| 243 | @Override |
| 244 | public void eSet(int featureID, Object newValue) { |
| 245 | switch (featureID) { |
| 246 | case featureconfigPackage.ATTRIBUTE_VALUE__VALUE: |
| 247 | setValue((String)newValue); |
| 248 | return; |
| 249 | case featureconfigPackage.ATTRIBUTE_VALUE__CONFIGNODE: |
| 250 | setConfignode((ConfigNode)newValue); |
| 251 | return; |
| 252 | } |
| 253 | super.eSet(featureID, newValue); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * <!-- begin-user-doc --> |
| 258 | * <!-- end-user-doc --> |
| 259 | * @generated |
| 260 | */ |
| 261 | @Override |
| 262 | public void eUnset(int featureID) { |
| 263 | switch (featureID) { |
| 264 | case featureconfigPackage.ATTRIBUTE_VALUE__VALUE: |
| 265 | setValue(VALUE_EDEFAULT); |
| 266 | return; |
| 267 | case featureconfigPackage.ATTRIBUTE_VALUE__CONFIGNODE: |
| 268 | setConfignode((ConfigNode)null); |
| 269 | return; |
| 270 | } |
| 271 | super.eUnset(featureID); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * <!-- begin-user-doc --> |
| 276 | * <!-- end-user-doc --> |
| 277 | * @generated |
| 278 | */ |
| 279 | @Override |
| 280 | public boolean eIsSet(int featureID) { |
| 281 | switch (featureID) { |
| 282 | case featureconfigPackage.ATTRIBUTE_VALUE__VALUE: |
| 283 | return VALUE_EDEFAULT == null ? value != null : !VALUE_EDEFAULT.equals(value); |
| 284 | case featureconfigPackage.ATTRIBUTE_VALUE__CONFIGNODE: |
| 285 | return getConfignode() != null; |
| 286 | } |
| 287 | return super.eIsSet(featureID); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * <!-- begin-user-doc --> |
| 292 | * <!-- end-user-doc --> |
| 293 | * @generated |
| 294 | */ |
| 295 | @Override |
| 296 | public String toString() { |
| 297 | if (eIsProxy()) return super.toString(); |
| 298 | |
| 299 | StringBuffer result = new StringBuffer(super.toString()); |
| 300 | result.append(" (value: "); |
| 301 | result.append(value); |
| 302 | result.append(')'); |
| 303 | return result.toString(); |
| 304 | } |
| 305 | |
| 306 | } //AttributeValueImpl |