KickJava   Java API By Example, From Geeks To Geeks.

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


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: EEnumImpl.java,v 1.6 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 import java.util.Iterator JavaDoc;
22
23 import org.eclipse.emf.common.notify.NotificationChain;
24 import org.eclipse.emf.common.util.EList;
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.EPackage;
29 import org.eclipse.emf.ecore.EStructuralFeature;
30 import org.eclipse.emf.ecore.EcorePackage;
31 import org.eclipse.emf.ecore.InternalEObject;
32 import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
33 import org.eclipse.emf.ecore.util.InternalEList;
34
35
36 /**
37  * <!-- begin-user-doc -->
38  * An implementation of the model object '<em><b>EEnum</b></em>'.
39  * <!-- end-user-doc -->
40  * <p>
41  * The following features are implemented:
42  * <ul>
43  * <li>{@link org.eclipse.emf.ecore.impl.EEnumImpl#getELiterals <em>ELiterals</em>}</li>
44  * </ul>
45  * </p>
46  *
47  * @generated
48  */

49 public class EEnumImpl extends EDataTypeImpl implements EEnum
50 {
51   /**
52    * The cached value of the '{@link #getELiterals() <em>ELiterals</em>}' containment reference list.
53    * <!-- begin-user-doc -->
54    * <!-- end-user-doc -->
55    * @see #getELiterals()
56    * @generated
57    * @ordered
58    */

59   protected EList eLiterals = null;
60
61   /**
62    * <!-- begin-user-doc -->
63    * <!-- end-user-doc -->
64    * @generated
65    */

66   protected EEnumImpl()
67   {
68     super();
69   }
70
71   protected void setDataTypeGeneratedInstanceClass(boolean isGenerated)
72   {
73   }
74
75   public Object JavaDoc getDefaultValue()
76   {
77     EList eLiterals = getELiterals();
78     if (!eLiterals.isEmpty())
79     {
80       return ((EEnumLiteral)eLiterals.get(0)).getInstance();
81     }
82     return null;
83   }
84
85   /**
86    * Determines if the specified Object is an instance of this.
87    */

88   public boolean isInstance(Object JavaDoc object)
89   {
90     if (object != null)
91     {
92       Class JavaDoc instanceClass = getInstanceClass();
93       if (instanceClass != null)
94       {
95         return instanceClass.isInstance(object);
96       }
97       else
98       {
99         return getELiterals().contains(object);
100       }
101     }
102     return false;
103   }
104
105   /**
106    * <!-- begin-user-doc -->
107    * <!-- end-user-doc -->
108    * @generated
109    */

110   protected EClass eStaticClass()
111   {
112     return EcorePackage.eINSTANCE.getEEnum();
113   }
114
115   /**
116    * <!-- begin-user-doc -->
117    * <!-- end-user-doc -->
118    * @generated
119    */

120   public EList getELiterals()
121   {
122     if (eLiterals == null)
123     {
124       eLiterals = new EObjectContainmentWithInverseEList(EEnumLiteral.class, this, EcorePackage.EENUM__ELITERALS, EcorePackage.EENUM_LITERAL__EENUM);
125     }
126     return eLiterals;
127   }
128
129   /**
130    * <!-- begin-user-doc -->
131    * <!-- end-user-doc -->
132    * @generated
133    */

134   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
135   {
136     if (featureID >= 0)
137     {
138       switch (eDerivedStructuralFeatureID(featureID, baseClass))
139       {
140         case EcorePackage.EENUM__EANNOTATIONS:
141           return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs);
142         case EcorePackage.EENUM__EPACKAGE:
143           return eBasicSetContainer(null, EcorePackage.EENUM__EPACKAGE, msgs);
144         case EcorePackage.EENUM__ELITERALS:
145           return ((InternalEList)getELiterals()).basicRemove(otherEnd, msgs);
146         default:
147           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
148       }
149     }
150     return eBasicSetContainer(null, featureID, msgs);
151   }
152
153   /**
154    * <!-- begin-user-doc -->
155    * <!-- end-user-doc -->
156    * @generated
157    */

158   public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs)
159   {
160     if (eContainerFeatureID >= 0)
161     {
162       switch (eContainerFeatureID)
163       {
164         case EcorePackage.EENUM__EPACKAGE:
165           return eContainer.eInverseRemove(this, EcorePackage.EPACKAGE__ECLASSIFIERS, EPackage.class, msgs);
166         default:
167           return eDynamicBasicRemoveFromContainer(msgs);
168       }
169     }
170     return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs);
171   }
172
173   /**
174    * <!-- begin-user-doc -->
175    * <!-- end-user-doc -->
176    * @generated
177    */

178   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
179   {
180     switch (eDerivedStructuralFeatureID(eFeature))
181     {
182       case EcorePackage.EENUM__EANNOTATIONS:
183         return getEAnnotations();
184       case EcorePackage.EENUM__NAME:
185         return getName();
186       case EcorePackage.EENUM__INSTANCE_CLASS_NAME:
187         return getInstanceClassName();
188       case EcorePackage.EENUM__INSTANCE_CLASS:
189         return getInstanceClass();
190       case EcorePackage.EENUM__DEFAULT_VALUE:
191         return getDefaultValue();
192       case EcorePackage.EENUM__EPACKAGE:
193         return getEPackage();
194       case EcorePackage.EENUM__SERIALIZABLE:
195         return isSerializable() ? Boolean.TRUE : Boolean.FALSE;
196       case EcorePackage.EENUM__ELITERALS:
197         return getELiterals();
198     }
199     return eDynamicGet(eFeature, resolve);
200   }
201
202   /**
203    * <!-- begin-user-doc -->
204    * <!-- end-user-doc -->
205    * @generated
206    */

