KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > change > impl > FeatureMapEntryImpl


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2003-2005 IBM Corporation 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  *
13  * </copyright>
14  *
15  * $Id: FeatureMapEntryImpl.java,v 1.3 2005/06/08 06:16:16 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.change.impl;
18
19
20 import java.util.Map JavaDoc;
21
22 import org.eclipse.emf.common.notify.Notification;
23 import org.eclipse.emf.common.util.EList;
24 import org.eclipse.emf.ecore.EAttribute;
25 import org.eclipse.emf.ecore.EClass;
26 import org.eclipse.emf.ecore.EDataType;
27 import org.eclipse.emf.ecore.EObject;
28 import org.eclipse.emf.ecore.EReference;
29 import org.eclipse.emf.ecore.EStructuralFeature;
30 import org.eclipse.emf.ecore.change.ChangeFactory;
31 import org.eclipse.emf.ecore.change.ChangeKind;
32 import org.eclipse.emf.ecore.change.ChangePackage;
33 import org.eclipse.emf.ecore.change.FeatureMapEntry;
34 import org.eclipse.emf.ecore.change.ListChange;
35 import org.eclipse.emf.ecore.impl.ENotificationImpl;
36 import org.eclipse.emf.ecore.impl.EObjectImpl;
37 import org.eclipse.emf.ecore.util.EcoreUtil;
38 import org.eclipse.emf.ecore.util.FeatureMap;
39 //import org.eclipse.emf.ecore.InternalEObject;
40

41
42 /**
43  * <!-- begin-user-doc -->
44  * An implementation of the model object '<em><b>Feature Map Entry</b></em>'.
45  * @extends FeatureMap.Entry
46  * <!-- end-user-doc -->
47  * <p>
48  * The following features are implemented:
49  * <ul>
50  * <li>{@link org.eclipse.emf.ecore.change.impl.FeatureMapEntryImpl#getFeatureName <em>Feature Name</em>}</li>
51  * <li>{@link org.eclipse.emf.ecore.change.impl.FeatureMapEntryImpl#getDataValue <em>Data Value</em>}</li>
52  * <li>{@link org.eclipse.emf.ecore.change.impl.FeatureMapEntryImpl#getValue <em>Value</em>}</li>
53  * <li>{@link org.eclipse.emf.ecore.change.impl.FeatureMapEntryImpl#getFeature <em>Feature</em>}</li>
54  * <li>{@link org.eclipse.emf.ecore.change.impl.FeatureMapEntryImpl#getReferenceValue <em>Reference Value</em>}</li>
55  * </ul>
56  * </p>
57  *
58  * @generated
59  */

