KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > impl > EEnumLiteralImpl


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 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: EEnumLiteralImpl.java,v 1.4 2005/06/08 06:20:10 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.impl;
18
19
20 import java.util.Collection JavaDoc;
21
22 import org.eclipse.emf.common.notify.Notification;
23 import org.eclipse.emf.common.notify.NotificationChain;
24 import org.eclipse.emf.common.util.Enumerator;
25 import org.eclipse.emf.ecore.EClass;
26 import org.eclipse.emf.ecore.EEnum;
27 import org.eclipse.emf.ecore.EEnumLiteral;
28 import org.eclipse.emf.ecore.EStructuralFeature;
29 import org.eclipse.emf.ecore.EcorePackage;
30 import org.eclipse.emf.ecore.InternalEObject;
31 import org.eclipse.emf.ecore.util.InternalEList;
32
33
34 /**
35  * <!-- begin-user-doc -->
36  * An implementation of the model object '<em><b>EEnum Literal</b></em>'.
37  * <!-- end-user-doc -->
38  * <p>
39  * The following features are implemented:
40  * <ul>
41  * <li>{@link org.eclipse.emf.ecore.impl.EEnumLiteralImpl#getValue <em>Value</em>}</li>
42  * <li>{@link org.eclipse.emf.ecore.impl.EEnumLiteralImpl#getInstance <em>Instance</em>}</li>
43  * <li>{@link org.eclipse.emf.ecore.impl.EEnumLiteralImpl#getEEnum <em>EEnum</em>}</li>
44  * </ul>
45  * </p>
46  *
47  * @generated
48  */

49 public class EEnumLiteralImpl extends ENamedElementImpl implements EEnumLiteral
50 {
51   /**
52    * The default value of the '{@link #getValue() <em>Value</em>}' attribute.
53    * <!-- begin-user-doc -->
54    * <!-- end-user-doc -->
55    * @see #getValue()
56    * @generated
57    * @ordered
58    */

59   protected static final int VALUE_EDEFAULT = 0;
60
61   /**
62    * The cached value of the '{@link #getValue() <em>Value</em>}' attribute.
63    * <!-- begin-user-doc -->
64    * <!-- end-user-doc -->
65    * @see #getValue()
66    * @generated
67    * @ordered
68    */

69   protected int value = VALUE_EDEFAULT;
70
71   /**
72    * The default value of the '{@link #getInstance() <em>Instance</em>}' attribute.
73    * <!-- begin-user-doc -->
74    * <!-- end-user-doc -->
75    * @see #getInstance()
76    * @generated
77    * @ordered
78    */

79   protected static final Enumerator INSTANCE_EDEFAULT = null;
80
81   /**
82    * The cached value of the '{@link #getInstance() <em>Instance</em>}' attribute.
83    * <!-- begin-user-doc -->
84    * <!-- end-user-doc -->
85    * @see #getInstance()
86    * @generated
87    * @ordered
88    */

89   protected Enumerator instance = INSTANCE_EDEFAULT;
90
91   /**
92    * <!-- begin-user-doc -->
93    * <!-- end-user-doc -->
94    * @generated NOT
95    */

96   protected EEnumLiteralImpl()
97   {
98     super();
99     instance = this;
100   }
101
102   /**
103    * <!-- begin-user-doc -->
104    * <!-- end-user-doc -->
105    * @generated
106    */

107   protected EClass eStaticClass()
108   {
109     return EcorePackage.eINSTANCE.getEEnumLiteral();
110   }
111
112   /**
113    * <!-- begin-user-doc -->
114    * <!-- end-user-doc -->
115    * @generated
116    */

117   public int getValue()
118   {
119     return value;
120   }
121
122   /**
123    * <!-- begin-user-doc -->
124    * <!-- end-user-doc -->
125    * @generated
126    */

127   public void setValue(int newValue)
128   {
129     int oldValue = value;
130     value = newValue;
131     if (eNotificationRequired())
132       eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EENUM_LITERAL__VALUE, oldValue, value));
133   }
134
135   /**
136    * <!-- begin-user-doc -->
137    * <!-- end-user-doc -->
138    * @generated
139    */

140   public Enumerator getInstance()
141   {
142     return instance;
143   }
144
145   /**
146    * <!-- begin-user-doc -->
147    * <!-- end-user-doc -->
148    * @generated
149    */

150   public void setInstanceGen(Enumerator newInstance)
151   {
152     Enumerator oldInstance = instance;
153     instance = newInstance;
154     if (eNotificationRequired())
155       eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EENUM_LITERAL__INSTANCE, oldInstance, instance));
156   }
157
158   public void setInstance(Enumerator newInstance)
159   {
160     setInstanceGen(newInstance);
161     if (newInstance == null)
162     {
163       setName(null);
164       setValue(0);
165     }
166     else if (newInstance != this)
167     {
168       setName(newInstance.getName());
169       setValue(newInstance.getValue());
170     }
171   }
172
173   /**
174    * <!-- begin-user-doc -->
175    * <!-- end-user-doc -->
176    * @generated modifiable
177    */

178   public EEnum getEEnum()
179   {
180     return (eContainerFeatureID == EcorePackage.EENUM_LITERAL__EENUM) ? (EEnum)eContainer : null;
181   }
182
183   /**
184    * <!-- begin-user-doc -->
185    * <!-- end-user-doc -->
186    * @generated
187    */