207   public boolean eIsSet(EStructuralFeature eFeature)
208   {
209     switch (eDerivedStructuralFeatureID(eFeature))
210     {
211       case EcorePackage.EENUM__EANNOTATIONS:
212         return eAnnotations != null && !eAnnotations.isEmpty();
213       case EcorePackage.EENUM__NAME:
214         return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
215       case EcorePackage.EENUM__INSTANCE_CLASS_NAME:
216         return INSTANCE_CLASS_NAME_EDEFAULT == null ? instanceClassName != null : !INSTANCE_CLASS_NAME_EDEFAULT.equals(instanceClassName);
217       case EcorePackage.EENUM__INSTANCE_CLASS:
218         return INSTANCE_CLASS_EDEFAULT == null ? getInstanceClass() != null : !INSTANCE_CLASS_EDEFAULT.equals(getInstanceClass());
219       case EcorePackage.EENUM__DEFAULT_VALUE:
220         return DEFAULT_VALUE_EDEFAULT == null ? getDefaultValue() != null : !DEFAULT_VALUE_EDEFAULT.equals(getDefaultValue());
221       case EcorePackage.EENUM__EPACKAGE:
222         return getEPackage() != null;
223       case EcorePackage.EENUM__SERIALIZABLE:
224         return ((eFlags & SERIALIZABLE_EFLAG) != 0) != SERIALIZABLE_EDEFAULT;
225       case EcorePackage.EENUM__ELITERALS:
226         return eLiterals != null && !eLiterals.isEmpty();
227     }
228     return eDynamicIsSet(eFeature);
229   }
230
231   /**
232    * <!-- begin-user-doc -->
233    * <!-- end-user-doc -->
234    * @generated
235    */

236   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
237   {
238     switch (eDerivedStructuralFeatureID(eFeature))
239     {
240       case EcorePackage.EENUM__EANNOTATIONS:
241         getEAnnotations().clear();
242         getEAnnotations().addAll((Collection JavaDoc)newValue);
243         return;
244       case EcorePackage.EENUM__NAME:
245         setName((String JavaDoc)newValue);
246         return;
247       case EcorePackage.EENUM__INSTANCE_CLASS_NAME:
248         setInstanceClassName((String JavaDoc)newValue);
249         return;
250       case EcorePackage.EENUM__SERIALIZABLE:
251         setSerializable(((Boolean JavaDoc)newValue).booleanValue());
252         return;
253       case EcorePackage.EENUM__ELITERALS:
254         getELiterals().clear();
255         getELiterals().addAll((Collection JavaDoc)newValue);
256         return;
257     }
258     eDynamicSet(eFeature, newValue);
259   }
260
261   /**
262    * <!-- begin-user-doc -->
263    * <!-- end-user-doc -->
264    * @generated
265    */

266   public void eUnset(EStructuralFeature eFeature)
267   {
268     switch (eDerivedStructuralFeatureID(eFeature))
269     {
270       case EcorePackage.EENUM__EANNOTATIONS:
271         getEAnnotations().clear();
272         return;
273       case EcorePackage.EENUM__NAME:
274         setName(NAME_EDEFAULT);
275         return;
276       case EcorePackage.EENUM__INSTANCE_CLASS_NAME:
277         setInstanceClassName(INSTANCE_CLASS_NAME_EDEFAULT);
278         return;
279       case EcorePackage.EENUM__SERIALIZABLE:
280         setSerializable(SERIALIZABLE_EDEFAULT);
281         return;
282       case EcorePackage.EENUM__ELITERALS:
283         getELiterals().clear();
284         return;
285     }
286     eDynamicUnset(eFeature);
287   }
288
289   /**
290    * @generated modifiable
291    */

292   public EEnumLiteral getEEnumLiteral(String JavaDoc stringValue)
293   {
294     for (Iterator JavaDoc i = getELiterals().iterator(); i.hasNext(); )
295     {
296       EEnumLiteral eEnumLiteral = (EEnumLiteral) i.next();
297       if (eEnumLiteral.getName().equals(stringValue))
298       {
299         return eEnumLiteral;
300       }
301     }
302     return null;
303   }
304
305   /**
306    * @generated modifiable
307    */

308   public EEnumLiteral getEEnumLiteral(int intValue)
309   {
310     for (Iterator JavaDoc i = getELiterals().iterator(); i.hasNext(); )
311     {
312       EEnumLiteral eEnumLiteral = (EEnumLiteral) i.next();
313       if (eEnumLiteral.getValue() == intValue)
314       {
315         return eEnumLiteral;
316       }
317     }
318     return null;
319   }
320
321   /**
322    * <!-- begin-user-doc -->
323    * <!-- end-user-doc -->
324    * @generated
325    */

326   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
327   {
328     if (featureID >= 0)
329     {
330       switch (eDerivedStructuralFeatureID(featureID, baseClass))
331       {
332         case EcorePackage.EENUM__EANNOTATIONS:
333           return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs);
334         case EcorePackage.EENUM__EPACKAGE:
335           if (eContainer != null)
336             msgs = eBasicRemoveFromContainer(msgs);
337           return eBasicSetContainer(otherEnd, EcorePackage.EENUM__EPACKAGE, msgs);
338         case EcorePackage.EENUM__ELITERALS:
339           return ((InternalEList)getELiterals()).basicAdd(otherEnd, msgs);
340         default:
341           return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs);
342       }
343     }
344     if (eContainer != null)
345       msgs = eBasicRemoveFromContainer(msgs);
346     return eBasicSetContainer(otherEnd, featureID, msgs);
347   }
348
349 }
350
Popular Tags