|
Added
Link Here
|
| 1 |
/** |
| 2 |
* <copyright> |
| 3 |
* |
| 4 |
* Copyright (c) 2008 IBM Corporation, Zeligsoft Inc., and others. |
| 5 |
* All rights reserved. This program and the accompanying materials |
| 6 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 7 |
* which accompanies this distribution, and is available at |
| 8 |
* http://www.eclipse.org/legal/epl-v10.html |
| 9 |
* |
| 10 |
* Contributors: |
| 11 |
* IBM - Initial API and implementation |
| 12 |
* Zeligsoft - 216701 Removed redundant eStructuralFeature field from Stateless |
| 13 |
* |
| 14 |
* </copyright> |
| 15 |
* |
| 16 |
* $Id$ |
| 17 |
*/ |
| 18 |
package org.eclipse.emf.ecore.util; |
| 19 |
|
| 20 |
import org.eclipse.emf.common.notify.NotificationChain; |
| 21 |
import org.eclipse.emf.ecore.EObject; |
| 22 |
import org.eclipse.emf.ecore.EStructuralFeature; |
| 23 |
import org.eclipse.emf.ecore.InternalEObject; |
| 24 |
import org.eclipse.emf.ecore.EStructuralFeature.Setting; |
| 25 |
import org.eclipse.emf.ecore.EStructuralFeature.Internal.DynamicValueHolder; |
| 26 |
|
| 27 |
/** |
| 28 |
* A basic implementation of a stateful setting delegate. |
| 29 |
* At least the first two of these methods needs to be overridden. |
| 30 |
* <ul> |
| 31 |
* <li>{@link #dynamicGet(InternalEObject, DynamicValueHolder, int, boolean, boolean)}</li> |
| 32 |
* <li>{@link #dynamicIsSet(InternalEObject, DynamicValueHolder, int)}</li> |
| 33 |
* <li>{@link #dynamicSet(InternalEObject, DynamicValueHolder, int, Object)}</li> |
| 34 |
* <li>{@link #dynamicUnset(InternalEObject, DynamicValueHolder, int)}</li> |
| 35 |
* <li>{@link #dynamicInverseAdd(InternalEObject, DynamicValueHolder, int, InternalEObject, NotificationChain)}</li> |
| 36 |
* <li>{@link #dynamicInverseRemove(InternalEObject, DynamicValueHolder, int, InternalEObject, NotificationChain)}</li> |
| 37 |
* </ul> |
| 38 |
*/ |
| 39 |
public abstract class BasicSettingDelegate implements EStructuralFeature.Internal.SettingDelegate |
| 40 |
{ |
| 41 |
protected EStructuralFeature eStructuralFeature; |
| 42 |
|
| 43 |
public BasicSettingDelegate(EStructuralFeature eStructuralFeature) |
| 44 |
{ |
| 45 |
this.eStructuralFeature = eStructuralFeature; |
| 46 |
} |
| 47 |
|
| 48 |
public Setting dynamicSetting(final InternalEObject owner, final DynamicValueHolder settings, final int dynamicFeatureID) |
| 49 |
{ |
| 50 |
return |
| 51 |
new EStructuralFeature.Setting() |
| 52 |
{ |
| 53 |
public EObject getEObject() |
| 54 |
{ |
| 55 |
return owner; |
| 56 |
} |
| 57 |
|
| 58 |
public EStructuralFeature getEStructuralFeature() |
| 59 |
{ |
| 60 |
return eStructuralFeature; |
| 61 |
} |
| 62 |
|
| 63 |
public Object get(boolean resolve) |
| 64 |
{ |
| 65 |
return BasicSettingDelegate.this.dynamicGet(owner, settings, dynamicFeatureID, resolve, true); |
| 66 |
} |
| 67 |
|
| 68 |
public boolean isSet() |
| 69 |
{ |
| 70 |
return BasicSettingDelegate.this.dynamicIsSet(owner, settings, dynamicFeatureID); |
| 71 |
} |
| 72 |
|
| 73 |
public void set(Object newValue) |
| 74 |
{ |
| 75 |
BasicSettingDelegate.this.dynamicSet(owner, settings, dynamicFeatureID, newValue); |
| 76 |
} |
| 77 |
|
| 78 |
public void unset() |
| 79 |
{ |
| 80 |
BasicSettingDelegate.this.dynamicUnset(owner, settings, dynamicFeatureID); |
| 81 |
} |
| 82 |
}; |
| 83 |
} |
| 84 |
|
| 85 |
public abstract Object dynamicGet(InternalEObject owner, DynamicValueHolder settings, int dynamicFeatureID, boolean resolve, boolean coreType); |
| 86 |
|
| 87 |
|
| 88 |
public abstract boolean dynamicIsSet(InternalEObject owner, DynamicValueHolder settings, int dynamicFeatureID); |
| 89 |
|
| 90 |
|
| 91 |
public void dynamicSet(InternalEObject owner, DynamicValueHolder settings, int dynamicFeatureID, Object newValue) |
| 92 |
{ |
| 93 |
throw new UnsupportedOperationException(); |
| 94 |
} |
| 95 |
|
| 96 |
public void dynamicUnset(InternalEObject owner, DynamicValueHolder settings, int dynamicFeatureID) |
| 97 |
{ |
| 98 |
throw new UnsupportedOperationException(); |
| 99 |
} |
| 100 |
|
| 101 |
public NotificationChain dynamicInverseAdd |
| 102 |
(InternalEObject owner, |
| 103 |
DynamicValueHolder settings, |
| 104 |
int dynamicFeatureID, |
| 105 |
InternalEObject otherEnd, |
| 106 |
NotificationChain notifications) |
| 107 |
{ |
| 108 |
throw new UnsupportedOperationException(); |
| 109 |
} |
| 110 |
|
| 111 |
public NotificationChain dynamicInverseRemove |
| 112 |
(InternalEObject owner, |
| 113 |
DynamicValueHolder settings, |
| 114 |
int dynamicFeatureID, |
| 115 |
InternalEObject otherEnd, |
| 116 |
NotificationChain notifications) |
| 117 |
{ |
| 118 |
throw new UnsupportedOperationException(); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* A basic implementation of a stateless setting delegate. |
| 123 |
* At least the first two of these methods should be overridden. |
| 124 |
* <ul> |
| 125 |
* <li>{@link #setting(InternalEObject)}</li> |
| 126 |
* <li>{@link #get(InternalEObject, boolean, boolean)}</li> |
| 127 |
* <li>{@link #set(InternalEObject, Object)}</li> |
| 128 |
* <li>{@link #isSet(InternalEObject)}</li> |
| 129 |
* <li>{@link #unset(InternalEObject)}</li> |
| 130 |
* <li>{@link #inverseAdd(InternalEObject, InternalEObject, NotificationChain)}</li> |
| 131 |
* <li>{@link #inverseRemove(InternalEObject, InternalEObject, NotificationChain)}</li> |
| 132 |
* </ul> |
| 133 |
*/ |
| 134 |
public static abstract class Stateless extends BasicSettingDelegate |
| 135 |
{ |
| 136 |
public Stateless(EStructuralFeature eStructuralFeature) |
| 137 |
{ |
| 138 |
super(eStructuralFeature); |
| 139 |
} |
| 140 |
|
| 141 |
@Override |
| 142 |
public final Setting dynamicSetting(InternalEObject owner, DynamicValueHolder settings, int dynamicFeatureID) |
| 143 |
{ |
| 144 |
return setting(owner); |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Creates a setting for the owner and this delegate's feature. |
| 149 |
* @param owner the owner for the setting. |
| 150 |
* @return a new setting. |
| 151 |
*/ |
| 152 |
protected Setting setting(final InternalEObject owner) |
| 153 |
{ |
| 154 |
return |
| 155 |
new EStructuralFeature.Setting() |
| 156 |
{ |
| 157 |
public EObject getEObject() |
| 158 |
{ |
| 159 |
return owner; |
| 160 |
} |
| 161 |
|
| 162 |
public EStructuralFeature getEStructuralFeature() |
| 163 |
{ |
| 164 |
return eStructuralFeature; |
| 165 |
} |
| 166 |
|
| 167 |
public Object get(boolean resolve) |
| 168 |
{ |
| 169 |
return Stateless.this.get(owner, resolve, true); |
| 170 |
} |
| 171 |
|
| 172 |
public boolean isSet() |
| 173 |
{ |
| 174 |
return Stateless.this.isSet(owner); |
| 175 |
} |
| 176 |
|
| 177 |
public void set(Object newValue) |
| 178 |
{ |
| 179 |
Stateless.this.set(owner, newValue); |
| 180 |
} |
| 181 |
|
| 182 |
public void unset() |
| 183 |
{ |
| 184 |
Stateless.this.unset(owner); |
| 185 |
} |
| 186 |
}; |
| 187 |
} |
| 188 |
|
| 189 |
@Override |
| 190 |
public final Object dynamicGet(InternalEObject owner, DynamicValueHolder settings, int dynamicFeatureID, boolean resolve, boolean coreType) |
| 191 |
{ |
| 192 |
return get(owner, resolve, coreType); |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Returns the value of this delegate's feature for the owner. |
| 197 |
* @param owner the object for with to fetch the value. |
| 198 |
* @param resolve whether the returned object should be resolved it if is a proxy. |
| 199 |
* @param coreType whether to return the core type value or the API type value. |
| 200 |
* @return the value of this delegate's feature for the owner. |
| 201 |
* @see InternalEObject#eGet(EStructuralFeature, boolean, boolean) |
| 202 |
*/ |
| 203 |
protected abstract Object get(InternalEObject owner, boolean resolve, boolean coreType); |
| 204 |
|
| 205 |
@Override |
| 206 |
public final boolean dynamicIsSet(InternalEObject owner, DynamicValueHolder settings, int dynamicFeatureID) |
| 207 |
{ |
| 208 |
return isSet(owner); |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* Returns whether the value of this delegate's feature is considered set for the owner. |
| 213 |
* @param owner the object for with to test is set. |
| 214 |
* @return whether the value of this delegate's feature is considered set for the owner. |
| 215 |
* @see EObject#eIsSet(EStructuralFeature) |
| 216 |
*/ |
| 217 |
protected abstract boolean isSet(InternalEObject owner); |
| 218 |
|
| 219 |
@Override |
| 220 |
public final void dynamicSet(InternalEObject owner, DynamicValueHolder settings, int dynamicFeatureID, Object newValue) |
| 221 |
{ |
| 222 |
set(owner, newValue); |
| 223 |
} |
| 224 |
|
| 225 |
/** |
| 226 |
* Sets this new value of this delegate's feature for the owner. |
| 227 |
* @param owner the owner for which to set the value |
| 228 |
* @param newValue the new value for the feature. |
| 229 |
* @see EObject#eSet(EStructuralFeature, Object) |
| 230 |
*/ |
| 231 |
protected void set(InternalEObject owner, Object newValue) |
| 232 |
{ |
| 233 |
throw new UnsupportedOperationException(); |
| 234 |
} |
| 235 |
|
| 236 |
@Override |
| 237 |
public final void dynamicUnset(InternalEObject owner, DynamicValueHolder settings, int dynamicFeatureID) |
| 238 |
{ |
| 239 |
unset(owner); |
| 240 |
} |
| 241 |
|
| 242 |
/** |
| 243 |
* Unsets the values of this delegate's feature for the owner. |
| 244 |
* @param owner the owner for which to unset the value. |
| 245 |
* @see EObject#eUnset(EStructuralFeature) |
| 246 |
*/ |
| 247 |
protected void unset(InternalEObject owner) |
| 248 |
{ |
| 249 |
throw new UnsupportedOperationException(); |
| 250 |
} |
| 251 |
|
| 252 |
@Override |
| 253 |
public final NotificationChain dynamicInverseAdd |
| 254 |
(InternalEObject owner, |
| 255 |
DynamicValueHolder settings, |
| 256 |
int dynamicFeatureID, |
| 257 |
InternalEObject otherEnd, |
| 258 |
NotificationChain notifications) |
| 259 |
{ |
| 260 |
return inverseAdd(owner, otherEnd, notifications); |
| 261 |
} |
| 262 |
|
| 263 |
/** |
| 264 |
* Adds the object at the other end of a bidirectional reference to this delegate's feature |
| 265 |
* and returns accumulated notifications. |
| 266 |
* @param owner the owner for which to do the inverse add. |
| 267 |
* @param otherEnd the object to inverse add. |
| 268 |
* @param notifications the notifications accumulated so far. |
| 269 |
* @return the accumulated notifications. |
| 270 |
*/ |
| 271 |
protected NotificationChain inverseAdd |
| 272 |
(InternalEObject owner, |
| 273 |
InternalEObject otherEnd, |
| 274 |
NotificationChain notifications) |
| 275 |
{ |
| 276 |
throw new UnsupportedOperationException(); |
| 277 |
} |
| 278 |
|
| 279 |
@Override |
| 280 |
public final NotificationChain dynamicInverseRemove |
| 281 |
(InternalEObject owner, |
| 282 |
DynamicValueHolder settings, |
| 283 |
int dynamicFeatureID, |
| 284 |
InternalEObject otherEnd, |
| 285 |
NotificationChain notifications) |
| 286 |
{ |
| 287 |
return inverseRemove(owner, otherEnd, notifications); |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Remove the object at the other end of a bidirectional reference from this delegate's feature |
| 292 |
* and returns accumulated notifications. |
| 293 |
* @param owner the owner for which to do the inverse remove. |
| 294 |
* @param otherEnd the object to inverse remove. |
| 295 |
* @param notifications the notifications accumulated so far. |
| 296 |
* @return the accumulated notifications. |
| 297 |
*/ |
| 298 |
protected NotificationChain inverseRemove |
| 299 |
(InternalEObject owner, |
| 300 |
InternalEObject otherEnd, |
| 301 |
NotificationChain notifications) |
| 302 |
{ |
| 303 |
throw new UnsupportedOperationException(); |
| 304 |
} |
| 305 |
} |
| 306 |
} |