KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > codegen > ecore > genmodel > impl > GenEnumLiteralImpl


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: GenEnumLiteralImpl.java,v 1.4 2005/06/08 06:18:44 nickb Exp $
16  */

17 package org.eclipse.emf.codegen.ecore.genmodel.impl;
18
19
20 import org.eclipse.emf.codegen.ecore.genmodel.GenEnum;
21 import org.eclipse.emf.codegen.ecore.genmodel.GenEnumLiteral;
22 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
23 import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
24 import org.eclipse.emf.common.notify.Notification;
25 import org.eclipse.emf.common.notify.NotificationChain;
26 import org.eclipse.emf.ecore.EClass;
27 import org.eclipse.emf.ecore.EEnumLiteral;
28 import org.eclipse.emf.ecore.EModelElement;
29 import org.eclipse.emf.ecore.EStructuralFeature;
30 import org.eclipse.emf.ecore.InternalEObject;
31 import org.eclipse.emf.ecore.impl.ENotificationImpl;
32 import org.eclipse.emf.ecore.util.EcoreUtil;
33
34
35 /**
36  * <!-- begin-user-doc -->
37  * An implementation of the model object '<em><b>Gen Enum Literal</b></em>'.
38  * <!-- end-user-doc -->
39  * <p>
40  * The following features are implemented:
41  * <ul>
42  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenEnumLiteralImpl#getGenEnum <em>Gen Enum</em>}</li>
43  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenEnumLiteralImpl#getEcoreEnumLiteral <em>Ecore Enum Literal</em>}</li>
44  * </ul>
45  * </p>
46  *
47  * @generated
48  */

49 public class GenEnumLiteralImpl extends GenBaseImpl implements GenEnumLiteral
50 {
51   /**
52    * The cached value of the '{@link #getEcoreEnumLiteral() <em>Ecore Enum Literal</em>}' reference.
53    * <!-- begin-user-doc -->
54    * <!-- end-user-doc -->
55    * @see #getEcoreEnumLiteral()
56    * @generated
57    * @ordered
58    */

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

66   protected GenEnumLiteralImpl()
67   {
68     super();
69   }
70
71   /**
72    * <!-- begin-user-doc -->
73    * <!-- end-user-doc -->
74    * @generated
75    */

76   protected EClass eStaticClass()
77   {
78     return GenModelPackage.eINSTANCE.getGenEnumLiteral();
79   }
80
81   /**
82    * <!-- begin-user-doc -->
83    * <!-- end-user-doc -->
84    * @generated
85    */

86   public GenEnum getGenEnum()
87   {
88     if (eContainerFeatureID != GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM) return null;
89     return (GenEnum)eContainer;
90   }
91
92   /**
93    * <!-- begin-user-doc -->
94    * <!-- end-user-doc -->
95    * @generated
96    */

97   public void setGenEnum(GenEnum newGenEnum)
98   {
99     if (newGenEnum != eContainer || (eContainerFeatureID != GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM && newGenEnum != null))
100     {
101       if (EcoreUtil.isAncestor(this, newGenEnum))
102         throw new IllegalArgumentException JavaDoc("Recursive containment not allowed for " + toString());
103       NotificationChain msgs = null;
104       if (eContainer != null)
105         msgs = eBasicRemoveFromContainer(msgs);
106       if (newGenEnum != null)
107         msgs = ((InternalEObject)newGenEnum).eInverseAdd(this, GenModelPackage.GEN_ENUM__GEN_ENUM_LITERALS, GenEnum.class, msgs);
108       msgs = eBasicSetContainer((InternalEObject)newGenEnum, GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM, msgs);
109       if (msgs != null) msgs.dispatch();
110     }
111     else if (eNotificationRequired())
112       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM, newGenEnum, newGenEnum));
113   }
114
115   public EModelElement getEcoreModelElement()
116   {
117     return getEcoreEnumLiteral();
118   }
119
120   /**
121    * <!-- begin-user-doc -->
122    * <!-- end-user-doc -->
123    * @generated
124    */