60 public class FeatureMapEntryImpl extends EObjectImpl implements FeatureMapEntry, FeatureMap.Entry
61 {
62   /**
63    * The bit of {@link #eFlags} that is used to represent if feature is a proxy.
64    */

65   protected static final int EPROXY_FEATURECHANGE = ELAST_EOBJECT_FLAG << 1;
66   
67   /**
68    * The default value of the '{@link #getFeatureName() <em>Feature Name</em>}' attribute.
69    * <!-- begin-user-doc -->
70    * <!-- end-user-doc -->
71    * @see #getFeatureName()
72    * @generated
73    * @ordered
74    */

75   protected static final String JavaDoc FEATURE_NAME_EDEFAULT = null;
76
77   /**
78    * The default value of the '{@link #getDataValue() <em>Data Value</em>}' attribute.
79    * <!-- begin-user-doc -->
80    * <!-- end-user-doc -->
81    * @see #getDataValue()
82    * @generated
83    * @ordered
84    */

85   protected static final String JavaDoc DATA_VALUE_EDEFAULT = null;
86
87   /**
88    * The default value of the '{@link #getValue() <em>Value</em>}' attribute.
89    * <!-- begin-user-doc -->
90    * <!-- end-user-doc -->
91    * @see #getValue()
92    * @generated
93    * @ordered
94    */

95   protected static final Object JavaDoc VALUE_EDEFAULT = null;
96
97   protected EStructuralFeature feature = null;
98   
99   protected String JavaDoc featureName = null;
100
101   protected Object JavaDoc value = null;
102   
103   protected String JavaDoc valueString = null;
104
105   /**
106    * <!-- begin-user-doc -->
107    * <!-- end-user-doc -->
108    * @generated
109    */

110   protected FeatureMapEntryImpl()
111   {
112     super();
113   }
114
115   protected FeatureMapEntryImpl(EStructuralFeature feature, Object JavaDoc value)
116   {
117     this();
118     this.feature = feature;
119     setValue(value);
120   }
121
122   /**
123    * <!-- begin-user-doc -->
124    * <!-- end-user-doc -->
125    * @generated
126    */

127   protected EClass eStaticClass()
128   {
129     return ChangePackage.eINSTANCE.getFeatureMapEntry();
130   }
131
132   /**
133    * <!-- begin-user-doc -->
134    * <!-- end-user-doc -->
135    * @generated NOT
136    */

137   public String JavaDoc getFeatureName()
138   {
139     return feature == null ? featureName : feature.getName();
140   }
141
142   /**
143    * <!-- begin-user-doc -->
144    * <!-- end-user-doc -->
145    * @generated NOT
146    */

147   public void setFeatureName(String JavaDoc newFeatureName)
148   {
149     featureName = newFeatureName;
150     feature = null;
151     eFlags &= ~EPROXY_FEATURECHANGE;
152   }
153
154   /**
155    * <!-- begin-user-doc -->
156    * <!-- end-user-doc -->
157    * @generated NOT
158    */

159   public void unsetFeatureName()
160   {
161     setFeatureName(null);
162   }
163
164   /**
165    * <!-- begin-user-doc -->
166    * <!-- end-user-doc -->
167    * @generated NOT
168    */

169   public boolean isSetFeatureName()
170   {
171     return (feature != null || featureName != null) && getGreatGrandParent() instanceof EObjectToChangesMapEntryImpl;
172   }
173   
174   protected EObject getGreatGrandParent()
175   {
176     EObject container = eContainer();
177     if (container != null)
178     {
179       container = container.eContainer();
180       if (container != null)
181       {
182         return container.eContainer();
183       }
184     }
185     return null;
186   }
187
188   /**
189    * <!-- begin-user-doc -->
190    * <!-- end-user-doc -->
191    * @generated NOT
192    */

193   public String JavaDoc getDataValue()
194   {
195     if (valueString == null)
196     {
197       EStructuralFeature feature = getFeature();
198       if (feature instanceof EAttribute)
199       {
200         EDataType type = (EDataType)feature.getEType();
201         valueString = EcoreUtil.convertToString(type, value);
202       }
203     }
204     return valueString;
205   }
206
207   /**
208    * <!-- begin-user-doc -->
209    * <!-- end-user-doc -->
210    * @generated NOT
211    */

212   public void setDataValue(String JavaDoc newDataValue)
213   {
214     String JavaDoc oldDataValue = getDataValue();
215     valueString = newDataValue;
216     value = null;
217     if (eNotificationRequired())
218       eNotify(new ENotificationImpl(this, Notification.SET, ChangePackage.FEATURE_CHANGE__DATA_VALUE, oldDataValue, newDataValue));
219   }
220   
221   public EStructuralFeature getEStructuralFeature()
222   {
223     return getFeature();
224   }
225
226   /**
227    * <!-- begin-user-doc -->
228    * <!-- end-user-doc -->
229    * @generated NOT
230    */

231   public EStructuralFeature getFeature()
232   {
233     if (feature == null)
234     {
235       EObject greatGrandParent = getGreatGrandParent();
236       if (greatGrandParent instanceof EObjectToChangesMapEntryImpl)
237       {
238         feature = ((EObject)((Map.Entry JavaDoc)greatGrandParent).getKey()).eClass().getEStructuralFeature(featureName);
239       }
240     }
241     else if ((eFlags & EPROXY_FEATURECHANGE) !=0)
242     {
243       EStructuralFeature oldFeature = feature;
244       feature = (EStructuralFeature)EcoreUtil.resolve(feature, this);
245       if (feature != oldFeature)
246       {
247         if (eNotificationRequired())
248           eNotify(new ENotificationImpl(this, Notification.RESOLVE, ChangePackage.FEATURE_CHANGE__FEATURE, oldFeature, feature));
249       }
250       eFlags &= ~ EPROXY_FEATURECHANGE;
251     }
252     return feature;
253   }
254
255   /**
256    * <!-- begin-user-doc -->
257    * <!-- end-user-doc -->
258    * @generated NOT
259    */

260   public EStructuralFeature basicGetFeature()
261   {
262     return feature;
263   }
264
265   /**
266    * <!-- begin-user-doc -->
267    * <!-- end-user-doc -->
268    * @generated NOT
269    */

270   public void setFeature(EStructuralFeature newFeature)
271   {
272     EStructuralFeature oldFeature = basicGetFeature();
273     feature = newFeature;
274     featureName = null;
275     if (feature != null && feature.eIsProxy())
276       eFlags |= EPROXY_FEATURECHANGE;
277     else
278       eFlags &= ~EPROXY_FEATURECHANGE;
279     if (eNotificationRequired())
280       eNotify(new ENotificationImpl(this, Notification.SET, ChangePackage.FEATURE_CHANGE__FEATURE, oldFeature, newFeature));
281   }
282
283   /**
284    * <!-- begin-user-doc -->
285    * <!-- end-user-doc -->
286    * @generated NOT
287    */

288   public void unsetFeature()
289   {
290     setFeature(null);
291   }
292
293   /**
294    * <!-- begin-user-doc -->
295    * <!-- end-user-doc -->
296    * @generated NOT
297    */

298   public boolean isSetFeature()
299   {
300     return feature != null && !(getGreatGrandParent() instanceof EObjectToChangesMapEntryImpl);
301   }
302
303   /**
304    * <!-- begin-user-doc -->
305    * <!-- end-user-doc -->
306    * @generated NOT
307    */

308   public EObject getReferenceValue()
309   {
310     EObject referenceValue = basicGetReferenceValue();
311     if (referenceValue != null && referenceValue.eIsProxy())
312     {
313       EObject oldReferenceValue = referenceValue;
314       referenceValue = EcoreUtil.resolve(referenceValue, this);
315       if (referenceValue != oldReferenceValue)
316       {
317         if (eNotificationRequired())
318           eNotify(new ENotificationImpl(this, Notification.RESOLVE, ChangePackage.FEATURE_CHANGE__REFERENCE_VALUE, oldReferenceValue, referenceValue));
319       }
320     }
321     return referenceValue;
322   }
323
324   /**
325    * <!-- begin-user-doc -->
326    * <!-- end-user-doc -->
327    * @generated NOT
328    */

329   public EObject basicGetReferenceValue()
330   {
331     return feature instanceof EReference ? (EObject)value : null;
332   }
333
334   /**
335    * <!-- begin-user-doc -->
336    * <!-- end-user-doc -->
337    * @generated NOT
338    */

339   public void setReferenceValue(EObject newReferenceValue)
340   {
341     EObject oldReferenceValue = basicGetReferenceValue();
342     value = newReferenceValue;
343     valueString = null;
344     if (eNotificationRequired())
345       eNotify(new ENotificationImpl(this, Notification.SET, ChangePackage.FEATURE_CHANGE__REFERENCE_VALUE, oldReferenceValue, newReferenceValue));
346   }
347
348   /**
349    * <!-- begin-user-doc -->
350    * <!-- end-user-doc -->
351    * @generated NOT
352    */

353   public Object JavaDoc getValue()
354   {
355     EStructuralFeature feature = getFeature();
356     if (feature instanceof EReference)
357     {
358       return getReferenceValue();
359     }
360     else if (value == null) // feature is instance of EAttribute
361
{
362       EDataType type = (EDataType)feature.getEType();
363       value = EcoreUtil.createFromString(type, valueString);
364     }
365     return value;
366   }
367
368   protected void setValue(Object JavaDoc value)
369   {
370     EStructuralFeature feature = getFeature();
371     if (!eNotificationRequired())
372     {
373       valueString = null;
374       this.value = value;
375     }
376     else
377     {
378       if (feature instanceof EAttribute)
379       {
380         EDataType type = (EDataType)feature.getEType();
381         setDataValue(valueString = EcoreUtil.convertToString(type, value));
382         this.value = value;
383       }
384       else
385       {
386         setReferenceValue((EObject)value);
387       }
388     }
389   }
390
391   /**
392    * <!-- begin-user-doc -->
393    * <!-- end-user-doc -->
394    * @generated
395    */

396   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
397   {
398     switch (eDerivedStructuralFeatureID(eFeature))
399     {
400       case ChangePackage.FEATURE_MAP_ENTRY__FEATURE_NAME:
401         return getFeatureName();
402       case ChangePackage.FEATURE_MAP_ENTRY__DATA_VALUE:
403         return getDataValue();
404       case ChangePackage.FEATURE_MAP_ENTRY__VALUE:
405         return getValue();
406       case ChangePackage.FEATURE_MAP_ENTRY__FEATURE:
407         if (resolve) return getFeature();
408         return basicGetFeature();
409       case ChangePackage.FEATURE_MAP_ENTRY__REFERENCE_VALUE:
410         if (resolve) return getReferenceValue();
411         return basicGetReferenceValue();
412     }
413     return eDynamicGet(eFeature, resolve);
414   }
415
416   /**
417    * <!-- begin-user-doc -->
418    * <!-- end-user-doc -->
419    * @generated
420    */

421   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
422   {
423     switch (eDerivedStructuralFeatureID(eFeature))
424     {
425       case ChangePackage.FEATURE_MAP_ENTRY__FEATURE_NAME:
426         setFeatureName((String JavaDoc)newValue);
427         return;
428       case ChangePackage.FEATURE_MAP_ENTRY__DATA_VALUE:
429         setDataValue((String JavaDoc)newValue);
430         return;
431       case ChangePackage.FEATURE_MAP_ENTRY__FEATURE:
432         setFeature((EStructuralFeature)newValue);
433         return;
434       case ChangePackage.FEATURE_MAP_ENTRY__REFERENCE_VALUE:
435         setReferenceValue((EObject)newValue);
436         return;
437     }
438     eDynamicSet(eFeature, newValue);
439   }
440
441   /**
442    * <!-- begin-user-doc -->
443    * <!-- end-user-doc -->
444    * @generated
445    */

446   public void eUnset(EStructuralFeature eFeature)
447   {
448     switch (eDerivedStructuralFeatureID(eFeature))
449     {
450       case ChangePackage.FEATURE_MAP_ENTRY__FEATURE_NAME:
451         unsetFeatureName();
452         return;
453       case ChangePackage.FEATURE_MAP_ENTRY__DATA_VALUE:
454         setDataValue(DATA_VALUE_EDEFAULT);
455         return;
456       case ChangePackage.FEATURE_MAP_ENTRY__FEATURE:
457         unsetFeature();
458         return;
459       case ChangePackage.FEATURE_MAP_ENTRY__REFERENCE_VALUE:
460         setReferenceValue((EObject)null);
461         return;
462     }
463     eDynamicUnset(eFeature);
464   }
465
466   /**
467    * <!-- begin-user-doc -->
468    * <!-- end-user-doc -->
469    * @generated
470    */

471   public boolean eIsSet(EStructuralFeature eFeature)
472   {
473     switch (eDerivedStructuralFeatureID(eFeature))
474     {
475       case ChangePackage.FEATURE_MAP_ENTRY__FEATURE_NAME:
476         return isSetFeatureName();
477       case ChangePackage.FEATURE_MAP_ENTRY__DATA_VALUE:
478         return DATA_VALUE_EDEFAULT == null ? getDataValue() != null : !DATA_VALUE_EDEFAULT.equals(getDataValue());
479       case ChangePackage.FEATURE_MAP_ENTRY__VALUE:
480         return VALUE_EDEFAULT == null ? getValue() != null : !VALUE_EDEFAULT.equals(getValue());
481       case ChangePackage.FEATURE_MAP_ENTRY__FEATURE:
482         return isSetFeature();
483       case ChangePackage.FEATURE_MAP_ENTRY__REFERENCE_VALUE:
484         return basicGetReferenceValue() != null;
485     }
486     return eDynamicIsSet(eFeature);
487   }
488
489   protected ListChange createListChange(EList changesList, ChangeKind kind, int index)
490   {
491     ListChange listChange = ChangeFactory.eINSTANCE.createListChange();
492     listChange.setKind(kind);
493     listChange.setIndex(index);
494     changesList.add(listChange);
495     return listChange;
496   }
497 } //FeatureChangeImpl
498
Popular Tags