188   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
189   {
190     if (featureID >= 0)
191     {
192       switch (eDerivedStructuralFeatureID(featureID, baseClass))
193       {
194         case EcorePackage.EENUM_LITERAL__EANNOTATIONS:
195           return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs);
196         case EcorePackage.EENUM_LITERAL__EENUM:
197           if (eContainer != null)
198             msgs = eBasicRemoveFromContainer(msgs);
199           return eBasicSetContainer(otherEnd, EcorePackage.EENUM_LITERAL__EENUM, msgs);
200         default:
201           return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs);
202       }
203     }
204     if (eContainer != null)
205       msgs = eBasicRemoveFromContainer(msgs);
206     return eBasicSetContainer(otherEnd, featureID, msgs);
207   }
208
209   /**
210    * <!-- begin-user-doc -->
211    * <!-- end-user-doc -->
212    * @generated
213    */

214   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
215   {
216     if (featureID >= 0)
217     {
218       switch (eDerivedStructuralFeatureID(featureID, baseClass))
219       {
220         case EcorePackage.EENUM_LITERAL__EANNOTATIONS:
221           return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs);
222         case EcorePackage.EENUM_LITERAL__EENUM:
223           return eBasicSetContainer(null, EcorePackage.EENUM_LITERAL__EENUM, msgs);
224         default:
225           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
226       }
227     }
228     return eBasicSetContainer(null, featureID, msgs);
229   }
230
231   /**
232    * <!-- begin-user-doc -->
233    * <!-- end-user-doc -->
234    * @generated
235    */

236   public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs)
237   {
238     if (eContainerFeatureID >= 0)
239     {
240       switch (eContainerFeatureID)
241       {
242         case EcorePackage.EENUM_LITERAL__EENUM:
243           return eContainer.eInverseRemove(this, EcorePackage.EENUM__ELITERALS, EEnum.class, msgs);
244         default:
245           return eDynamicBasicRemoveFromContainer(msgs);
246       }
247     }
248     return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs);
249   }
250
251   /**
252    * <!-- begin-user-doc -->
253    * <!-- end-user-doc -->
254    * @generated
255    */

256   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
257   {
258     switch (eDerivedStructuralFeatureID(eFeature))
259     {
260       case EcorePackage.EENUM_LITERAL__EANNOTATIONS:
261         return getEAnnotations();
262       case EcorePackage.EENUM_LITERAL__NAME:
263         return getName();
264       case EcorePackage.EENUM_LITERAL__VALUE:
265         return new Integer JavaDoc(getValue());
266       case EcorePackage.EENUM_LITERAL__INSTANCE:
267         return getInstance();
268       case EcorePackage.EENUM_LITERAL__EENUM:
269         return getEEnum();
270     }
271     return eDynamicGet(eFeature, resolve);
272   }
273
274   /**
275    * <!-- begin-user-doc -->
276    * <!-- end-user-doc -->
277    * @generated
278    */

279   public boolean eIsSet(EStructuralFeature eFeature)
280   {
281     switch (eDerivedStructuralFeatureID(eFeature))
282     {
283       case EcorePackage.EENUM_LITERAL__EANNOTATIONS:
284         return eAnnotations != null && !eAnnotations.isEmpty();
285       case EcorePackage.EENUM_LITERAL__NAME:
286         return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
287       case EcorePackage.EENUM_LITERAL__VALUE:
288         return value != VALUE_EDEFAULT;
289       case EcorePackage.EENUM_LITERAL__INSTANCE:
290         return INSTANCE_EDEFAULT == null ? instance != null : !INSTANCE_EDEFAULT.equals(instance);
291       case EcorePackage.EENUM_LITERAL__EENUM:
292         return getEEnum() != null;
293     }
294     return eDynamicIsSet(eFeature);
295   }
296
297   /**
298    * <!-- begin-user-doc -->
299    * <!-- end-user-doc -->
300    * @generated
301    */

302   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
303   {
304     switch (eDerivedStructuralFeatureID(eFeature))
305     {
306       case EcorePackage.EENUM_LITERAL__EANNOTATIONS:
307         getEAnnotations().clear();
308         getEAnnotations().addAll((Collection JavaDoc)newValue);
309         return;
310       case EcorePackage.EENUM_LITERAL__NAME:
311         setName((String JavaDoc)newValue);
312         return;
313       case EcorePackage.EENUM_LITERAL__VALUE:
314         setValue(((Integer JavaDoc)newValue).intValue());
315         return;
316       case EcorePackage.EENUM_LITERAL__INSTANCE:
317         setInstance((Enumerator)newValue);
318         return;
319     }
320     eDynamicSet(eFeature, newValue);
321   }
322
323   /**
324    * <!-- begin-user-doc -->
325    * <!-- end-user-doc -->
326    * @generated
327    */

328   public void eUnset(EStructuralFeature eFeature)
329   {
330     switch (eDerivedStructuralFeatureID(eFeature))
331     {
332       case EcorePackage.EENUM_LITERAL__EANNOTATIONS:
333         getEAnnotations().clear();
334         return;
335       case EcorePackage.EENUM_LITERAL__NAME:
336         setName(NAME_EDEFAULT);
337         return;
338       case EcorePackage.EENUM_LITERAL__VALUE:
339         setValue(VALUE_EDEFAULT);
340         return;
341       case EcorePackage.EENUM_LITERAL__INSTANCE:
342         setInstance(INSTANCE_EDEFAULT);
343         return;
344     }
345     eDynamicUnset(eFeature);
346   }
347
348   public String JavaDoc toString()
349   {
350     return getName();
351   }
352
353   /**
354    * <!-- begin-user-doc -->
355    * <!-- end-user-doc -->
356    * @generated
357    */

358   public String JavaDoc toStringGen()
359   {
360     if (eIsProxy()) return super.toString();
361
362     StringBuffer JavaDoc result = new StringBuffer JavaDoc(super.toString());
363     result.append(" (value: ");
364     result.append(value);
365     result.append(", instance: ");
366     result.append(instance);
367     result.append(')');
368     return result.toString();
369   }
370
371 }
372
Popular Tags