125   public EEnumLiteral getEcoreEnumLiteral()
126   {
127     if (ecoreEnumLiteral != null && ecoreEnumLiteral.eIsProxy())
128     {
129       EEnumLiteral oldEcoreEnumLiteral = ecoreEnumLiteral;
130       ecoreEnumLiteral = (EEnumLiteral)eResolveProxy((InternalEObject)ecoreEnumLiteral);
131       if (ecoreEnumLiteral != oldEcoreEnumLiteral)
132       {
133         if (eNotificationRequired())
134           eNotify(new ENotificationImpl(this, Notification.RESOLVE, GenModelPackage.GEN_ENUM_LITERAL__ECORE_ENUM_LITERAL, oldEcoreEnumLiteral, ecoreEnumLiteral));
135       }
136     }
137     return ecoreEnumLiteral;
138   }
139
140   /**
141    * <!-- begin-user-doc -->
142    * <!-- end-user-doc -->
143    * @generated
144    */

145   public EEnumLiteral basicGetEcoreEnumLiteral()
146   {
147     return ecoreEnumLiteral;
148   }
149
150   /**
151    * <!-- begin-user-doc -->
152    * <!-- end-user-doc -->
153    * @generated
154    */

155   public void setEcoreEnumLiteral(EEnumLiteral newEcoreEnumLiteral)
156   {
157     EEnumLiteral oldEcoreEnumLiteral = ecoreEnumLiteral;
158     ecoreEnumLiteral = newEcoreEnumLiteral;
159     if (eNotificationRequired())
160       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_ENUM_LITERAL__ECORE_ENUM_LITERAL, oldEcoreEnumLiteral, ecoreEnumLiteral));
161   }
162
163   /**
164    * <!-- begin-user-doc -->
165    * <!-- end-user-doc -->
166    * @generated
167    */

168   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
169   {
170     if (featureID >= 0)
171     {
172       switch (eDerivedStructuralFeatureID(featureID, baseClass))
173       {
174         case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM:
175           if (eContainer != null)
176             msgs = eBasicRemoveFromContainer(msgs);
177           return eBasicSetContainer(otherEnd, GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM, msgs);
178         default:
179           return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs);
180       }
181     }
182     if (eContainer != null)
183       msgs = eBasicRemoveFromContainer(msgs);
184     return eBasicSetContainer(otherEnd, featureID, msgs);
185   }
186
187   /**
188    * <!-- begin-user-doc -->
189    * <!-- end-user-doc -->
190    * @generated
191    */

192   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
193   {
194     if (featureID >= 0)
195     {
196       switch (eDerivedStructuralFeatureID(featureID, baseClass))
197       {
198         case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM:
199           return eBasicSetContainer(null, GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM, msgs);
200         default:
201           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
202       }
203     }
204     return eBasicSetContainer(null, featureID, msgs);
205   }
206
207   /**
208    * <!-- begin-user-doc -->
209    * <!-- end-user-doc -->
210    * @generated
211    */

212   public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs)
213   {
214     if (eContainerFeatureID >= 0)
215     {
216       switch (eContainerFeatureID)
217       {
218         case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM:
219           return eContainer.eInverseRemove(this, GenModelPackage.GEN_ENUM__GEN_ENUM_LITERALS, GenEnum.class, msgs);
220         default:
221           return eDynamicBasicRemoveFromContainer(msgs);
222       }
223     }
224     return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs);
225   }
226
227   /**
228    * <!-- begin-user-doc -->
229    * <!-- end-user-doc -->
230    * @generated
231    */

232   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
233   {
234     switch (eDerivedStructuralFeatureID(eFeature))
235     {
236       case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM:
237         return getGenEnum();
238       case GenModelPackage.GEN_ENUM_LITERAL__ECORE_ENUM_LITERAL:
239         if (resolve) return getEcoreEnumLiteral();
240         return basicGetEcoreEnumLiteral();
241     }
242     return eDynamicGet(eFeature, resolve);
243   }
244
245   /**
246    * <!-- begin-user-doc -->
247    * <!-- end-user-doc -->
248    * @generated
249    */

250   public boolean eIsSet(EStructuralFeature eFeature)
251   {
252     switch (eDerivedStructuralFeatureID(eFeature))
253     {
254       case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM:
255         return getGenEnum() != null;
256       case GenModelPackage.GEN_ENUM_LITERAL__ECORE_ENUM_LITERAL:
257         return ecoreEnumLiteral != null;
258     }
259     return eDynamicIsSet(eFeature);
260   }
261
262   /**
263    * <!-- begin-user-doc -->
264    * <!-- end-user-doc -->
265    * @generated
266    */

267   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
268   {
269     switch (eDerivedStructuralFeatureID(eFeature))
270     {
271       case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM:
272         setGenEnum((GenEnum)newValue);
273         return;
274       case GenModelPackage.GEN_ENUM_LITERAL__ECORE_ENUM_LITERAL:
275         setEcoreEnumLiteral((EEnumLiteral)newValue);
276         return;
277     }
278     eDynamicSet(eFeature, newValue);
279   }
280
281   /**
282    * <!-- begin-user-doc -->
283    * <!-- end-user-doc -->
284    * @generated
285    */

286   public void eUnset(EStructuralFeature eFeature)
287   {
288     switch (eDerivedStructuralFeatureID(eFeature))
289     {
290       case GenModelPackage.GEN_ENUM_LITERAL__GEN_ENUM:
291         setGenEnum((GenEnum)null);
292         return;
293       case GenModelPackage.GEN_ENUM_LITERAL__ECORE_ENUM_LITERAL:
294         setEcoreEnumLiteral((EEnumLiteral)null);
295         return;
296     }
297     eDynamicUnset(eFeature);
298   }
299
300   public String JavaDoc getName()
301   {
302     return getEcoreEnumLiteral().getName();
303   }
304
305   public String JavaDoc getCapName()
306   {
307     return capName(getName());
308   }
309
310   public String JavaDoc getFormattedName()
311   {
312     return format(getCapName(), ' ', null, false);
313   }
314
315   public int getValue()
316   {
317     return getEcoreEnumLiteral().getValue();
318   }
319
320   public String JavaDoc getEnumLiteralID()
321   {
322     return format(getName(), '_', null, false).toUpperCase();
323   }
324
325   public GenPackage getGenPackage()
326   {
327     return getGenEnum().getGenPackage();
328   }
329
330   public String JavaDoc getEnumLiteralAccessorName()
331   {
332     return getGenEnum().getName() + "_" + getCapName();
333   }
334
335   public void initialize(EEnumLiteral eEnumLiteral)
336   {
337     setEcoreEnumLiteral(eEnumLiteral);
338   }
339
340   public String JavaDoc getModelInfo()
341   {
342     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
343     if (!getEnumLiteralID().equals(getName()))
344     {
345       result.append("name=\"");
346       result.append(getName());
347       result.append('"');
348     }
349
350     appendAnnotationInfo(result, getEcoreEnumLiteral());
351
352     return result.toString();
353   }
354
355   public boolean reconcile(GenEnumLiteral oldGenEnumLiteralVersion)
356   {
357     if (getEcoreEnumLiteral().getName().equals(oldGenEnumLiteralVersion.getEcoreEnumLiteral().getName()))
358     {
359       reconcileSettings(oldGenEnumLiteralVersion);
360       return true;
361     }
362     else
363     {
364       return false;
365     }
366   }
367
368   protected void reconcileSettings(GenEnumLiteral oldGenEnumLiteralVersion)
369   {
370   }
371
372   public boolean reconcile()
373   {
374     EEnumLiteral eEnumLiteral = getEcoreEnumLiteral();
375     if (eEnumLiteral == null || eEnumLiteral.eIsProxy() || eEnumLiteral.eResource() == null)
376     {
377       return false;
378     }
379     else
380     {
381       return true;
382     }
383   }
384 }
385
Popular Tags